private void EastUpMove(MoveValidationContext context) { var newX = context.Src.X.Increase(DistanceOfTwo); var newY = context.Src.Y + DistanceOfOne; AddValidMove(context, newX, newY); }
private void NorthLeftMove(MoveValidationContext context) { var newX = context.Src.X.Decrease(DistanceOfOne); var newY = context.Src.Y + DistanceOfTwo; AddValidMove(context, newX, newY); }
private void WestDownMove(MoveValidationContext context) { var newX = context.Src.X.Decrease(DistanceOfTwo); var newY = context.Src.Y - DistanceOfOne; AddValidMove(context, newX, newY); }
public override void ValidMove(MoveValidationContext context) { if (Movement != null) { Movement.ValidMove(context); } }
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); } } }
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 SouthRightMove(MoveValidationContext context) { var newX = context.Src.X.Increase(DistanceOfOne); var newY = context.Src.Y - DistanceOfTwo; AddValidMove(context, newX, newY); }
public override void ValidMove(MoveValidationContext context) { Movement.ValidMove(context); if (PawnInStartingPosition(context.Piece.Player, context.Src)) { base.ValidMove(context); } }
public override void ValidMove(MoveValidationContext context) { Movement.ValidMove(context); //left ValidMoveAction(context, (src, i) => src.Increase(i)); //right ValidMoveAction(context, (src, i) => src.Decrease(i)); }
protected void NorthEastMove(MoveValidationContext context) { ValidMoveAction ( context, (src, i) => src.Increase(i), (src, i) => src + i ); }
protected void SouthWestMove(MoveValidationContext context) { ValidMoveAction ( context, (src, i) => src.Decrease(i), (src, i) => src - i ); }
public void ValidatingMovement(MoveValidationContext context) { if (context.ActivePlayer == Player) { Movement.ValidMove(context); } else { context.InvalidMessage = "not players piece"; } }
public override void ValidMove(MoveValidationContext context) { NorthLeftMove(context); NorthRightMove(context); EastUpMove(context); EastDownMove(context); SouthLeftMove(context); SouthRightMove(context); WestUpMove(context); WestDownMove(context); }
public void Move(Cell src, Cell dst) { Console.WriteLine($"move from {src} to {dst}"); var piece = Board.ContainsKey(src) ? Board[src] : null; if (piece == null) { Console.WriteLine($"no piece at {src}"); } else { var context = new MoveValidationContext { ActivePlayer = ActivePlayer, Src = src, Board = Board, Piece = piece }; piece.ValidatingMovement(context); var moveOutput = context.Find(dst); if (moveOutput != null) { MoveExecutor.ExecuteMove ( new MoveExecutionContext { Type = moveOutput.Type, Src = src, Dst = moveOutput.Cell, Piece = piece, Board = Board, Captured = Captured } ); TogglePlayerTurn(); if (WhiteKingCaptured()) { Winner = EPlayer.Black; } else if (BlackKingCaptured()) { Winner = EPlayer.White; } } else { Console.WriteLine($"no valid move from {src} to {dst}, reason: {context.InvalidMessage}"); } } BoardPresenter.Print(Board); CapturedPresenter.Print(Captured); }
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); }
public override void ValidMove(MoveValidationContext context) { Movement.ValidMove(context); if (Mode == EVerticalMode.Any) { //up ValidMoveAction(context, (src, i) => src + i); //down ValidMoveAction(context, (src, i) => src - i); } else { if (context.ActivePlayer == EPlayer.White) { ValidMoveAction(context, (src, i) => src + i); //up for white } else { ValidMoveAction(context, (src, i) => src - i); //down for black } } }
public override void ValidMove(MoveValidationContext context) { Movement.ValidMove(context); if (Mode == EDiagonalMode.Any) { NorthEastMove(context); NorthWestMove(context); SouthEastMove(context); SouthWestMove(context); } else { if (context.ActivePlayer == EPlayer.White) { NorthEastMove(context); NorthWestMove(context); } else { SouthEastMove(context); SouthWestMove(context); } } }
public override void ValidMove(MoveValidationContext context) { }
public abstract void ValidMove(MoveValidationContext context);
public override void ValidMove(MoveValidationContext context) { LeftCastling(context); RightCastling(context); }