tic tac toe loops help !!
Author |
Message |
ddndd
|
Posted: Fri Dec 18, 2009 2:36 pm Post subject: tic tac toe loops help !! |
|
|
What is it you are trying to achieve?
<im trying to make a tic tac toe game, >
What is the problem you are having?
<im stuck, im not sure where to put my loops >
Describe what you have tried to solve this problem
i tried different things like putting the loops in different places but it didnt work,
i still says finished when i run it>
Please specify what version of Turing you are using
<4.1.1>
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
mouse tik tac toe.t |
Filesize: |
15.05 KB |
Downloaded: |
201 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Fri Dec 18, 2009 3:14 pm Post subject: Re: tic tac toe loops help !! |
|
|
Your loops are in the right place. Your problem is this little chunk here:
Turing: |
if box1 not= 1 and box2 not= 1 and box3 not= 1 and box4 not= 1 and box5 not= 1 and box6 not= 1 and box7 not= 1 and box8 not= 1 and box9 not= 1 then
put "no one wins"
exit
end if
|
When the game starts, what are the values of the boxes? Will any of the boxes be equal to 1?
Next problem, mousewhere is not blocking. This means that when you call mousewhere, Turing just checks to see if there is input, it doesn't wait for input to happen (unlike, for example, get which halts the program and waits for keyboard input). This means that the player won't get a chance to play the game. You need to keep track of whose turn it is and only run the code for that person.
Finally, each and every time your computer takes a turn, you put in an exit statement. Is there a reason you want the loop to exit whenever the computer chooses a square?
|
|
|
|
|
![](images/spacer.gif) |
ddndd
|
Posted: Fri Dec 18, 2009 3:43 pm Post subject: Re: tic tac toe loops help !! |
|
|
TheGuardian001 @ Fri Dec 18, 2009 3:14 pm wrote: Your loops are in the right place. Your problem is this little chunk here:
Turing: |
if box1 not= 1 and box2 not= 1 and box3 not= 1 and box4 not= 1 and box5 not= 1 and box6 not= 1 and box7 not= 1 and box8 not= 1 and box9 not= 1 then
put "no one wins"
exit
end if
|
When the game starts, what are the values of the boxes? Will any of the boxes be equal to 1?
Next problem, mousewhere is not blocking. This means that when you call mousewhere, Turing just checks to see if there is input, it doesn't wait for input to happen (unlike, for example, get which halts the program and waits for keyboard input). This means that the player won't get a chance to play the game. You need to keep track of whose turn it is and only run the code for that person.
Finally, each and every time your computer takes a turn, you put in an exit statement. Is there a reason you want the loop to exit whenever the computer chooses a square?
ok the value of the boxes is 0 when the game starts
im not sure about what you are talking about for the mouse part, do you mean i have to use Mouse.ButtonWait ??
and i used the exit statements so that the computer cant have more than one turn if i take that out the computer will put more than one x which is not part of the game
thank you for the fast response tho
|
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Fri Dec 18, 2009 4:23 pm Post subject: Re: tic tac toe loops help !! |
|
|
ddndd wrote:
ok the value of the boxes is 0 when the game starts
So what will happen when the if statement I showed get run? will your loop keep running?
ddndd wrote:
im not sure about what you are talking about for the mouse part, do you mean i have to use Mouse.ButtonWait ??
No, you do want to use mousewhere, but since it doesn't wait for input, you will need to keep track of whose turn it is.
for example
code: |
var turn : int := 0
loop
if turn = 0
Do stuff for player
%once the players turn is over, set
turn := 1 %it is now the computers turn
elsif turn = 1
Do stuff for computer
%once the computers turn is over, set
turn = 0 %it is now the players turn again.
end if
end loop
|
This means you that the code for the computer won't be run unless it's their turn, and the code for the player can't be run unless it's their turn.
ddndd wrote:
and i used the exit statements so that the computer cant have more than one turn
As for all the exits you put in, that isn't what they're doing at all. When you put an exit in, you exit whatever loop you are in. Can you tell me what's after your loop? What will the program do when it exits the loop?
|
|
|
|
|
![](images/spacer.gif) |
ddndd
|
Posted: Fri Dec 18, 2009 5:18 pm Post subject: Re: tic tac toe loops help !! |
|
|
TheGuardian001 @ Fri Dec 18, 2009 4:23 pm wrote: ddndd wrote:
ok the value of the boxes is 0 when the game starts
So what will happen when the if statement I showed get run? will your loop keep running?
ddndd wrote:
im not sure about what you are talking about for the mouse part, do you mean i have to use Mouse.ButtonWait ??
No, you do want to use mousewhere, but since it doesn't wait for input, you will need to keep track of whose turn it is.
for example
code: |
var turn : int := 0
loop
if turn = 0
Do stuff for player
%once the players turn is over, set
turn := 1 %it is now the computers turn
elsif turn = 1
Do stuff for computer
%once the computers turn is over, set
turn = 0 %it is now the players turn again.
end if
end loop
|
This means you that the code for the computer won't be run unless it's their turn, and the code for the player can't be run unless it's their turn.
ddndd wrote:
and i used the exit statements so that the computer cant have more than one turn
As for all the exits you put in, that isn't what they're doing at all. When you put an exit in, you exit whatever loop you are in. Can you tell me what's after your loop? What will the program do when it exits the loop?
ok so i got it to work because i took out some of the exits and the no one wins statements but now the i have another problem which is the computer can be defeated easily so idk what to do to make it harder any ideas ??
i attached the new file after the changes so you guys can see all the new changes
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
mouse tik tac toe.t |
Filesize: |
15.95 KB |
Downloaded: |
128 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
ddndd
|
Posted: Sun Dec 20, 2009 11:50 pm Post subject: Re: tic tac toe loops help !! |
|
|
hmmmm 5 downloads and no comments ...
|
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Mon Dec 21, 2009 1:18 am Post subject: Re: tic tac toe loops help !! |
|
|
There's no real way to help you make it harder.
Just think of how you would react to different situations, then program them in. You could try making it look for specific patterns, or even specific moves. Ultimately it'll just be up to the number of different situations you tell it to react to.
Tic-tac-toe is a reasonably difficult game to make a really good AI for, since it can only react properly to what you tell it to react to. Unless you write in every possible way they can win (and normally even if you do), it generally comes down to luck.
One thing you could try putting in would be not letting it put an X in a space that doesn't have a chance of giving it a line, unless no options that do are available. For example, if the current board is:
It should know not to place an X in the top center square, as this can't possibly get it a row.
As for how you'd actually program that, I have no idea without thinking it through properly.
|
|
|
|
|
![](images/spacer.gif) |
|
|