Computer Science Canada tic tac toe (2) |
Author: | montyburns [ Wed Jan 07, 2004 11:17 am ] |
Post subject: | tic tac toe (2) |
Need help making ai for simple tic tac toe game in turing. here is my program that, so far, only inputs the x anywhere the user wants. if not a simple ai could i get help for having a second person input using the mouse. i am a beginner. this includes programmer comments %Declaration Section var x, y, button : int %Sets the screen size setscreen ("graphics") setscreen ("graphics:400;400") %Makes the background drawfillbox (0, 0, maxx, maxy, black) %Draws the large box drawbox (5, 5, maxx - 5, maxy - 5, yellow) %Draws the smaller boxes drawline (maxx div 3, maxy - 5, maxx div 3, 5, yellow) drawline (maxx div 1.5, maxy - 5, maxx div 1.5, 5, yellow) drawline (maxx - 5, maxy div 3, 5, maxy div 3, yellow) drawline (maxx - 5, maxy div 1.5, 5, maxy div 1.5, yellow) %puts the x's in the boxes which have been clicked loop mousewhere (x, y, button) if x >= 5 and x <= maxx div 3 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 then drawline (10, maxy - 10, maxx div 3 - 10, maxy div 1.5 + 10, yellow) drawline (10, maxy div 1.5 + 10, maxx div 3 - 10, maxy - 10, yellow) elsif x >= maxx div 3 and x <= maxx div 1.5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 then drawline (maxx div 3 + 10, maxy - 10, maxx div 1.5 - 10, maxy div 1.5 + 10, yellow) drawline (maxx div 3 + 10, maxy div 1.5 + 10, maxx div 1.5 - 10, maxy - 10, yellow) elsif x >= maxx div 1.5 and x <= maxx - 5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 then drawline (maxx div 1.5 + 10, maxy - 10, maxx - 10, maxy div 1.5 + 10, yellow) drawline (maxx div 1.5 + 10, maxy div 1.5 + 10, maxx - 10, maxy - 10, yellow) elsif x >= 5 and x <= maxx div 3 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 then drawline (10, maxy div 3 + 10, maxx div 3 - 10, maxy div 1.5 - 10, yellow) drawline (10, maxy div 1.5 - 10, maxx div 3 - 10, maxy div 3 + 10, yellow) elsif x >= maxx div 3 and x <= maxx div 1.5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 then drawline (maxx div 3 + 10, maxy div 3 + 10, maxx div 1.5 - 10, maxy div 1.5 - 10, yellow) drawline (maxx div 3 + 10, maxy div 1.5 - 10, maxx div 1.5 - 10, maxy div 3 + 10, yellow) elsif x >= maxx div 1.5 and x <= maxx - 5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 then drawline (maxx div 1.5 + 10, maxy div 3 + 10, maxx - 10, maxy div 1.5 - 10, yellow) drawline (maxx div 1.5 + 10, maxy div 1.5 - 10, maxx - 10, maxy div 3 + 10, yellow) elsif x >= 5 and x <= maxx div 3 and y >= 5 and y <= maxy div 3 and button = 1 then drawline (10, maxy div 3 - 10, maxx div 3 - 10, 10, yellow) drawline (10, 10, maxx div 3 - 10, maxy div 3 - 10, yellow) elsif x >= maxx div 3 and x <= maxx div 1.5 and y >= 5 and y <= maxy div 3 and button = 1 then drawline (maxx div 3 + 10, maxy div 3 - 10, maxx div 1.5 - 10, 10, yellow) drawline (maxx div 3 + 10, 10, maxx div 1.5 - 10, maxy div 3 - 10, yellow) elsif x >= maxx div 1.5 and x <= maxx - 5 and y >= 5 and y <= maxy div 3 and button = 1 then drawline (maxx div 1.5 + 10, 10, maxx - 10, maxy div 3 - 10, yellow) drawline (maxx div 1.5 + 10, maxy div 3 - 10, maxx - 10, 10, yellow) end if end loop |
Author: | DanShadow [ Fri Jan 09, 2004 3:45 pm ] | ||
Post subject: | |||
You could have an array (square:array 1..9 of string) that tells the computer whether the box is used or not. So, for example,
|
Author: | santabruzer [ Fri Jan 09, 2004 6:36 pm ] |
Post subject: | |
wouldn't it be easier to use a 2d array.. with one as the row and the other as the col i.e. (square : array 1..3, 1..3) |
Author: | DanShadow [ Fri Jan 09, 2004 6:46 pm ] |
Post subject: | |
well yes...it would be easier. But I usually wont post something unless everyone will understand it. Like some newbie programmers wont understand getting arrays past the first dimension, so i just put the code up like so. |
Author: | santabruzer [ Fri Jan 09, 2004 6:47 pm ] |
Post subject: | |
ha ha.. yea..... almost done my ISU though.. i realized it's utter crap ![]() |
Author: | DanShadow [ Fri Jan 09, 2004 6:55 pm ] |
Post subject: | |
Exact same here, lol. I did a two player, graphical RPG using key board to move...and got bored in Communication Technology class...and ended up making a 100 line program that was like 10x better, lol. Stupid ISU. So, what did you make your ISU? |
Author: | santabruzer [ Fri Jan 09, 2004 6:57 pm ] |
Post subject: | |
Tetris.. the amazing world of it.. oh man.. i dunnu.. i still say my game is utter crap but i dunnu.. for gr. 10 that's probalby fine ![]() |
Author: | DanShadow [ Fri Jan 09, 2004 7:07 pm ] |
Post subject: | |
yeah, for gr.10 thats awesome. Lucky you, actually getting computer science taught to you in gr.10...im in gr.11 and im just being taught it now. I hate how underfunded Computer Science really is...makes me want to set fire to the education district management people... gr ![]() |
Author: | montyburns [ Mon Jan 12, 2004 6:12 am ] |
Post subject: | |
computer science in underrated in high school because they only want you to learn the basics before you have to pays thousands of dollars a year for university or college. btw thanx for the help |
Author: | montyburns [ Mon Jan 12, 2004 10:46 am ] |
Post subject: | |
i have a new problem but i'm not using the ai because i don't have enough time to program. my problem is that i can only click two of the squares before the program stops working. also if the top left corner square is not clicked an x will appear automatically. here is the new program %Declaration Section var xpos, y, button : int var count : int := 1 var box1, box2, box3, box4, box5, box6, box7, box8, box9, x, o : boolean := false %Sets the screen size setscreen ("graphics") setscreen ("graphics:400;400") %Makes the background drawfillbox (0, 0, maxx, maxy, black) %Draws the smaller boxes drawbox (5, 5, maxx div 3, maxy div 3, yellow) drawbox (maxx div 3, 5, maxx div 1.5, maxy div 3, yellow) drawbox (maxx div 1.5, 5, maxx - 5, maxy div 3, yellow) drawbox (5, maxy div 3, maxx div 3, maxy div 1.5, yellow) drawbox (maxx div 3, maxy div 3, maxx div 1.5, maxy div 1.5, yellow) drawbox (maxx div 1.5, maxy div 3, maxx - 5, maxy div 1.5, yellow) drawbox (5, maxy div 1.5, maxx div 3, maxy - 5, yellow) drawbox (maxx div 3, maxy div 1.5, maxx div 1.5, maxy - 5, yellow) drawbox (maxx div 1.5, maxy div 1.5, maxx - 5, maxy - 5, yellow) %puts the x's and o's in the boxes which have been clicked loop mousewhere (xpos, y, button) if xpos >= 5 and xpos <= maxx div 3 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box1 then else drawline (10, maxy - 10, maxx div 3 - 10, maxy div 1.5 + 10, yellow) drawline (10, maxy div 1.5 + 10, maxx div 3 - 10, maxy - 10, yellow) count := count + 1 box1 := true end if elsif xpos >= 5 and xpos <= maxx div 3 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box1 then else drawoval (maxx div 3 div 2, maxy - 65, 55, 55, yellow) count := count + 1 box1 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box2 then else drawline (maxx div 3 + 10, maxy - 10, maxx div 1.5 - 10, maxy div 1.5 + 10, yellow) drawline (maxx div 3 + 10, maxy div 1.5 + 10, maxx div 1.5 - 10, maxy - 10, yellow) count := count + 1 box2 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box2 then else drawoval (maxx div 2, maxy - 65, 55, 55, yellow) count := count + 1 box2 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box3 then else drawline (maxx div 1.5 + 10, maxy - 10, maxx - 10, maxy div 1.5 + 10, yellow) drawline (maxx div 1.5 + 10, maxy div 1.5 + 10, maxx - 10, maxy - 10, yellow) count := count + 1 box3 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y >= maxy div 1.5 and y <= maxy - 5 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box3 then else drawoval (maxx - 65, maxy - 65, 55, 55, yellow) count := count + 1 box3 := true end if elsif xpos >= 5 and xpos <= maxx div 3 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box4 then else drawline (10, maxy div 3 + 10, maxx div 3 - 10, maxy div 1.5 - 10, yellow) drawline (10, maxy div 1.5 - 10, maxx div 3 - 10, maxy div 3 + 10, yellow) count := count + 1 box4 := true end if elsif xpos >= 5 and xpos <= maxx div 3 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box4 then else drawoval (maxx div 3 div 2, maxy div 1.5 - 60, 55, 55, yellow) count := count + 1 box4 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box5 then else drawline (maxx div 3 + 10, maxy div 3 + 10, maxx div 1.5 - 10, maxy div 1.5 - 10, yellow) drawline (maxx div 3 + 10, maxy div 1.5 - 10, maxx div 1.5 - 10, maxy div 3 + 10, yellow) count := count + 1 box5 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box5 then else drawoval (maxx div 2, maxy div 1.5 - 60, 55, 55, yellow) count := count + 1 box5 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box6 then else drawline (maxx div 1.5 + 10, maxy div 3 + 10, maxx - 10, maxy div 1.5 - 10, yellow) drawline (maxx div 1.5 + 10, maxy div 1.5 - 10, maxx - 10, maxy div 3 + 10, yellow) count := count + 1 box6 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y <= maxy div 1.5 and y >= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box6 then else drawoval (maxx - 65, maxy div 1.5 - 60, 55, 55, yellow) count := count + 1 box6 := true end if elsif xpos >= 5 and xpos <= maxx div 3 and y >= 5 and y <= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box7 then else drawline (10, maxy div 3 - 10, maxx div 3 - 10, 10, yellow) drawline (10, 10, maxx div 3 - 10, maxy div 3 - 10, yellow) count := count + 1 box7 := true end if elsif xpos >= 5 and xpos <= maxx div 3 and y >= 5 and y <= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box7 then else drawoval (maxx div 3 div 2, maxy div 3 - 60, 55, 55, yellow) count := count + 1 box7 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y >= 5 and y <= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box8 then else drawline (maxx div 3 + 10, maxy div 3 - 10, maxx div 1.5 - 10, 10, yellow) drawline (maxx div 3 + 10, 10, maxx div 1.5 - 10, maxy div 3 - 10, yellow) count := count + 1 box8 := true end if elsif xpos >= maxx div 3 and xpos <= maxx div 1.5 and y >= 5 and y <= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box8 then else drawoval (maxx div 2, maxy div 3 - 60, 55, 55, yellow) count := count + 1 box8 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y >= 5 and y <= maxy div 3 and button = 1 and count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then if box9 then else drawline (maxx div 1.5 + 10, 10, maxx - 10, maxy div 3 - 10, yellow) drawline (maxx div 1.5 + 10, maxy div 3 - 10, maxx - 10, 10, yellow) count := count + 1 box9 := true end if elsif xpos >= maxx div 1.5 and xpos <= maxx - 5 and y >= 5 and y <= maxy div 3 and button = 1 and count = 2 or count = 4 or count = 6 or count = 8 then if box9 then else drawoval (maxx - 65, maxy div 3 - 60, 55, 55, yellow) count := count + 1 box9 := true end if end if end loop |