Ejemplo n.º 1
0
        protected virtual Dictionary <ChessPiece, List <Move> > CalculatePlayerMoves(Player player)
        {
            var movesDict   = Board.GetAllMoves(player);
            var otherPlayer = player == White ? Black : White;

            var temp_board = new Chessboard(Board);

            foreach (var dict in movesDict)
            {
                var moveList = dict.Value;
                var piece    = dict.Key;

                for (int i = moveList.Count - 1; i >= 0; i--)
                {
                    temp_board.ExecuteAction(moveList[i]);

                    if (temp_board.IsKingInCheck(otherPlayer))
                    {
                        movesDict.Remove(piece);
                    }

                    temp_board.NavigateBack();
                }
            }

            return(movesDict);
        }
Ejemplo n.º 2
0
        public void ExecuteAction_ValidMove_Success()
        {
            var pawn = empty_2x2_board.AddPiece(new Pawn(new Position(1, 0), white, Position.Up));

            empty_2x2_board.ExecuteAction(pawn.GetMoves(empty_2x2_board)[0]);

            Assert.IsTrue(empty_2x2_board.GetPiece(new Position(1, 1)).Equals(pawn));
        }