Exemple #1
0
        public void TestProcessEnPassant()
        {
            var fromSquare = new Square(Files.g, Ranks.five);
            var toSquare   = new Square(Files.h, Ranks.six);

            IChess chess = new Custom(CustomPositionB);

            var rushed  = chess.AvailableMoves(false).Where(m => m.Type == MoveType.Rush).Single();
            var passant = new Move(fromSquare, toSquare, MoveType.Passant);

            IPiece piece = null;

            // Triggers En Passant
            chess.Process(rushed, out piece);

            // Executes it
            Assert.True(chess.Process(passant, out piece));

            Assert.NotNull(piece);
            Assert.True(piece is Pawn);
            Assert.False(piece.Color);

            Assert.True(chess.Position[toSquare] is Pawn);
            Assert.True(chess.Position[toSquare].Color);

            Assert.Empty(chess.Position.Values.Where(p => p == piece).ToList());
            Assert.DoesNotContain(new Square(Files.h, Ranks.five), chess.Position.Keys);
        }
Exemple #2
0
        public void TestCopyConstructor()
        {
            IChess chess = new Custom(CustomPositionA, new HashSet <MoveType>()
            {
                MoveType.Passant
            });

            IPiece piece;

            chess.Process(((Custom)chess).AllMoves(true).First(), out piece);
            chess.Process(((Custom)chess).AllMoves(false).First(), out piece);
            chess.Process(((Custom)chess).AllMoves(true).Last(), out piece);
            chess.Process(((Custom)chess).AllMoves(false).Last(), out piece);

            IChess copy = new Custom((Custom)chess);

            Assert.Equal(chess.Position.Keys, copy.Position.Keys);
            Assert.Equal(chess.MoveEntries, copy.MoveEntries);
            Assert.Equal(chess.AvailableMoves(true), copy.AvailableMoves(true));
            Assert.Equal(chess.AvailableMoves(false), copy.AvailableMoves(false));
            Assert.Equal(((Custom)chess).BannedMoves, ((Custom)copy).BannedMoves);
        }