private static void AddValidMove(MoveValidationContext context, char newX, int newY) { if (Cell.IsXValid(newX) && Cell.IsYValid(newY)) { var moveOutput = new MoveOutput { Cell = new Cell { X = newX, Y = newY } }; var piece = context.Board.ContainsKey(moveOutput.Cell) ? context.Board[moveOutput.Cell] : null; if (piece == null) { moveOutput.Type = EMoveOutputType.NormalMove; context.ValidMoves.Add(moveOutput); } else { if (piece.Player != context.Piece.Player) { moveOutput.Type = EMoveOutputType.CaptureMove; context.ValidMoves.Add(moveOutput); } } } }
private void RightCastling(MoveValidationContext context) { var playerOriginalY = PlayerOriginalY(context.ActivePlayer); if (context.Src.X == Board.KingOriginalX && context.Src.Y == playerOriginalY) { var rockCell = new Cell { X = Board.EndOfX, Y = playerOriginalY }; var rock = context.Board.ContainsKey(rockCell) ? context.Board[rockCell] : null; var piecesInBetween = context.Board.ContainsKey(new Cell { X = Board.EndOfX.Decrease(1), Y = playerOriginalY }) || context.Board.ContainsKey(new Cell { X = Board.EndOfX.Decrease(2), Y = playerOriginalY }); if (rock is Rock && !piecesInBetween) { var moveOutput = new MoveOutput { Cell = new Cell { X = Board.KingOriginalX.Increase(CastlingDistance), Y = playerOriginalY } }; moveOutput.Type = EMoveOutputType.CastlingMove; context.ValidMoves.Add(moveOutput); } } }
protected void ValidMoveAction(MoveValidationContext context, Func <char, int, char> funcNextX, Func <int, int, int> funcNextY) { var stop = false; var i = 1; do { if (i > MaxDistance) { stop = true; } else { var nextX = funcNextX(context.Src.X, i); var nextY = funcNextY(context.Src.Y, i); var moveOutput = new MoveOutput { Cell = new Cell { X = nextX, Y = nextY } }; var piece = context.Board.ContainsKey(moveOutput.Cell) ? context.Board[moveOutput.Cell] : null; if (piece == null) { moveOutput.Type = EMoveOutputType.NormalMove; context.ValidMoves.Add(moveOutput); } else { stop = true; if (piece.Player != context.Piece.Player && Mode == EDiagonalMode.Any) { moveOutput.Type = EMoveOutputType.CaptureMove; context.ValidMoves.Add(moveOutput); } } } i++; } while (!stop); }