// Test the functionality related to 'taking' a piece, or stack of // pieces, from a position on the game board. Additionally, it // should be possible to attempt to 'take' a piece from an invalid // position on the game board without error. Throws Exception if // 'taking' the pieces from the board does not result in the // specified position being empty. private static void TestTake() { // Create a new empty game board. TzaarBoard board = new TzaarBoard(true); // Create some game pieces of various types. TzaarPiece p1 = new TzaarPiece.Tzaar(TzaarColor.BLACK); TzaarPiece p2 = new TzaarPiece.Tzarra(TzaarColor.BLACK); TzaarPiece p3 = new TzaarPiece.Tott(TzaarColor.BLACK); // Add the pieces we created to the board at the target // position. board.Add(p1, 0, 0); board.Add(p2, 0, 0); board.Add(p3, 0, 0); // Check that there are 3 pieces on the target position. if (board.Query(0, 0).Count != 3) throw new Exception(); // Take the pieces. if (board.Take(0, 0).Count != 3) throw new Exception(); // Check that there are now 0 pieces on the target position. if (board.Query(0, 0).Count != 0) throw new Exception(); // Try to Take from a spot that doesn't exist. board.Take(-1, 8); }
// The goal is to test various representative valid and invalid // moves for correctness. Throws Exception if a validly specified // path is determined to be invalid, or if an invalidly specified // path is determined to be valid. private static void TestBoardMapPathing() { // Create a new empty game board. TzaarBoardMap boardMap = new TzaarBoardMap(); TzaarBoard board = new TzaarBoard(true); // Create some game pieces of various types. TzaarPiece p1 = new TzaarPiece.Tzaar(TzaarColor.BLACK); TzaarPiece p2 = new TzaarPiece.Tzarra(TzaarColor.BLACK); TzaarPiece p3 = new TzaarPiece.Tott(TzaarColor.BLACK); // Operate on this specific position. int col = 8; int row = 0; // Add the pieces we created to the board at the target // position. board.Add(p1, col, row); board.Add(p2, col, row); board.Add(p3, col, row); // Check that a valid move is reported as valid. if (!boardMap.IsValidPath(board, 0, 0, 0, 1)) throw new Exception(); // Check that an invalid move is reported as invalid. if (boardMap.IsValidPath(board, 4, 3, 4, 4)) throw new Exception(); board.Add(p1, 2, 2); board.Add(p2, 2, 3); // Check that an invalid move is reported as invalid. if (!boardMap.IsValidPath(board, 2, 2, 2, 3)) throw new Exception(); // Check that passing through another piece is reported as // invalid. board.Add(p1, 1, 1); if (boardMap.IsValidPath(board, 0, 0, 2, 2)) throw new Exception(); // Remove the obstructing piece and verify that (0, 0) and // (2, 2) are now connected. board.Take(1, 1); if (!boardMap.IsValidPath(board, 0, 0, 2, 2)) throw new Exception(); }