// returns true if a piece to capture was detected public static PieceMinified Check(PieceMinified piece, BoardMinified board, int size) { if (piece.Y > 1) { // left if (piece.X > 1) { piece = CheckDirection(piece, board, -1, -1); } // right if (piece.X < size - 2) { piece = CheckDirection(piece, board, 1, -1); } } if (piece.Y < size - 2) { // left if (piece.X > 1) { piece = CheckDirection(piece, board, -1, 1); } // right if (piece.X < size - 2) { piece = CheckDirection(piece, board, 1, 1); } } return(piece); }
public PieceMinified Check(PieceMinified piece, BoardMinified board, sbyte directionDown, sbyte directionRight) { var boardCell = board.GetBoardCell((byte)(piece.X + directionRight), (byte)(piece.Y + directionDown)); if (boardCell.IsEmpty()) { piece.AddAvailableMove(directionRight, directionDown, false); } return(piece); }
public override BoardMinified ApplyRule(BoardMinified board, HistoryItemMinified latestMove) { var size = board.GetSize(); var player1Figures = new PieceMinified[20]; var player2Figures = new PieceMinified[20]; if (size < 4) { throw new NotImplementedException("Game size smaller than 4"); } // todo - refactor this var isWhite = true; byte i = 0; for (var y = (byte)(size - 1); y > size / 2; y--) { var startX = (byte)(1 - y % 2); for (var x = startX; x < size; x += 2) { var piece = new PieceMinified(x, y, isWhite, true, false); player1Figures[i] = piece; board.SetBoardCell(x, y, new BoardCell(i, isWhite)); i++; } } i = 0; for (byte y = 0; y < size / 2 - 1; y++) { var startX = (byte)(1 - y % 2); for (var x = startX; x < size; x += 2) { var piece = new PieceMinified(x, y, !isWhite, false, true); player2Figures[i] = piece; board.SetBoardCell(x, y, new BoardCell(i, isWhite)); i++; } } for (byte j = 0; j < player1Figures.Length; j++) { board.Player1Pieces[j] = player1Figures[j]; } for (byte j = 0; j < player2Figures.Length; j++) { board.Player2Pieces[j] = player2Figures[j]; } return(Next(board, null)); }
private static PieceMinified CheckDirection(PieceMinified piece, BoardMinified board, sbyte directionRight, sbyte directionDown) { var target = board.GetBoardCell((byte)(piece.X + directionRight), (byte)(piece.Y + directionDown)); if (!target.IsEmpty() && target.IsWhite() != piece.IsWhite) { var second = board.GetBoardCell((byte)(piece.X + 2 * directionRight), (byte)(piece.Y + 2 * directionDown)); if (second.IsEmpty()) { piece.AddAvailableMove(directionRight, directionDown, true); } } return(piece); }
public void PieceMinificationsTest_1() { var piece1 = new PieceMinified(); var piece2 = new PieceMinified(); Assert.True(piece1.Equals(piece2)); piece2.CanGoDown = true; Assert.True(piece1.Equals(piece2)); piece1.CanGoUp = true; Assert.True(piece1.Equals(piece2)); piece1.IsCaptured = true; Assert.False(piece1.Equals(piece2)); piece2.IsCaptured = true; Assert.True(piece1.Equals(piece2)); }
public void CheckersRulesPrimitiveTest_2() { var board = BoardMinifiedTest.CreateSampleBoard(); board.Player1PiecesCount--; var pieceToCapture = new PieceMinified(1, 2, false, false, true); board.SetBoardCell(1, 2, new BoardCell(1, false)); board.Player2Pieces[1] = pieceToCapture; board = _rules.FastForwardAvailableMoves(board); var afterRulesAppending1 = (PieceMinified)board.Player1Pieces[0]; afterRulesAppending1.GetAvailableMoves() .Should() .BeEquivalentTo(new[] { new Cell(2, 1), new Cell(), new Cell(), new Cell() }); var afterRulesAppending2 = (PieceMinified)board.Player1Pieces[1]; afterRulesAppending2.HasAvailableMoves().Should().BeFalse(); }