• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Game of craps rollout name logic

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Saloon Keeper
Posts: 15488
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15488
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a point, in these cases, names don't matter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic