Turing Connect Four Stacking Problem
| Author |
Message |
Michael3176
|
Posted: Sat Jan 05, 2013 10:07 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| Ok i will next time sorry, and Well I think the proc is there to trap anything full columns and allow me to place a token where there is open space, but I don't know identify when a column was chosen twice or 3 times, and as to which doesn't belong , I guess it would be the draw command considering you said I'm not filling it it in here ? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Raknarg

|
Posted: Sat Jan 05, 2013 10:25 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| Sorry, you mind clarifying your question? |
|
|
|
|
 |
Michael3176
|
Posted: Sat Jan 05, 2013 10:33 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
Im not sure how to get my program to now draw the counters when the user chooses a coloumn, and have them stack one upon the other using the
searchColumn procedure, so i am wondering what code would i now put in my display procedure to make the counters display stacked upon eachother like connect four would run. |
|
|
|
|
 |
Raknarg

|
Posted: Sat Jan 05, 2013 10:35 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| The same way you were trying to do it before, thats the correct way, just instead of the searching procedure put it in the display prodecure |
|
|
|
|
 |
Michael3176
|
Posted: Sat Jan 05, 2013 10:45 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| when i do that it says, "i" has not been declared, and also, it does not display properly, the counters do not stack one at a time, all the counters will stack up to 6 in the column chosen, and i do not know why, i can post the code of the game again if you are confused? |
|
|
|
|
 |
Raknarg

|
Posted: Sat Jan 05, 2013 10:46 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| sure, lets see what you have now |
|
|
|
|
 |
Michael3176
|
Posted: Sat Jan 05, 2013 10:51 pm Post subject: Re: Turing Connect Four Stacking Problem |
|
|
code:
| Turing: |
import GUI
var mainWin := Window.Open ("position:300;300, graphics:660;500")
var coloumn : int
var player : int := 1
var done, validMove : boolean
var board : array 1 .. 7, 1 .. 6 of int
forward proc mainMenu
procedure setup
for x : 1 .. 7
for y : 1 .. 6
board (x, y ) := 0
end for
end for
end setup
proc searchColoumn
setup
for decreasing i : 6 .. 0
if i = 0 then
board (coloumn, 1) := player
validMove := true
exit
elsif board (coloumn, i ) not= 0 then
if i = 6 then
validMove := false
exit
else
board (coloumn, i + 1) := player
validMove := true
exit
end if
end if
if player = 1 then
Draw.FillOval ((coloumn + 2) * 50, i * 50, 20, 20, red)
else
Draw.FillOval ((coloumn + 2) * 50, i * 50, 20, 20, blue)
end if
end for
end searchColoumn
proc title
cls
locate (1, 36)
put "Connect Four"
put ""
end title
proc switch
if player = 1 then
player := 2
else
player := 1
end if
end switch
proc pauseProgram
var reply : string (1)
put ""
put "Press any key to continue...." ..
getch (reply )
end pauseProgram
proc intro
title
var menuButton := GUI.CreateButton (295, 50, 0, "Main Menu", mainMenu )
end intro
proc instructions
title
put
"Connect Four is a two player game on which playes take turns dropping tokens into a 7x6 grid falling vertically. Players win by getting four tokens in a row in any straight direction. Click on one of the top cirlces to drop a token."
var menuButton := GUI.CreateButton (295, 50, 0, "Main Menu", mainMenu )
end instructions
proc checkWin
done := false
if whatdotcolour (65, 35) = red and whatdotcolour (150, 35) = red and whatdotcolour (240, 35) = red and whatdotcolour (330, 35) = red then
locate (2, 1)
put "Player one has won."
done := true
elsif whatdotcolour (65, 35) = blue and whatdotcolour (150, 35) = blue and whatdotcolour (240, 35) = blue and whatdotcolour (330, 35) = blue then
locate (2, 1)
put "Player two has won."
done := true
elsif whatdotcolour (150, 35) = red and whatdotcolour (240, 35) = red and whatdotcolour (330, 35) = red and whatdotcolour (420, 35) = red then
locate (2, 1)
put "Player one has won."
done := true
elsif whatdotcolour (150, 35) = blue and whatdotcolour (240, 35) = blue and whatdotcolour (330, 35) = blue and whatdotcolour (420, 35) = blue then
locate (2, 1)
put "Player two has won."
done := true
elsif whatdotcolour (240, 35) = red and whatdotcolour (330, 35) = red and whatdotcolour (420, 35) = red and whatdotcolour (505, 35) = red then
locate (2, 1)
put "Player one has won."
done := true
elsif whatdotcolour (240, 35) = red and whatdotcolour (330, 35) = red and whatdotcolour (420, 35) = red and whatdotcolour (505, 35) = red then
locate (2, 1)
put "Player two has won."
done := true
elsif whatdotcolour (330, 35) = red and whatdotcolour (420, 35) = red and whatdotcolour (505, 35) = red and whatdotcolour (595, 35) = red then
locate (2, 1)
put "Player one has won."
done := true
elsif whatdotcolour (330, 35) = blue and whatdotcolour (420, 35) = blue and whatdotcolour (505, 35) = blue and whatdotcolour (595, 35) = blue then
locate (2, 1)
put "Player two has won."
done := true
else
done := false
end if
end checkWin
proc processing
searchColoumn
switch
end processing
proc display
end display
proc userInput
title
display
loop
locate (2, 1)
put "Player ", player, ",please enter a coloumn number: " ..
get coloumn
if coloumn < 1 or coloumn > 7 then
locate (2, 1)
put "Player ", player, ",please enter coloums 1-9 only: " ..
get coloumn
else
processing
display
checkWin
end if
exit when done = true
end loop
end userInput
proc goodBye
title
put "Made by Michael Bartella."
delay (1300)
Window.Close (mainWin )
end goodBye
body proc mainMenu
title
var intrusctionsButton := GUI.CreateButton (295, 300, 100, "Instructions", instructions )
var newGameButton := GUI.CreateButton (295, 200, 100, "New Game", userInput )
var exitB := GUI.CreateButtonFull (295, 100, 100, "Exit", GUI.Quit, 0, KEY_ESC, false)
end mainMenu
intro
loop
exit when GUI.ProcessEvent
end loop
goodBye
|
|
|
|
|
|
 |
jr5000pwp
|
Posted: Sat Jan 05, 2013 11:05 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| Turing: | for decreasing i : 6 .. 0 | loops through all rows in a column, right? And is inside that loop, what do you think is gonna happen? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Michael3176
|
Posted: Sat Jan 05, 2013 11:12 pm Post subject: Re: Turing Connect Four Stacking Problem |
|
|
| I know but i dont know where else to put it, because thats the only place in my program where i has been declared. |
|
|
|
|
 |
Insectoid

|
Posted: Sat Jan 05, 2013 11:15 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| You don't have to use i. You can use a new for loop. You could use p if you wanted. Or q. Or gfefreqwrewhr (though I don't recommend it). |
|
|
|
|
 |
Michael3176
|
Posted: Sat Jan 05, 2013 11:30 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| i know, but thats where im getting at, i dont know what to put in this for loop or how to use it with the draw command |
|
|
|
|
 |
Michael3176
|
Posted: Sun Jan 06, 2013 9:50 am Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| So any idea on what code I should use? |
|
|
|
|
 |
Raknarg

|
Posted: Sun Jan 06, 2013 1:20 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| Yes we do, but we're trying to get you to see things for yourself |
|
|
|
|
 |
Michael3176
|
Posted: Sun Jan 06, 2013 3:42 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| ive been trying for a while now and have no idea, i made put the draw command in a display procedure, i had a for loop in that of 1..6 and all the counters showed up at once again, i have no idea what to do. |
|
|
|
|
 |
Michael3176
|
Posted: Sun Jan 06, 2013 10:09 pm Post subject: RE:Turing Connect Four Stacking Problem |
|
|
| ? |
|
|
|
|
 |
|
|