
-----------------------------------
cycro1234
Sun Jan 16, 2005 10:38 pm

4 in a row check
-----------------------------------
How would I make a procedure that checks in my connect 4 game if there are 4 of the same colour in a row? Do I use whatdotcolour?

-----------------------------------
cycro1234
Sun Jan 16, 2005 10:42 pm


-----------------------------------
I have something like this :

 if whatdotcolour (x, y) = 12 and whatdotcolour (x+70, y) = 12 and whatdotcolour (x+140, y) = 12 then
    put "Game Over"
end if 

However, there are many possibilities, since the player can get 4 in a row left to right, diagonally, and up and down. Is there a shorter way than this? Or more effective?

-----------------------------------
Bacchus
Sun Jan 16, 2005 11:19 pm


-----------------------------------
instead of always checking them, when the token you watever you use to mark a space when the player chooses it, i would set an array to the color. then all you have to do is compare arrays

-----------------------------------
cycro1234
Sun Jan 16, 2005 11:44 pm


-----------------------------------
How would I do that? An example please? I'm still kinda new to arrays.

-----------------------------------
cycro1234
Thu Jan 20, 2005 12:33 pm


-----------------------------------
*Sigh* One day left til it's due, and I'm STILL stuck. I haven't figured out how to make my program work with arrays. ANy help at all would be greatly appreciated.   :cry:

-----------------------------------
eNc
Thu Jan 20, 2005 4:24 pm


-----------------------------------
*Sigh* One day left til it's due, and I'm STILL stuck. I haven't figured out how to make my program work with arrays. ANy help at all would be greatly appreciated.   :cry:


var a : array 1..4 of int
var b : array 1..4 or int

for i : 1..4
        if a(i) = b(i) then
        Do some stuff here
        end if
end for



I don't kno it that will help

-----------------------------------
cycro1234
Thu Jan 20, 2005 4:43 pm


-----------------------------------
Ok, I found out where my problem is exactly, but now i need to know how to fix it. I'll describe the problem:

One of my very first pieces of code is:

var y : int := 540

I need this y value to use later on in my code to control the drop of my piece. The drop always starts at 540. I also have a procedure before this called "check" that checks if there are 4 pieces of the same colour in a row. Now here is my procedure (shortened up) that controls the drop:


procedure dropBall (x : int) 
if playerTurn = 1 then
   loop
         y := y - 70
         drawoval (x, y + 70, 24, 24, 0)
         drawoval (x, y, 24, 24, 7)
         %If I put the check here, then it will try to check for 4 in a row every time the y value                 decreases.
          %check (x,y)
          exit when y < 130
   end loop
   y := 540 %I need to reset the value of y to 540 so that when       
            %playerTurn = 2, The piece will start at the top. Otherwise,  
            %the next piece  will drop from the height that the previous  
            %piece stopped at.   
   playerTurn = 2

else
     loop
         y := y - 70
         drawoval (x, y + 70, 24, 24, 0)
         drawoval (x, y, 24, 24, 7)
         %If I put the check here, then it will try to check for 4 in a row every time the y value                 decreases.
          %check (x,y)
          exit when y < 130
   end loop
   y := 540 %I need to reset the value of y to 540 so that when       
            %playerTurn = 2, The piece will start at the top. Otherwise,  
            %the next piece  will drop from the height that the previous  
            %piece stopped at.   
   playerTurn = 1
end if
%Normally I should put the check OUTSIDE the if statements. However, since I have the final statement as y := 540, it will perform the check at 540. 


Any ideas on how I could possible fix this? My ISP is due tomorrow and I really need help!

-----------------------------------
Cervantes
Thu Jan 20, 2005 5:00 pm


-----------------------------------
How about adding a line to your check procedure, at the end.  Add:

y := 540
And take out the y := 540 in your dropBall procedure.

-----------------------------------
cycro1234
Thu Jan 20, 2005 5:20 pm


-----------------------------------
I would, but my check procedure has a y as its variable.

procedure check (x, y: int)

-----------------------------------
cycro1234
Thu Jan 20, 2005 6:06 pm


-----------------------------------
What do I do if the procedure has y as one of its parameters?
