Ejemplo n.º 1
0
            public void ApplyMoveToFENTests()
            {
                // This is the method meant to be called by clients for the most
                // part and does take side-effects into account, such as captures,
                // promotions, castlings, updating the move count and active player, etc

                // You should be able to replay a game by applying moves repeatedly
                string initialFEN = ChessBoard.InitialFENPosition;

                // These assume starting from the standard position with white
                // "san move", "expected new FEN"
                Tuple <string, string>[] testData =
                {
                    // Records from a game where stockfish 8 played itself (plus some forced moves to test promotion)
                    new Tuple <string, string>("d2d4",  "rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR b KQkq - 0 1"),
                    new Tuple <string, string>("d7d5",  "rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2"),
                    new Tuple <string, string>("c2c4",  "rnbqkbnr/ppp1pppp/8/3p4/2PP4/8/PP2PPPP/RNBQKBNR b KQkq - 0 2"),
                    new Tuple <string, string>("e7e6",  "rnbqkbnr/ppp2ppp/4p3/3p4/2PP4/8/PP2PPPP/RNBQKBNR w KQkq - 0 3"),
                    new Tuple <string, string>("g1f3",  "rnbqkbnr/ppp2ppp/4p3/3p4/2PP4/5N2/PP2PPPP/RNBQKB1R b KQkq - 1 3"),
                    new Tuple <string, string>("g8f6",  "rnbqkb1r/ppp2ppp/4pn2/3p4/2PP4/5N2/PP2PPPP/RNBQKB1R w KQkq - 2 4"),
                    new Tuple <string, string>("b1c3",  "rnbqkb1r/ppp2ppp/4pn2/3p4/2PP4/2N2N2/PP2PPPP/R1BQKB1R b KQkq - 3 4"),
                    new Tuple <string, string>("c7c6",  "rnbqkb1r/pp3ppp/2p1pn2/3p4/2PP4/2N2N2/PP2PPPP/R1BQKB1R w KQkq - 0 5"),
                    new Tuple <string, string>("e2e3",  "rnbqkb1r/pp3ppp/2p1pn2/3p4/2PP4/2N1PN2/PP3PPP/R1BQKB1R b KQkq - 0 5"),
                    new Tuple <string, string>("b8d7",  "r1bqkb1r/pp1n1ppp/2p1pn2/3p4/2PP4/2N1PN2/PP3PPP/R1BQKB1R w KQkq - 1 6"),
                    new Tuple <string, string>("f1d3",  "r1bqkb1r/pp1n1ppp/2p1pn2/3p4/2PP4/2NBPN2/PP3PPP/R1BQK2R b KQkq - 2 6"),
                    new Tuple <string, string>("d5c4",  "r1bqkb1r/pp1n1ppp/2p1pn2/8/2pP4/2NBPN2/PP3PPP/R1BQK2R w KQkq - 0 7"),
                    new Tuple <string, string>("d3c4",  "r1bqkb1r/pp1n1ppp/2p1pn2/8/2BP4/2N1PN2/PP3PPP/R1BQK2R b KQkq - 0 7"),
                    new Tuple <string, string>("b7b5",  "r1bqkb1r/p2n1ppp/2p1pn2/1p6/2BP4/2N1PN2/PP3PPP/R1BQK2R w KQkq - 0 8"),
                    new Tuple <string, string>("c4e2",  "r1bqkb1r/p2n1ppp/2p1pn2/1p6/3P4/2N1PN2/PP2BPPP/R1BQK2R b KQkq - 1 8"),
                    new Tuple <string, string>("c8b7",  "r2qkb1r/pb1n1ppp/2p1pn2/1p6/3P4/2N1PN2/PP2BPPP/R1BQK2R w KQkq - 2 9"),
                    new Tuple <string, string>("e1g1",  "r2qkb1r/pb1n1ppp/2p1pn2/1p6/3P4/2N1PN2/PP2BPPP/R1BQ1RK1 b kq - 3 9"),
                    new Tuple <string, string>("f8e7",  "r2qk2r/pb1nbppp/2p1pn2/1p6/3P4/2N1PN2/PP2BPPP/R1BQ1RK1 w kq - 4 10"),
                    new Tuple <string, string>("a2a3",  "r2qk2r/pb1nbppp/2p1pn2/1p6/3P4/P1N1PN2/1P2BPPP/R1BQ1RK1 b kq - 0 10"),
                    new Tuple <string, string>("a7a5",  "r2qk2r/1b1nbppp/2p1pn2/pp6/3P4/P1N1PN2/1P2BPPP/R1BQ1RK1 w kq - 0 11"),
                    new Tuple <string, string>("b2b3",  "r2qk2r/1b1nbppp/2p1pn2/pp6/3P4/PPN1PN2/4BPPP/R1BQ1RK1 b kq - 0 11"),
                    new Tuple <string, string>("e8g8",  "r2q1rk1/1b1nbppp/2p1pn2/pp6/3P4/PPN1PN2/4BPPP/R1BQ1RK1 w - - 1 12"),
                    new Tuple <string, string>("c1b2",  "r2q1rk1/1b1nbppp/2p1pn2/pp6/3P4/PPN1PN2/1B2BPPP/R2Q1RK1 b - - 2 12"),
                    new Tuple <string, string>("b5b4",  "r2q1rk1/1b1nbppp/2p1pn2/p7/1p1P4/PPN1PN2/1B2BPPP/R2Q1RK1 w - - 0 13"),
                    new Tuple <string, string>("a3b4",  "r2q1rk1/1b1nbppp/2p1pn2/p7/1P1P4/1PN1PN2/1B2BPPP/R2Q1RK1 b - - 0 13"),
                    new Tuple <string, string>("a5b4",  "r2q1rk1/1b1nbppp/2p1pn2/8/1p1P4/1PN1PN2/1B2BPPP/R2Q1RK1 w - - 0 14"),
                    new Tuple <string, string>("a1a8",  "R2q1rk1/1b1nbppp/2p1pn2/8/1p1P4/1PN1PN2/1B2BPPP/3Q1RK1 b - - 0 14"),
                    new Tuple <string, string>("d8a8",  "q4rk1/1b1nbppp/2p1pn2/8/1p1P4/1PN1PN2/1B2BPPP/3Q1RK1 w - - 0 15"),
                    new Tuple <string, string>("c3a4",  "q4rk1/1b1nbppp/2p1pn2/8/Np1P4/1P2PN2/1B2BPPP/3Q1RK1 b - - 1 15"),
                    new Tuple <string, string>("c6c5",  "q4rk1/1b1nbppp/4pn2/2p5/Np1P4/1P2PN2/1B2BPPP/3Q1RK1 w - - 0 16"),
                    new Tuple <string, string>("d4c5",  "q4rk1/1b1nbppp/4pn2/2P5/Np6/1P2PN2/1B2BPPP/3Q1RK1 b - - 0 16"),
                    new Tuple <string, string>("d7c5",  "q4rk1/1b2bppp/4pn2/2n5/Np6/1P2PN2/1B2BPPP/3Q1RK1 w - - 0 17"),
                    new Tuple <string, string>("a4c5",  "q4rk1/1b2bppp/4pn2/2N5/1p6/1P2PN2/1B2BPPP/3Q1RK1 b - - 0 17"),
                    new Tuple <string, string>("e7c5",  "q4rk1/1b3ppp/4pn2/2b5/1p6/1P2PN2/1B2BPPP/3Q1RK1 w - - 0 18"),
                    new Tuple <string, string>("d1c2",  "q4rk1/1b3ppp/4pn2/2b5/1p6/1P2PN2/1BQ1BPPP/5RK1 b - - 1 18"),
                    new Tuple <string, string>("f8c8",  "q1r3k1/1b3ppp/4pn2/2b5/1p6/1P2PN2/1BQ1BPPP/5RK1 w - - 2 19"),
                    new Tuple <string, string>("f1a1",  "q1r3k1/1b3ppp/4pn2/2b5/1p6/1P2PN2/1BQ1BPPP/R5K1 b - - 3 19"),
                    new Tuple <string, string>("a8b8",  "1qr3k1/1b3ppp/4pn2/2b5/1p6/1P2PN2/1BQ1BPPP/R5K1 w - - 4 20"),
                    new Tuple <string, string>("b2e5",  "1qr3k1/1b3ppp/4pn2/2b1B3/1p6/1P2PN2/2Q1BPPP/R5K1 b - - 5 20"),
                    new Tuple <string, string>("c5d6",  "1qr3k1/1b3ppp/3bpn2/4B3/1p6/1P2PN2/2Q1BPPP/R5K1 w - - 6 21"),
                    new Tuple <string, string>("c2b2",  "1qr3k1/1b3ppp/3bpn2/4B3/1p6/1P2PN2/1Q2BPPP/R5K1 b - - 7 21"),
                    new Tuple <string, string>("d6e5",  "1qr3k1/1b3ppp/4pn2/4b3/1p6/1P2PN2/1Q2BPPP/R5K1 w - - 0 22"),
                    new Tuple <string, string>("b2e5",  "1qr3k1/1b3ppp/4pn2/4Q3/1p6/1P2PN2/4BPPP/R5K1 b - - 0 22"),
                    new Tuple <string, string>("b8e5",  "2r3k1/1b3ppp/4pn2/4q3/1p6/1P2PN2/4BPPP/R5K1 w - - 0 23"),
                    new Tuple <string, string>("f3e5",  "2r3k1/1b3ppp/4pn2/4N3/1p6/1P2P3/4BPPP/R5K1 b - - 0 23"),
                    new Tuple <string, string>("c8c3",  "6k1/1b3ppp/4pn2/4N3/1p6/1Pr1P3/4BPPP/R5K1 w - - 1 24"),
                    new Tuple <string, string>("e2c4",  "6k1/1b3ppp/4pn2/4N3/1pB5/1Pr1P3/5PPP/R5K1 b - - 2 24"),
                    new Tuple <string, string>("g7g5",  "6k1/1b3p1p/4pn2/4N1p1/1pB5/1Pr1P3/5PPP/R5K1 w - - 0 25"),
                    new Tuple <string, string>("a1a7",  "6k1/Rb3p1p/4pn2/4N1p1/1pB5/1Pr1P3/5PPP/6K1 b - - 1 25"),
                    new Tuple <string, string>("b7d5",  "6k1/R4p1p/4pn2/3bN1p1/1pB5/1Pr1P3/5PPP/6K1 w - - 2 26"),
                    new Tuple <string, string>("f2f3",  "6k1/R4p1p/4pn2/3bN1p1/1pB5/1Pr1PP2/6PP/6K1 b - - 0 26"),
                    new Tuple <string, string>("d5c4",  "6k1/R4p1p/4pn2/4N1p1/1pb5/1Pr1PP2/6PP/6K1 w - - 0 27"),
                    new Tuple <string, string>("b3c4",  "6k1/R4p1p/4pn2/4N1p1/1pP5/2r1PP2/6PP/6K1 b - - 0 27"),
                    new Tuple <string, string>("b4b3",  "6k1/R4p1p/4pn2/4N1p1/2P5/1pr1PP2/6PP/6K1 w - - 0 28"),
                    new Tuple <string, string>("a7b7",  "6k1/1R3p1p/4pn2/4N1p1/2P5/1pr1PP2/6PP/6K1 b - - 1 28"),
                    new Tuple <string, string>("c3c1",  "6k1/1R3p1p/4pn2/4N1p1/2P5/1p2PP2/6PP/2r3K1 w - - 2 29"),
                    new Tuple <string, string>("g1f2",  "6k1/1R3p1p/4pn2/4N1p1/2P5/1p2PP2/5KPP/2r5 b - - 3 29"),
                    new Tuple <string, string>("b3b2",  "6k1/1R3p1p/4pn2/4N1p1/2P5/4PP2/1p3KPP/2r5 w - - 0 30"),
                    new Tuple <string, string>("c4c5",  "6k1/1R3p1p/4pn2/2P1N1p1/8/4PP2/1p3KPP/2r5 b - - 0 30"),
                    new Tuple <string, string>("b2b1q", "6k1/1R3p1p/4pn2/2P1N1p1/8/4PP2/5KPP/1qr5 w - - 0 31"),
                    new Tuple <string, string>("b7b1",  "6k1/5p1p/4pn2/2P1N1p1/8/4PP2/5KPP/1Rr5 b - - 0 31"),
                    new Tuple <string, string>("c1b1",  "6k1/5p1p/4pn2/2P1N1p1/8/4PP2/5KPP/1r6 w - - 0 32"),
                    new Tuple <string, string>("e5d3",  "6k1/5p1p/4pn2/2P3p1/8/3NPP2/5KPP/1r6 b - - 1 32"),
                    new Tuple <string, string>("b1d1",  "6k1/5p1p/4pn2/2P3p1/8/3NPP2/5KPP/3r4 w - - 2 33"),
                    new Tuple <string, string>("f2e2",  "6k1/5p1p/4pn2/2P3p1/8/3NPP2/4K1PP/3r4 b - - 3 33"),
                    new Tuple <string, string>("d1a1",  "6k1/5p1p/4pn2/2P3p1/8/3NPP2/4K1PP/r7 w - - 4 34"),
                    new Tuple <string, string>("g2g4",  "6k1/5p1p/4pn2/2P3p1/6P1/3NPP2/4K2P/r7 b - - 0 34"),
                    new Tuple <string, string>("a1a2",  "6k1/5p1p/4pn2/2P3p1/6P1/3NPP2/r3K2P/8 w - - 1 35"),
                    new Tuple <string, string>("e2e1",  "6k1/5p1p/4pn2/2P3p1/6P1/3NPP2/r6P/4K3 b - - 2 35"),
                    new Tuple <string, string>("a2h2",  "6k1/5p1p/4pn2/2P3p1/6P1/3NPP2/7r/4K3 w - - 0 36"),
                    new Tuple <string, string>("d3f2",  "6k1/5p1p/4pn2/2P3p1/6P1/4PP2/5N1r/4K3 b - - 1 36"),
                    new Tuple <string, string>("f6d5",  "6k1/5p1p/4p3/2Pn2p1/6P1/4PP2/5N1r/4K3 w - - 2 37"),
                    new Tuple <string, string>("e3e4",  "6k1/5p1p/4p3/2Pn2p1/4P1P1/5P2/5N1r/4K3 b - - 0 37"),
                    new Tuple <string, string>("d5e7",  "6k1/4np1p/4p3/2P3p1/4P1P1/5P2/5N1r/4K3 w - - 1 38"),
                };

                string fen = initialFEN;

                foreach (Tuple <string, string> tuple in testData)
                {
                    string newFen = FenParser.ApplyMoveToFEN(fen, tuple.Item1);
                    Trace.WriteLine(String.Format("Verify \"{0}\" + \"{1}\" = \"{2}\" Ret: \"{3}\"", fen, tuple.Item1, tuple.Item2, newFen));
                    Assert.IsTrue(String.Compare(newFen, tuple.Item2) == 0);
                    fen = newFen;
                }

                // White knight in position to capture black kingside rook
                string initialFEN2 = "r1b1kb1r/pp1n1ppp/2p1pnN1/q2p4/2PP4/2N5/PP2PPPP/R1BQKB1R w KQkq - 4 7";

                Tuple <string, string>[] testData2 =
                {
                    new Tuple <string, string>("g6h8", "r1b1kb1N/pp1n1ppp/2p1pn2/q2p4/2PP4/2N5/PP2PPPP/R1BQKB1R b KQq - 0 7"),
                };

                fen = initialFEN2;
                foreach (Tuple <string, string> tuple in testData2)
                {
                    string newFen = FenParser.ApplyMoveToFEN(fen, tuple.Item1);
                    Trace.WriteLine(String.Format("Verify \"{0}\" + \"{1}\" = \"{2}\" Ret: \"{3}\"", fen, tuple.Item1, tuple.Item2, newFen));
                    Assert.IsTrue(String.Compare(newFen, tuple.Item2) == 0);
                    fen = newFen;
                }
            }