dice-notation-java icon indicating copy to clipboard operation
dice-notation-java copied to clipboard

Detailed view for a roll

Open bbassac opened this issue 7 years ago • 16 comments

Hi, I try to use this librairy for a little game for my boy, but (maybe it already exists), i can't find the way to have the detail of rolls Ex : 1 want a 2D10 , if i to a .roll(), i'll have 15 for example. But i would like to have a sorted list with 7 and 8 (7 for the first dire, 8 for the second)

How could i help you with this 'feature' ?

bbassac avatar Jan 21 '19 12:01 bbassac

I'll take a look, but there is a DiceNotationTransformer interface for these custom operations.

This implementation for example will take all the dice from a parsed expression:

final TransformableDiceNotationExpression parsed;
final Dice dice;

parsed = new DefaultDiceNotationExpressionParser().parse("1d6+12");

dice = parsed.transform(new DiceSetsTransformer()).iterator().next();

System.out.println(dice.getQuantity());
System.out.println(dice.getSides());

This case would need a transformer which generates a result for each dice set.

Bernardo-MG avatar Jan 21 '19 13:01 Bernardo-MG

Related to #49

Bernardo-MG avatar Jan 21 '19 15:01 Bernardo-MG

This is what I've just added to develop:

To get the roll history:

final TransformableDiceNotationExpression parsed;
final RollHistory history;

parsed = new DefaultDiceNotationExpressionParser().parse("2d6+12");

history = new DiceRoller().transform(parsed);

Then, to print the final value:

// Prints the final result
System.out.println(history.getFinalRoll());

And to print each roll from the dice set:

final Iterable<RollResult> results;
final RollResult result;

results = history.getRollResults();
result = results .iterator().nex();

// Prints each roll
System.out.println(result.getAllRolls());

Bernardo-MG avatar Jan 27 '19 18:01 Bernardo-MG

@bbassac Does this look good? If there is any problem, like it not being too clear, tell me.

Otherwise I expect to publish a new version with this and other changes in a few weeks.

Bernardo-MG avatar Jan 27 '19 18:01 Bernardo-MG

Hi (Bonjour),

I'll try this tonight, but can you just explain me how i can retrieve the 'develop' library ? I checkout branch, and maven install ?

Le dim. 27 janv. 2019 à 19:57, Bernardo [email protected] a écrit :

@bbassac https://github.com/bbassac Does this look good? If there is any problem, like it not being too clear, tell me.

Otherwise I expect to publish a new version with this and other changes in a few weeks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-457944158, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMAnOVtv44WWW4nk_k-aPq1K27mbglks5vHfa0gaJpZM4aKsSV .

bbassac avatar Jan 28 '19 13:01 bbassac

The snapshots are being published to https://oss.sonatype.org, you can configure Maven and add the http://oss.sonatype.org/content/repositories/snapshots repository to it, then you can take the latest snapshot (2.0.0-SNAPSHOT).

Otherwise, you can download the repository and install the develop branch with the standard command:

mvn clean install

Afterwards you can make use of the 2.0.0-SNAPSHOT.

Take notice that as part of the changes several clases have been modified, that's the reason for changing the major version, but the develop branch includes, in the readme and deployed docs, updated usage information.

Bernardo-MG avatar Jan 28 '19 14:01 Bernardo-MG

I'm trying your sample .... but i think there "s a strange thing : final TransformableDiceNotationExpression parsed; The class does not exists anymore ... i replaced it by a DiceNotationExpression

And

before to retrieve the 'sum' of rolls, we was doing

final DiceNotationExpressionParser parser;final TransformableDiceNotationExpression parsed;

parser = new DefaultDiceNotationExpressionParser();

parsed = parser.parse("1d6+12"); System.out.println(parsed.roll());

but now, with :

final DiceNotationExpression parsed; final RollHistory history;

parsed = new DefaultDiceParser().parse("2d6+12");

I can't do a 'parsed.roll' Any idea ?

And thank you very much for this feature, i's really good !!

Bruno

Le lun. 28 janv. 2019 à 15:43, Bernardo [email protected] a écrit :

The snapshots are being published to https://oss.sonatype.org, you can configure Maven and add the http://oss.sonatype.org/content/repositories/snapshots repository to it, then you can take the latest snapshot (2.0.0-SNAPSHOT).

Otherwise, you can download the repository and install the develop branch with the standard command:

mvn clean install

Afterwards you can make use of the 2.0.0-SNAPSHOT.

Take notice that as part of the changes several clases have been modified, that's the reason for changing the major version, but the develop branch includes, in the readme and deployed docs, updated usage information.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-458158109, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMApCb1867H3lk5MxnQg6LoXdNTYVzks5vHwx7gaJpZM4aKsSV .

bbassac avatar Jan 28 '19 16:01 bbassac

