Connect 4- how to check for winner? -
05-24-2012, 10:53 AM
Hello, i am new to alice and currently working on my final project in this 5 week course. My project is a game of 2 player connect four. I have gotten the board set up, and the pieces change colour when each person clicks. However, i am completely stuck when finding a way to detect that there has been a winner
Unfortunately, that is going to be very hard, probably harder than what you've done so far. The easiest way I can think of to do it is use 2 lists, one boolean for isRed/isBlack, and another representing the number of the area the piece occupies. Then, you need to have lots of if statements saying if 4 numbers next to each other horizontally are red/black, win, then do the same with vertically, and then diagonally, though that will be very hard. You're going to need some kind of algorithm to do it unless you want brute force programming, like if(#.IsBlack && #+1.IsBlack etc etc) for horizontal, then vertical and diagonal will be even harder
My train of though kind of went crazy there, so if you need clarification, feel free to ask. Unfortunately, there is no easy way to do what you're asking.
--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes
Wondering about my Avatar?
http://en.wikipedia.org/wiki/Tardigrade
Wondering about my username?
http://www.youtube.com/watch?v=jG7vhMMXagQ