Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Connect4 HELP HELP HELP
|
Posted: Mar 20, 2002 4:58 PM
|
|
On such a problem, which seems complicated at first, the trick is to decompose it into smaller problems. In this case, I would break it into (at least) three smaller problems: check for horizonal wins for a given color, then vertical, then diagonal. You only need to check for the specified color, because, if black has just made a move, white could not possibly have a win (or you'd have found it on the previous check). That is, you only need to check for the color that has just placed a piece.
You should be able to crank out the horizontal and vertical checks in a heartbeat, but if you have trouble with the diagonal, report back here. For clarity, I would create at least three different check methods. The check methods should probably return information (coordinates) about where the winning string of 4 starts.
Finally, do you get extra credit if do this thing graphically in Swing, instead of println()? Even if you don't, try to keep your game implementation classes separate from your input and output so that it can be easily adapted to a graphical UI.
|
|