• Post Reply Bookmark Topic Watch Topic
  • New Topic

Game of craps rollout name logic  RSS feed

 
gyank kannur
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to print the outcome of crap roll out. Can any design pattern be applied for the logic below

 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gyank,
I think I would be inclined to use a switch statement along with things in your case.

you could even nest the switch statements, but I think you loose readability if you do.

I am a fan of single return point, so I'd go along and do this:

Les

Note: previous code was for example only, not meant to indicate working code.

BTW: || is OR, && is AND.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be inclined to use an array and just look up the names, rather than a forest of if's and else's. (Although consistent indentation would be a design pattern to be considered for the original code.)





I'm leaving the static imports needed to make this work as an exercise for the student.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, I like that much better too ;)
Paul Clapham wrote:I would be inclined to use an array and just look up the names, rather than a forest of if's and else's. (Although consistent indentation would be a design pattern to be considered for the original code.)





I'm leaving the static imports needed to make this work as an exercise for the student.
 
Stephan van Hulst
Saloon Keeper
Posts: 7964
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any difference between an EASYSIX and an EASYSIX2? If not, I would just create a Roll class that has lesserDie() and greaterDie() properties, a name() property that just generates a String based on the total() of the two dice and whether the roll isHard() and isEven():

 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Is there any difference between an EASYSIX and an EASYSIX2?


In the original code, one is produced by rolling 1-5 (in either order) and the other is produced by rolling 2-4 (in either order). I'm not that familiar with the rules or traditions of craps (I can recognize crap when I see it, but that's an entirely different question) so I left that kind of question alone.
 
gyank kannur
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the outcome of easy six can be any combination 1,5 or 2,4. Same with easy eight. That's the reason to differentiate.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but in a craps game, if an eight is rolled, all that matters is if it's easy or hard (unless there is a hop-bet).
 
Stephan van Hulst
Saloon Keeper
Posts: 7964
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gyank kannur wrote:Yes, the outcome of easy six can be any combination 1,5 or 2,4. Same with easy eight. That's the reason to differentiate.


Sure, but why does that matter for the name of the roll? If you want to distinguish between two rolls with the same total, you can just check whether the roll isHard().
 
gyank kannur
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a point, in these cases, names don't matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!