Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to start a Yatzy game

Status
Not open for further replies.

gasolin

Programmer
Feb 28, 2003
1
DK
Hi

I like to start programing a game call Yatzy, its a dice game with 5 dice.

But I dont have a clue on have to make the code so it can recognize the dice to see if the player have 2 pair or 3 identical or a house with is 2+3 identical and so on...

I dont expected a full code, but only ideas how to make the recognize code.
 
You could draw an old-fashioned flow chart and try to handle all of the various branches, but that will get messy in a hurry.

If I were doing it, I would probably write a series of functions to test for specific holdings. Assuming that you have defined a type to describe the dice, you would have a series of functions something like these:
Code:
function IsYatzy( dice:TDice ): boolean;
end;

function IsFourOfAKind( dice:TDice ): boolean;
end;

function IsFullHouse( dice:TDice ): boolean;
end;

etc.
then you would have a top-level routine to work you way down the list. Of course, if your version works the way Yahtzee does, just because you rolled a full house you may only be able to play three of a kind (or maybe just a pair). So it's not enough just to find the "best" hand, you have to find the best hand that can be played.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top