コード例 #1
0
        private void EastUpMove(MoveValidationContext context)
        {
            var newX = context.Src.X.Increase(DistanceOfTwo);
            var newY = context.Src.Y + DistanceOfOne;

            AddValidMove(context, newX, newY);
        }
コード例 #2
0
        private void NorthLeftMove(MoveValidationContext context)
        {
            var newX = context.Src.X.Decrease(DistanceOfOne);
            var newY = context.Src.Y + DistanceOfTwo;

            AddValidMove(context, newX, newY);
        }
コード例 #3
0
        private void WestDownMove(MoveValidationContext context)
        {
            var newX = context.Src.X.Decrease(DistanceOfTwo);
            var newY = context.Src.Y - DistanceOfOne;

            AddValidMove(context, newX, newY);
        }
コード例 #4
0
 public override void ValidMove(MoveValidationContext context)
 {
     if (Movement != null)
     {
         Movement.ValidMove(context);
     }
 }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
 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);
             }
         }
     }
 }
コード例 #7
0
        private void SouthRightMove(MoveValidationContext context)
        {
            var newX = context.Src.X.Increase(DistanceOfOne);
            var newY = context.Src.Y - DistanceOfTwo;

            AddValidMove(context, newX, newY);
        }
コード例 #8
0
 public override void ValidMove(MoveValidationContext context)
 {
     Movement.ValidMove(context);
     if (PawnInStartingPosition(context.Piece.Player, context.Src))
     {
         base.ValidMove(context);
     }
 }
コード例 #9
0
 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));
 }
コード例 #10
0
 protected void NorthEastMove(MoveValidationContext context)
 {
     ValidMoveAction
     (
         context,
         (src, i) => src.Increase(i),
         (src, i) => src + i
     );
 }
コード例 #11
0
 protected void SouthWestMove(MoveValidationContext context)
 {
     ValidMoveAction
     (
         context,
         (src, i) => src.Decrease(i),
         (src, i) => src - i
     );
 }
コード例 #12
0
 public void ValidatingMovement(MoveValidationContext context)
 {
     if (context.ActivePlayer == Player)
     {
         Movement.ValidMove(context);
     }
     else
     {
         context.InvalidMessage = "not players piece";
     }
 }
コード例 #13
0
        public override void ValidMove(MoveValidationContext context)
        {
            NorthLeftMove(context);
            NorthRightMove(context);

            EastUpMove(context);
            EastDownMove(context);

            SouthLeftMove(context);
            SouthRightMove(context);

            WestUpMove(context);
            WestDownMove(context);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
 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
         }
     }
 }
コード例 #17
0
 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);
         }
     }
 }
コード例 #18
0
 public override void ValidMove(MoveValidationContext context)
 {
 }
コード例 #19
0
 public abstract void ValidMove(MoveValidationContext context);
コード例 #20
0
 public override void ValidMove(MoveValidationContext context)
 {
     LeftCastling(context);
     RightCastling(context);
 }