# RogueSharp Version 2.0

Version 2.0 of RogueSharp was just released. It now contains better functionality for dealing with Dice and parsing Dice Notation strings.

Dice Notation .NET – Significant portions of the code in RougeSharp.DiceNotation namespace are from this great library. Thank you to Chris Wagner for originally creating this.

## Usage

The easiest way to roll dice using dice notation is to use the static Roll method on the Dice class and provide a string representing the dice expression.

**Example 1**

// Roll 3 dice with 6 sides each and sum the results together // This produces a result between 3 and 18 int result = Dice.Roll( "3d6" );

**Example 2**

// Roll 4 dice with 6 sides each // But then only keep the 3 highest rolls // This produces a result between 3 and 18 // Higher results should be produced on average than rolling 3d6 int result = Dice.Roll( "4d6k3" );

**Example 3**

// Roll 1 die with 10 sides and add 5 to the result // This produces a result between 6 and 15 int result = Dice.Roll( "1d10+5" );

**Example 4**

// Roll 1 die with 10 sides and 2 dice with 6 sides each... // Sum up the values of the dice and subtract 5 from the final result // This produces a result between -2 and 17 int result = Dice.Roll( "1d10+2d6-5" );

## Creating Expressions Fluently

If you haven’t heard of Fluent interfaces you can check out the link on Wikipedia to get a better description than I could provide. I think of it is using method chaining to produce more readable code. If you have ever used LINQ and seen how you could chain methods together to build your queries, I think that is a decent example. Let’s see how you can build a DiceExpression fluently

// In dice notation the following is the same as "5+1d8+4d6k3" DiceExpression diceExpression = new DiceExpression() .Constant( 5 ) // Add a constant of 5 .Die( 8 ) // Add an 8 sided Die .Dice( 4, 6, choose: 3 ); // Add 4d6 but when rolling them keep the 3 highest results // Total should be between 9 and 31. DiceResult result = diceExpression.Roll(); int total = result.Value;

## Upgrading from v1.X

If you are were using an earlier version of RogueSharp and you used the `Dice` or `Die` classes there will be some minor changes that you will have to make to use v2.0. I have upgraded the sample for the tutorial series here so you can get an idea of what it will take: https://bitbucket.org/FaronBracy/roguesharpmonogamesamples/commits/25a57cc9820bcb2e75a043d76ca6bf32020db2ff

musaabosmanWill you be continuing the tutorial series?

Faron BracyPost authorHello and thank you for visiting! If you are referring to the MonoGame and RogueSharp series I have not been working on additional posts for that particular series. I do plan on releasing more versions of RougeSharp as well as creating additional blog posts. What I have been working on lately is learning Unity and attempting to create a version of RogueSharp that works well with Unity as well as a set of quick start tutorials for how to use it. Other things in the works are a random name generator, cleanup of the GoalMaps class and a tutorial showing how to make enemies run away.

musaabosmanSounds great 🙂

Thank you!

Musaab OsmanAlthough I would prefer Monogame 🙂

Musaab OsmanActually, I’m looking forward to your Unity tutorial. I haven’t used Unity before, but it looks interesting.

Pingback: RogueSharp V3 Tutorial – Monster Generation | Creating a Roguelike Game in C#