Monday, April 25, 2011

Inside information on win checking

We were able to implement the win checking in Lua easier than C# mainly because of using a matrix to represent the board instead of a button array. The matrix allowed us to break the board down into sections where we needed to check for certain win scenarios. The seven different possibilities to win are shown in the image below:


After we implemented the basic win scenarios shown above, we determined that the code above does not account for the cases where the winning piece is placed in the middle of the four pieces, not an end piece. In order to account for these scenarios, we created the following for loop. This for loop checks the win for the current column and the two columns to the right of the piece. We also added a check to make sure the current column is inside the board.

The last two cases are for the diagonal wins are taken care of by the following for loop. This checks the diagonal wins for the 2 pieces up and down to the right of the current piece. We also added a check here to make sure our current row is inside the board.

Piecing it all together - we get our CheckWin function!

No comments:

Post a Comment