Esempio n. 1
0
 public Games(Board b, BoardPresenter bp, MoveExecutor me)
 {
     Board          = b;
     BoardPresenter = bp;
     //MoveValidator = mv;
     MoveExecutor      = me;
     ActivePlayer      = EPlayer.White;
     CapturedPresenter = new CapturedPresenter();
 }
Esempio n. 2
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);
        }