Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Cointoss Game Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nelsonkkyy




PostPosted: 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
Sponsor
sponsor
Superskull85




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: