コード例 #1
0
        public void TestAllMovesWithEnPassant()
        {
            var customBoard = new Dictionary <Square, IPiece>()
            {
                { new Square(Files.a, Ranks.five), new Pawn(true) },
                { new Square(Files.b, Ranks.seven), new Pawn(false) }
            };

            var withPassant = new Custom(customBoard);
            var bansPassant = new Custom(customBoard,
                                         new HashSet <MoveType>()
            {
                MoveType.Passant
            });

            var rushMove = withPassant.AllMoves(false).Where(m => m.Type == MoveType.Rush).Single();

            ((IChess)withPassant).Process(rushMove, out IPiece withPiece);
            ((IChess)bansPassant).Process(rushMove, out IPiece bansPiece);

            var allWithMoves = withPassant.AllMoves(true);
            var allBansMoves = bansPassant.AllMoves(true);

            Assert.Equal(2, allWithMoves.Count());
            Assert.Single(allBansMoves);

            var passantMove = allWithMoves.Where(m => m.Type == MoveType.Passant).Single();

            Assert.True(passantMove.FromSquare.IsSameSquareAs(new Square(Files.a, Ranks.five)));
            Assert.True(passantMove.ToSquare.IsSameRankAs(new Square(Files.b, Ranks.six)));
        }
コード例 #2
0
        public void TestEnPassantWrongTrigger()
        {
            var customBoard = new Dictionary <Square, IPiece>()
            {
                { new Square(Files.a, Ranks.five), new Pawn(true) },
                { new Square(Files.b, Ranks.seven), new Pawn(false) },
                { new Square(Files.h, Ranks.one), new King(true) },
                { new Square(Files.h, Ranks.eight), new King(false) },
            };

            var chess = new Custom(customBoard);

            var rushMove  = chess.AllMoves(false).Where(m => m.Type == MoveType.Rush).Single();
            var whiteKing = chess.AllMoves(true).Where(m => m.FromSquare.File == Files.h).ToList().First();
            var blackKing = chess.AllMoves(false).Where(m => m.FromSquare.File == Files.h).ToList().First();

            IPiece piece = null;

            // Process a rush move - triggers En Passant
            ((IChess)chess).Process(rushMove, out piece);

            // Process a move with white king - abdicates En Passant
            ((IChess)chess).Process(whiteKing, out piece);

            // Process a move with black king - Rushed pawn on the same square
            // This is a wrong trigger, as En Passant was abdicated
            ((IChess)chess).Process(blackKing, out piece);

            Assert.Empty(chess.AllMoves(true).Where(m => m.Type == MoveType.Passant).ToList());
        }
コード例 #3
0
        public void TestAllMoves(
            List <MoveType> allowedMoves,
            int whiteMoveCount,
            int blackMoveCount
            )
        {
            var banned = Enum.GetValues(typeof(MoveType)).Cast <MoveType>()
                         .Where(mt => !allowedMoves.Contains(mt)).ToHashSet();

            var chess = new Custom(CustomPositionA, banned);

            var whiteMoves = chess.AllMoves(true);
            var blackMoves = chess.AllMoves(false);

            Assert.Equal(whiteMoveCount, whiteMoves.Count());
            Assert.Equal(blackMoveCount, blackMoves.Count());
        }