Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Connect 4 Checking Procedure Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KennEH!




PostPosted: Tue Jan 26, 2010 5:58 pm   Post subject: Connect 4 Checking Procedure Help

What is it you are trying to achieve?
I am working on a connect four program and I'm trying to checking for four pieces in a line.


What is the problem you are having?
My check works, but only if you placed the first or last piece in the line of four.

Describe what you have tried to solve this problem
I have tried using a nested loop to check every piece in the grid, but it ends up not checking until the last possible piece is played.

Turing:


%checks pieces in every direction around placed piece to see if won
%win - if false program will continue to loop, if fails program exits loop
%pc - colour of piece
%x - x coordinate of piece
%y - y coordinate of piece
proc check
    for x : 25 .. 325 by 50
        for y : 20 .. 275 by 50
            if whatdotcolour (x, y) = pc and whatdotcolour (x + 50, y) = pc and whatdotcolour (x + 100, y) = pc and whatdotcolour (x + 150, y) = pc or
                    whatdotcolour (x, y) = pc and whatdotcolour (x, y + 50) = pc and whatdotcolour (x, y + 100) = pc and whatdotcolour (x, y + 150) = pc or
                    whatdotcolour (x, y) = pc and whatdotcolour (x + 50, y + 50) = pc and whatdotcolour (x + 100, y + 100) = pc and whatdotcolour (x + 150, y + 150) = pc or
                    whatdotcolour (x, y) = pc and whatdotcolour (x - 50, y) = pc and whatdotcolour (x - 100, y) = pc and whatdotcolour (x - 150, y) = pc or
                    whatdotcolour (x, y) = pc and whatdotcolour (x, y - 50) = pc and whatdotcolour (x, y - 100) = pc and whatdotcolour (x, y - 150) = pc or
                    whatdotcolour (x, y) = pc and whatdotcolour (x - 50, y - 50) = pc and whatdotcolour (x - 100, y - 100) = pc and whatdotcolour (x - 150, y - 150) = pc then
                win := true
            else
                win := false
            end if
        end for
    end for
end check



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: