Cointoss Game Help
Author |
Message |
nelsonkkyy
|
Posted: Wed Nov 04, 2009 8:04 pm Post subject: Cointoss Game Help |
|
|
What is it you are trying to achieve?
I am making a coin toss game. First, the coin toss three times and 2 people are playing.For each player they have to choose 3 times (Like,Head,tail,head {HTH}).To win this game, who get the most correct of sides and that is the winner.
What is the problem you are having?
<Now i am stuck in the last part which is how to deciede who is the winner. Can anyone help me?>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
var T1,T2:string
put "PLAYER1 choose a triplet,H/T"
get T1
put "PLAYER1 choose a different triplet,H/T"
get T2
put "player 1 choose"," ",T1
put "player 2 choose"," ",T2
put" "
put"The Triplets are..."
put" "
var coin:array 1..3 of int
for i : 1..3
coin(i):=Rand.Int(1,2)
if coin(i) = 1 then
put "H"
elsif coin(i) = 2 then
put "T"
end if
end for
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Superskull85
|
Posted: Wed Nov 04, 2009 9:54 pm Post subject: RE:Cointoss Game Help |
|
|
Well you could add the outcomes together and check for different situations. If the total is equal to (1 * 3) (if all of the outcomes were heads) than whoever chose heads wins. If the total is equal to (2 * 3) (if all of the outcome were tails) than whoever chose tails wins.
For the other two possibilities (1, 1, 2) or (1, 2, 2), in any order, the total would be 4 and 5 respectively. If the first two possibilities are false than check if the total is evenly divisible by 2. If it is, than whoever chose heads wins. If it isn't, than whoever chose tails wins.
This method only works for three outcomes. However, you could extend it to include any odd amount of outcomes. If you want to include an even amount of outcomes, you will have to include a check for the possibility of getting the same amount of heads as tails. |
|
|
|
|
|
|
|