Hi. So i founded by myself solutions ^^ (i'm dumb sometimes) Value variable is my input (with "4d6+5" for example) I can retrieve each dice throw : perfect But maybe a toString() method on a RollResult could generate a readable string surch as "4 5 6 4 /+5" or something else ? and maybe a "stream' for lambda expressions would be more usable ?

final DiceNotationExpression parsed = new DefaultDiceParser().parse(value); final RollHistory history = new DiceRoller().transform(parsed); final Iterable<RollResult> results = history.getRollResults(); final RollResult result= results .iterator().next();

Stream<Integer> targetStream = StreamSupport.stream(result.getAllRolls().spliterator(), false); String listeDetail = targetStream.map(Object::toString).collect(Collectors.joining(" "));

Dice dice = new Dice(); dice.setExpression(value); dice.setDetail(listeDetail); dice.setValue(history.getFinalRoll());

[image: image.png]

Le lun. 28 janv. 2019 à 17:49, bruno bassac [email protected] a écrit :

I'm trying your sample .... but i think there "s a strange thing : final TransformableDiceNotationExpression parsed; The class does not exists anymore ... i replaced it by a DiceNotationExpression

And

before to retrieve the 'sum' of rolls, we was doing

final DiceNotationExpressionParser parser;final TransformableDiceNotationExpression parsed;

parser = new DefaultDiceNotationExpressionParser();

parsed = parser.parse("1d6+12"); System.out.println(parsed.roll());

but now, with :

final DiceNotationExpression parsed; final RollHistory history;

parsed = new DefaultDiceParser().parse("2d6+12");

I can't do a 'parsed.roll' Any idea ?

And thank you very much for this feature, i's really good !!

Bruno

Le lun. 28 janv. 2019 à 15:43, Bernardo [email protected] a écrit :

The snapshots are being published to https://oss.sonatype.org, you can configure Maven and add the http://oss.sonatype.org/content/repositories/snapshots repository to it, then you can take the latest snapshot (2.0.0-SNAPSHOT).

Otherwise, you can download the repository and install the develop branch with the standard command:

mvn clean install

Afterwards you can make use of the 2.0.0-SNAPSHOT.

Take notice that as part of the changes several clases have been modified, that's the reason for changing the major version, but the develop branch includes, in the readme and deployed docs, updated usage information.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-458158109, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMApCb1867H3lk5MxnQg6LoXdNTYVzks5vHwx7gaJpZM4aKsSV .

bbassac avatar Jan 28 '19 17:01 bbassac

Don't worry, it changed a bit, it's normal getting lost at first when a library suddenly changes.

I'll take a look at the lambda idea. Maybe a traverser stream, which gives an inorder/postorder/preorder stream for the parsed notation, combined with a lambda can be easier to customize.

As for the readable form, an expression like "4d6+5" maybe could be printed as "[4 5 6 4] + 5".

I'll take a look at this as soon as I can.

Bernardo-MG avatar Jan 29 '19 07:01 Bernardo-MG

Added #60 and #61 to handle these issues

Bernardo-MG avatar Jan 29 '19 07:01 Bernardo-MG

But it 's so good to play with dices !!! This format "[4 5 6 4] + 5" seems usefull ! The method 'getFinalRoll' is (for me) not very exact because a final roll is the last roll of a serie. maybe a good method name should be "getFinalResult' ?

I hope it helps you ...

Bruno

Le mar. 29 janv. 2019 à 08:18, Bernardo [email protected] a écrit :

Added #60 https://github.com/Bernardo-MG/dice-notation-java/issues/60 and #61 https://github.com/Bernardo-MG/dice-notation-java/issues/61 to handle these issues

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-458433027, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMAkKgULX-Ha-5NQC3aUHh1GXOlL88ks5vH_XggaJpZM4aKsSV .

bbassac avatar Jan 29 '19 08:01 bbassac

I've added #62 for the method name change.

And it helps a lot having user input. If you think of anything else don't doubt about saying so.

Bernardo-MG avatar Jan 29 '19 08:01 Bernardo-MG

Hi ! I just took the last version of the lib ! And i saw the getTotalToll and TextHistory !

I'm gonna try this !!!!!! Thanx

Le mar. 29 janv. 2019 à 09:43, Bernardo [email protected] a écrit :

I've added #62 https://github.com/Bernardo-MG/dice-notation-java/issues/62 for the method name change.

And it helps a lot having user input. If you think of anything else don't doubt about saying so.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-458454844, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMAscpOvaJE6-mj1rOD0Wv8p_u9mfqks5vIAnFgaJpZM4aKsSV .

bbassac avatar Feb 15 '19 09:02 bbassac

Take note that it is not working correctly yet. But I'm lacking time lately, so I can't tell when will I be able to finish it. With a bit of luck tomorrow I'll be able to move it forward a bit.

Bernardo-MG avatar Feb 15 '19 09:02 Bernardo-MG

I tested it because my code doesn't compile anymore. It seems to works with the few tests I made

Le ven. 15 févr. 2019 à 10:38, Bernardo [email protected] a écrit :

Take note that it is not working correctly yet. But I'm lacking time lately, so I can't tell when will I be able to finish it. With a bit of luck tomorrow I'll be able to move it forward a bit.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bernardo-MG/dice-notation-java/issues/48#issuecomment-463970908, or mute the thread https://github.com/notifications/unsubscribe-auth/AIVMAhefOypWPj5K6dRZEPKs02zr9E9oks5vNn_9gaJpZM4aKsSV .

bbassac avatar Feb 15 '19 09:02 bbassac

I've just moved a new version to develop. Now the history text is generated correctly for all the operations.

Also now the text value is generated with the 'toString' method of RollHistory.

I'll try to smooth this all a bit more before publishing a new version.

Bernardo-MG avatar Feb 16 '19 19:02 Bernardo-MG