Computer Science Canada Turing Tic Tac Toe Help |
Author: | 5ilentAK [ Sat Dec 15, 2012 11:23 pm ] | ||
Post subject: | Turing Tic Tac Toe Help | ||
What is it you are trying to achieve? Creating a Tic Tac Toe Game What is the problem you are having? Do not know how to repeat the code once someone won. The program is supposed to exit once a player has won 3 times or after each round. Also the user may quit the program after every round. I do not know how to implement these codes into my program. Describe what you have tried to solve this problem I tried pasting the whole code into the if statements at the end and it's not working. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using Version 4.1.1 |
Author: | 5ilentAK [ Sun Dec 16, 2012 5:12 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
Please i need help :s |
Author: | Panphobia [ Sun Dec 16, 2012 5:19 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
put it in a procedure and call it three times? |
Author: | 5ilentAK [ Sun Dec 16, 2012 5:43 pm ] |
Post subject: | Re: RE:Turing Tic Tac Toe Help |
Panphobia @ Sun Dec 16, 2012 5:19 pm wrote: put it in a procedure and call it three times?
can you help me write a code for it? |
Author: | Panphobia [ Sun Dec 16, 2012 5:47 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
since it is best of 3 right, just make a procedure with the code you want to repeat three times, then check for wins, and losses and make an if, like if wins = 1 and lose = 1 then call the procedure once more, else if wins = 2 then..... you see what im getting at there, and for the procedure just read about it on the wiki on compsci http://wiki.compsci.ca/index.php?title=Turing_Functions_and_Procedures |
Author: | 5ilentAK [ Sun Dec 16, 2012 6:09 pm ] |
Post subject: | Re: RE:Turing Tic Tac Toe Help |
Can you implement that into my program? I've been trying and i can't seem to get it to work ![]() |
Author: | Panphobia [ Sun Dec 16, 2012 6:11 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
Show me what you have done already, I wont do all the work for you |
Author: | 5ilentAK [ Sun Dec 16, 2012 6:21 pm ] |
Post subject: | Re: Turing Tic Tac Toe Help |
It's kind of rough, and a new program, i tried putting the proc "playAgain" whether the person has tied or won or lost. It doesn't repeat itself though var character : string(1) var player1, player2, first : string var numberOfWins1, numberOfWins2: int var x, y : int var command : string var mark : array 1 .. 3, 1 .. 3 of int var midx, midy, counter, win, z : int := 0 numberOfWins1 := 0 numberOfWins2 := 0 player1 := "1" player2 := "2" first := player1 put "Number Of Wins" put "--------------" put player1, ": ", numberOfWins1 put player2, ": ", numberOfWins2 proc choice counter += 1 if counter mod 2 = 0 then drawoval (midx, midy, 20, 20, black) elsif counter mod 2 = 1 then drawline (midx - 25, midy - 25, midx + 25, midy + 25, black) drawline (midx - 25, midy + 25, midx + 25, midy - 25, black) end if end choice for a : 1 .. 3 for b : 1 .. 3 mark (a, b) := 0 end for end for procedure playAgain ( n : int ) for i : 1 .. n Draw.ThickLine (500, 250, 500, 50, 3, 12) Draw.ThickLine (400, 250, 400, 50, 3, 12) Draw.ThickLine (300, 120, 600, 120, 3, 12) Draw.ThickLine (300, 190, 600, 190, 3, 12) loop Mouse.Where (x, y, z) if x >= 302 and y >= 193 and x <= 396 and y <= 249 and z=1 and mark (1, 1) = 0 then midx := 349 midy := 221 choice if counter mod 2 = 0 then mark (1, 1) := 2 elsif counter mod 2 = 1 then mark (1, 1) := 1 end if elsif x >= 404 and y >= 193 and x <= 497 and y <= 249 and z=1 and mark (1, 2) = 0 then midx := 451 midy := 221 choice if counter mod 2 = 0 then mark (1, 2) := 2 elsif counter mod 2 = 1 then mark (1, 2) := 1 end if elsif x >= 504 and y >= 193 and x <= 598 and y <= 249 and z=1 and mark (1, 3) = 0 then midx := 551 midy := 221 choice if counter mod 2 = 0 then mark (1, 3) := 2 elsif counter mod 2 = 1 then mark (1, 3) := 1 end if elsif x >= 302 and y >= 127 and x <= 396 and y <= 188 and z=1 and mark (2, 1) = 0 then midx := 349 midy := 158 choice if counter mod 2 = 0 then mark (2, 1) := 2 elsif counter mod 2 = 1 then mark (2, 1) := 1 end if elsif x >= 402 and y >= 122 and x <= 498 and y <= 188 and z=1 and mark (2, 2) = 0 then midx := 450 midy := 155 choice if counter mod 2 = 0 then mark (2, 2) := 2 elsif counter mod 2 = 1 then mark (2, 2) := 1 end if elsif x >= 504 and y >= 124 and x <= 598 and y <= 186 and z=1 and mark (2, 3) = 0 then midx := 551 midy := 155 choice if counter mod 2 = 0 then mark (2, 3) := 2 elsif counter mod 2 = 1 then mark (2, 3) := 1 end if elsif x >= 302 and y >= 51 and x <= 396 and y <= 116 and z=1 and mark (3, 1) = 0 then midx := 349 midy := 84 choice if counter mod 2 = 0 then mark (3, 1) := 2 elsif counter mod 2 = 1 then mark (3, 1) := 1 end if elsif x >= 404 and y >= 53 and x <= 497 and y <= 116 and z=1 and mark (3, 2) = 0 then midx := 451 midy := 84 choice if counter mod 2 = 0 then mark (3, 2) := 2 elsif counter mod 2 = 1 then mark (3, 2) := 1 end if elsif x >= 504 and y >= 51 and x <= 598 and y <= 114 and z=1 and mark (3, 3) = 0 then midx := 551 midy := 84 choice if counter mod 2 = 0 then mark (3, 3) := 2 elsif counter mod 2 = 1 then mark (3, 3) := 1 end if end if if mark (1, 1) = mark (1, 2) and mark (1, 2) = mark (1, 3) and mark (1, 2) not= 0 then win := mark (1, 1) elsif mark (2, 1) = mark (2, 2) and mark (2, 2) = mark (2, 3) and mark (2, 2) not= 0 then win := mark (2, 1) elsif mark (3, 1) = mark (3, 2) and mark (3, 2) = mark (3, 3) and mark (3, 2) not= 0 then win := mark (3, 1) elsif mark (1, 1) = mark (2, 1) and mark (2, 1) = mark (3, 1) and mark (2, 1) not= 0 then win := mark (1, 1) elsif mark (1, 2) = mark (2, 2) and mark (2, 2) = mark (3, 2) and mark (2, 2) not= 0 then win := mark (1, 2) elsif mark (1, 3) = mark (2, 3) and mark (2, 3) = mark (3, 3) and mark (2, 3) not= 0 then win := mark (1, 3) elsif mark (1, 1) = mark (2, 2) and mark (2, 2) = mark (3, 3) and mark (2, 2) not= 0 then win := mark (1, 1) elsif mark (1, 3) = mark (2, 2) and mark (2, 2) = mark (3, 1) and mark (2, 2) not= 0 then win := mark (1, 3) end if delay (90) exit when win not= 0 exit when counter = 9 end loop end for end playAgain playAgain (1) loop if mark (1, 1) = mark (1, 2) and mark (1, 2) = mark (1, 3) and mark (1, 2) not= 0 then win := mark (1, 1) elsif mark (2, 1) = mark (2, 2) and mark (2, 2) = mark (2, 3) and mark (2, 2) not= 0 then win := mark (2, 1) elsif mark (3, 1) = mark (3, 2) and mark (3, 2) = mark (3, 3) and mark (3, 2) not= 0 then win := mark (3, 1) elsif mark (1, 1) = mark (2, 1) and mark (2, 1) = mark (3, 1) and mark (2, 1) not= 0 then win := mark (1, 1) elsif mark (1, 2) = mark (2, 2) and mark (2, 2) = mark (3, 2) and mark (2, 2) not= 0 then win := mark (1, 2) elsif mark (1, 3) = mark (2, 3) and mark (2, 3) = mark (3, 3) and mark (2, 3) not= 0 then win := mark (1, 3) elsif mark (1, 1) = mark (2, 2) and mark (2, 2) = mark (3, 3) and mark (2, 2) not= 0 then win := mark (1, 1) elsif mark (1, 3) = mark (2, 2) and mark (2, 2) = mark (3, 1) and mark (2, 2) not= 0 then win := mark (1, 3) end if delay (90) exit when win not= 0 exit when counter = 9 end loop if counter = 9 then put "tied" put "Do you want to play again?" get command if command = "yes" then playAgain(1) end if elsif win = 1 and first = player2 then put player2, " won!" numberOfWins2 := numberOfWins2 +1 put "Do you want to play again?" get command if command = "yes" then playAgain(1) end if elsif win = 1 and first = player1 then put player1, " won!" numberOfWins1 := numberOfWins1 +1 put "Do you want to play again?" get command if command = "yes" then playAgain(1) end if elsif win = 2 and first = player2 then put player2, " won!" numberOfWins2 := numberOfWins2 +1 put "Do you want to play again?" get command if command = "yes" then playAgain(1) end if elsif win = 2 and first = player1 then put player1, " won!" numberOfWins1 := numberOfWins1 +1 put "Do you want to play again?" get command if command = "yes" then playAgain(1) end if end if |
Author: | Panphobia [ Sun Dec 16, 2012 6:25 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
can you use code brackets, and please can you make your code cleaner, commenting maybe? Also make an algorithm that decides the winner, not just using one giant if. But I will see what the problem is |
Author: | 5ilentAK [ Sun Dec 16, 2012 6:33 pm ] | ||
Post subject: | Re: Turing Tic Tac Toe Help | ||
|
Author: | Panphobia [ Sun Dec 16, 2012 6:45 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
I would suggest cleaning up your code, so it is more readable, adding comments like I said, and maybe suggest scrapping some of it, so it is easier for you to understand why it is not giving you the option to play again, but it is calling the procedure, check out why when you say yes it is finishing your programs execution, i made a put statement in your procedure and it does output it, so your problem is not that it isnt being executed |
Author: | 5ilentAK [ Sun Dec 16, 2012 7:08 pm ] |
Post subject: | RE:Turing Tic Tac Toe Help |
I noticed that the proc does execute, but i still don't see how it's not allowing me to play it again ![]() |