public void TestLegalJumpsWontJumpOverOwnPiece() { var board = new CheckerBoard(); board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0); board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 2, 1); // One below and to the right var whiteMoves = board.GetLegalMoves(PieceColor.White); Assert.AreEqual(2, whiteMoves.Count); var moveForwardLeft = new Move(new CheckerPiece(board.GetPiece(CheckerBoard.SIZE - 2, 1)), MoveDirection.ForwardLeft); var moveForwardRight = new Move(new CheckerPiece(board.GetPiece(CheckerBoard.SIZE - 2, 1)), MoveDirection.ForwardRight); Assert.IsTrue(whiteMoves.Contains(moveForwardLeft)); Assert.IsTrue(whiteMoves.Contains(moveForwardRight)); }
private static void AssertPiecesRemoved(CheckerBoard board, IEnumerable <CheckerPiece> pieces) { foreach (var piece in pieces) { Assert.AreNotEqual(piece, board.GetPiece(piece.Row, piece.Col)); } }
private static void AssertPieceExists(CheckerBoard board, int row, int col, PieceColor color) { var piece = board.GetPiece(row, col); Assert.IsNotNull(piece); Assert.AreEqual(color, piece.Owner); }
private MoveBreakdown CreateBreakdown() { int newRow = _move.Piece.Row; int newCol = _move.Piece.Col; var removedPieces = new List <CheckerPiece>(); foreach (MoveDirection direction in _move.Direction) { newRow += MoveUtil.GetRowMoveAmountByColor(_move.Piece.Owner, direction); newCol += MoveUtil.GetColMoveAmount(direction); // adjust for jump CheckerPiece pieceAtPosition = _board.GetPiece(newRow, newCol); if (pieceAtPosition != null && pieceAtPosition.Owner != _move.Piece.Owner) { removedPieces.Add(pieceAtPosition); newRow += MoveUtil.GetRowMoveAmountByColor(_move.Piece.Owner, direction); newCol += MoveUtil.GetColMoveAmount(direction); } } return(new MoveBreakdown { FinalRow = newRow, FinalCol = newCol, RemovedPieces = removedPieces }); }
public void TestKingJump() { var board = new CheckerBoard(); board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 1, 0); board.GetPiece(CheckerBoard.SIZE - 1, 0).IsKing = true; board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 2, 1); //board.PlacePiece(PieceColor.White, Board.BOARD_SIZE - 4, 3); var blackMoves = board.GetLegalMoves(PieceColor.Black); Assert.AreEqual(1, blackMoves.Count); var blackMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection> { MoveDirection.BackwardRight }); Assert.AreEqual(blackMove, blackMoves[0]); }
private static void AssertBackwardRightMoveIsCorrect(CheckerBoard board, int originalRow, int originalColumn, PieceColor color) { Assert.IsNull(board.GetPiece(originalRow, originalColumn)); int newRow = originalRow + MoveUtil.GetRowMoveAmountByColor(color, MoveDirection.BackwardRight); int newCol = originalColumn + MoveUtil.GetColMoveAmount(MoveDirection.BackwardRight); AssertPieceExists(board, newRow, newCol, color); }
public void TestLegalJumps() { var board = new CheckerBoard(); board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0); board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 2, 1); // One below and to the right var whiteMoves = board.GetLegalMoves(PieceColor.White); var blackMoves = board.GetLegalMoves(PieceColor.Black); Assert.AreEqual(1, whiteMoves.Count); Assert.AreEqual(1, blackMoves.Count); var whiteMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection> { MoveDirection.ForwardRight }); var blackMove = new Move(board.GetPiece(CheckerBoard.SIZE - 2, 1), new List <MoveDirection> { MoveDirection.ForwardRight }); Assert.AreEqual(whiteMove, whiteMoves[0]); Assert.AreEqual(blackMove, blackMoves[0]); }
public void TestMultipleJumps() { var board = new CheckerBoard(); board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0); board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 2, 1); board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 4, 3); var whiteMoves = board.GetLegalMoves(PieceColor.White); Assert.AreEqual(1, whiteMoves.Count); var whiteMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection> { MoveDirection.ForwardRight, MoveDirection.ForwardRight }); Assert.AreEqual(whiteMove, whiteMoves[0]); }
public void AddPiece_WhiteNonKingPiece_AddsWithCorrectValues() { _board.AddPiece(_piece); Assert.AreEqual(_piece, _board.GetPiece(_piece.Row, _piece.Col)); }