Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RollingDice

Small command-line dice roller written in C# with .NET 10.

Supports standard tabletop dice expressions such as 2d6 (roll two d6), 4d6+3 (roll four d6, then add 3), 3d4 kh 1 (roll 3d4 but keep only the highest), or 4d6+7 dl 1 (roll four d6, drop the lowest, then add 7).

Usage

RollingDice <expression>
RollingDice <expression> <mode> <n>

Where:

  • <expression> is <count>d<faces>[+/-<modifier>]
    • <count>: number of dice to roll (at least 1)
    • <faces>: one of 4, 6, 8, 10, 12, 20, 100
    • <modifier>: optional signed integer added to the final sum
  • <mode> (optional) is one of:
    • kh : keep highest
    • kl : keep lowest
    • dh : drop highest
    • dl : drop lowest
  • <n> is the number of dice to keep or drop (must be strictly less than <count>)

The program prints the resulting sum on stdout.

Examples

RollingDice 2d6
# → 7

RollingDice 4d6+1
# → 14

RollingDice 4d6 kh 3
# → 13

RollingDice 2d20 kl 1
# → 8

The results above are illustrative: each invocation rolls fresh dice, so the actual output will vary from one run to the next.

Exit codes

Code Meaning
0 Success
1 Internal error (unexpected runtime failure)
2 Invalid user input (bad expression, out of range)

Error messages are written to stderr.

Prerequisites

The .NET 10 SDK is required to build and run the project from source. Once a self-contained executable has been published (see Build & run below), the resulting binary runs without a separate .NET runtime installation on the target machine.

Build & run

All commands below are meant to be run from the repository root.

dotnet build
dotnet run --project src/RollingDice -- 2d6

To produce a standalone executable (no separate .NET runtime install required on the target machine):

dotnet publish src/RollingDice -c Release -r linux-x64 --self-contained

The resulting binary is written under src/RollingDice/bin/Release/net10.0/linux-x64/publish/. Replace linux-x64 with win-x64 or osx-x64 (or osx-arm64) to target a different platform.

Project layout

RollingDice/
├── LICENSE
├── README.md
├── RollingDice.slnx              # .NET solution file
└── src/
    └── RollingDice/
        ├── RollingDice.csproj
        ├── Program.cs
        ├── Common/
        │   ├── Error.cs              # Base record for typed errors
        │   ├── Result.cs             # Result<T> pattern
        │   └── Errors/               # Specific error records (ArgumentsCountError, ParseError, ...)
        └── Entities/
            ├── Die.cs
            ├── DiceMode.cs
            ├── DiceRoll.cs
            ├── Instructions.cs
            └── Factories/
                ├── DiceRollFactory.cs
                └── InstructionsFactory.cs

Argument validation is reported via the Result pattern. Programmer errors (broken invariants) still raise exceptions.

License

This project is released under the MIT License. You are free to use, copy, modify, merge, publish, and distribute the code, as long as the original copyright notice and license text are preserved. The software is provided "as is", without warranty of any kind.

Acknowledgements

This program was written by me, with Claude (Anthropic's AI assistant) used mainly for help writing this README, for code reviews, and for help consolidating and tightening the implementation. The ideas, the design choices, and the overall organization of the code are mine.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages