Question about a connect-four style system...

Blitz3D Forums/Blitz3D Beginners Area/Question about a connect-four style system...

It is easiest if you make sure the object align to a grid of a certain width, and then divide their locations by that width, and use floor on the resulting number to get an intger that tells you which grid squares they reside in.

Ie: Grid_X = Floor(Peice_X# / Peice_Width#)

Then you can place markers in an array showing where all the peices of a certain color are in the grid, and use that to determine if there are four in a row.

But you need to make sure the peices align to the grid when you place them, or this won't work. Don't bother trying to find a way to figure out if peices are in a row without aligning them to a grid... Then you're getting into artificial intelligence and fuzzy logic. :-)

To check if there are four in a row, you just start at the first peice, and move across to the right... If you see a red peice, increment the counter by 1. If you see a peice which is not red, reset the counter to 0. If the counter is then equal to 4, then you have four in a row.