Sunday, July 15, 2012

Back in the saddle

Wow, finally a breather so I can get back to programming?  Excellent!

Here's a screenshot of the NetReversi game so far.  It doesn't do anything yet (other than move the cursor), but some of the logic is built-in ready to be used:


Here's a little snippet of the code.  I'm currently using the Notepad++ editor:


Today I'm working on what might be the most difficult piece of this game - determining if a move is legal.

In Reversi, you play on a 8x8 board, with game discs that are black on one side, white on the other.  Like checkers, you and your opponent both have a color (white or black).  When you take one of your opponent's pieces, you turn it to your color by flipping it.

The way to take one of your opponent's pieces is by surrounding them on the board, either horizontally, vertically, or diagonally.  If you have one of your pieces on one side of your opponent's piece(s), and you place one of your pieces on an empty square adjacent to and on the other side of those opponent's pieces, you turn all the opponent's pieces in between to your color.  For a better explanation of the rules, you can consult Wikipedia's page on Reversi.

The thing is, since a capture can happen from any angle (horiz, vert, or diag), and since you have to circumscribe your opponent's pieces, it's actually a deceptively difficult algorithm to determine if a move is legal.  The best bet is probably to use a recursive function.

More to come, hopefully later today...