Build a Mini-Chess Mover

Once you have a board representation and move generator, you will want to move pieces around on the board—as will your program.

Add a method to your State class called "move" that accepts a Move argument. If the target piece exists and belongs to the side on move, the method should return a new State for after the move. Otherwise, it should throw an exception.

Add another method "humanMove" that takes an argument of the form "a1-b2"; that is, a pair of board coordinates with a dash between them. (Use lowercase only.) The method decodes the coordinates, checks to see if the move is fully legal, and then invokes "move" to move the piece. Otherwise, it should throw an exception. The easy way to check for a legal move is to use "move" to generate all legal moves and then walk them all.

prev index next