Alice Community

Alice Community (
-   How do I...? (
-   -   Connect 4- how to check for winner? (

p86aaron 05-24-2012 10:53 AM

Connect 4- how to check for winner?
1 Attachment(s)
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

Any help is appreciated :)

TauTrumpsPi 05-24-2012 02:34 PM

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.

All times are GMT -5. The time now is 11:00 AM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.