public EndgameTrainingSession(string sessionId, ChessGame game)
        {
            SessionID = sessionId;
            Game      = game;
            if (Game is AtomicChessGame && Game.IsInCheck(Player.Black))
            {
                Game = new AtomicChessGame(Game.GetFen().Replace(" w ", " b "));
                ReadOnlyCollection <Move> validMoves = Game.GetValidMoves(Player.Black);
                if (validMoves.Count == 0)
                {
                    WasAlreadyLost = true;
                }
                else
                {
                    Game.ApplyMove(validMoves[rnd.Next(0, validMoves.Count)], true);
                    Game = new AtomicChessGame(string.Join(" ", Game.GetFen().Split(' ').Take(4)) + " 0 1");
                }
            }
            ReadOnlyCollection <Move> antiValidMoves;

            if (Game is AntichessGame && (antiValidMoves = Game.GetValidMoves(Player.White)).Count == 1 && Game.GetPieceAt(antiValidMoves[0].NewPosition) != null)
            {
                WasAlreadyLost = true;
            }
            InitialFEN = Game.GetFen();
        }
Ejemplo n.º 2
0
        public static void TestSanPawnCapturePromotionNoCheckmate()
        {
            AtomicChessGame game = new AtomicChessGame("k1r5/3P4/K7/8/8/8/8/8 w - - 0 1");

            game.MakeMove(new Move("D7", "C8", Player.White, 'R'), true);
            System.Console.WriteLine(game.GetFen());
            Assert.AreEqual("dxc8=R", game.Moves[game.Moves.Count - 1].SAN);
        }
        public EndgameTrainingSession(string sessionId, ChessGame game)
        {
            SessionID = sessionId;
            Game      = game;
            if (Game is AtomicChessGame && Game.IsInCheck(Player.Black))
            {
                Game = new AtomicChessGame(Game.GetFen().Replace(" w ", " b "));
                ReadOnlyCollection <Move> validMoves = Game.GetValidMoves(Player.Black);
                if (validMoves.Count == 0)
                {
                    WasAlreadyLost = true;
                }
                else
                {
                    Game.MakeMove(validMoves[rnd.Next(0, validMoves.Count)], true);
                    Game = new AtomicChessGame(string.Join(" ", Game.GetFen().Split(' ').Take(4)) + " 0 1");
                }
            }
            ReadOnlyCollection <Move> antiValidMoves;

            if (Game is AntichessGame)
            {
                if ((antiValidMoves = Game.GetValidMoves(Player.White)).Count == 1 && Game.GetPieceAt(antiValidMoves[0].NewPosition) != null)
                {
                    WasAlreadyLost = true;
                }
                else
                {
                    WasAlreadyLost = true;
                    foreach (Move valid in antiValidMoves)
                    {
                        AntichessGame copy = new AntichessGame(Game.GetFen());
                        copy.MakeMove(valid, true);
                        ReadOnlyCollection <Move> validMoves2 = copy.GetValidMoves(copy.WhoseTurn);
                        bool wonForAll = true;
                        foreach (Move valid2 in validMoves2)
                        {
                            AntichessGame copy2 = new AntichessGame(copy.GetFen());
                            copy2.MakeMove(valid2, true);
                            if (copy2.GetValidMoves(copy2.WhoseTurn).Any(x => copy2.GetPieceAt(x.NewPosition) != null))
                            {
                                wonForAll = false;
                                break;
                            }
                        }
                        if (wonForAll)
                        {
                            WasAlreadyLost = false;
                            break;
                        }
                    }
                }
            }
            InitialFEN = Game.GetFen();
        }
Ejemplo n.º 4
0
        public void TestFenCastlingFieldAfterRookExplosion_WhiteQueenside()
        {
            AtomicChessGame game = new AtomicChessGame("r1bqkbnr/pppppppp/8/8/1nPP4/6P1/PP2PP1P/RNBQKBNR b KQkq - 0 3");

            game.ApplyMove(new Move("b4", "a2", Player.Black), true);
            Assert.False(game.CanWhiteCastleQueenSide);
            Assert.AreEqual("r1bqkbnr/pppppppp/8/8/2PP4/6P1/1P2PP1P/2BQKBNR w Kkq - 0 4", game.GetFen());
        }
Ejemplo n.º 5
0
        public void TestFenCastlingFieldAfterRookExplosion_WhiteKingside()
        {
            AtomicChessGame game = new AtomicChessGame("rnbqkb1r/pppppppp/8/8/5Pn1/2P5/PPQPP1PP/RNB1KBNR b KQkq - 2 3");

            game.ApplyMove(new Move("g4", "h2", Player.Black), true);
            Assert.False(game.CanWhiteCastleKingSide);
            Assert.AreEqual("rnbqkb1r/pppppppp/8/8/5P2/2P5/PPQPP1P1/RNB1KB2 w Qkq - 0 4", game.GetFen());
        }
Ejemplo n.º 6
0
        public void TestFenCastlingFieldAfterRookExplosion_BlackQueenside()
        {
            AtomicChessGame game = new AtomicChessGame("rnbqkbnr/pp2pppp/8/1Npp4/8/8/PPPPPPPP/R1BQKBNR w KQkq - 0 3");

            game.ApplyMove(new Move("b5", "a7", Player.White), true);
            Assert.False(game.CanBlackCastleQueenSide);
            Assert.AreEqual("2bqkbnr/1p2pppp/8/2pp4/8/8/PPPPPPPP/R1BQKBNR b KQk - 0 3", game.GetFen());
        }
Ejemplo n.º 7
0
        public void TestFenCastlingFieldAfterRookExplosion_BlackKingside()
        {
            AtomicChessGame game = new AtomicChessGame("rnbqkbnr/ppp3pp/3pp3/5pN1/8/4P3/PPPP1PPP/RNBQKB1R w KQkq - 0 4");

            game.ApplyMove(new Move("g5", "h7", Player.White), true);
            Assert.False(game.CanBlackCastleKingSide);
            Assert.AreEqual("rnbqkb2/ppp3p1/3pp3/5p2/8/4P3/PPPP1PPP/RNBQKB1R b KQq - 0 4", game.GetFen());
        }
Ejemplo n.º 8
0
 public void TestFenCastlingFieldAfterRookExplosion_WhiteQueenside()
 {
     AtomicChessGame game = new AtomicChessGame("r1bqkbnr/pppppppp/8/8/1nPP4/6P1/PP2PP1P/RNBQKBNR b KQkq - 0 3");
     game.ApplyMove(new Move("b4", "a2", Player.Black), true);
     Assert.False(game.CanWhiteCastleQueenSide);
     Assert.AreEqual("r1bqkbnr/pppppppp/8/8/2PP4/6P1/1P2PP1P/2BQKBNR w Kkq - 0 4", game.GetFen());
 }
Ejemplo n.º 9
0
 public void TestFenCastlingFieldAfterRookExplosion_WhiteKingside()
 {
     AtomicChessGame game = new AtomicChessGame("rnbqkb1r/pppppppp/8/8/5Pn1/2P5/PPQPP1PP/RNB1KBNR b KQkq - 2 3");
     game.ApplyMove(new Move("g4", "h2", Player.Black), true);
     Assert.False(game.CanWhiteCastleKingSide);
     Assert.AreEqual("rnbqkb1r/pppppppp/8/8/5P2/2P5/PPQPP1P1/RNB1KB2 w Qkq - 0 4", game.GetFen());
 }
Ejemplo n.º 10
0
 public void TestFenCastlingFieldAfterRookExplosion_BlackQueenside()
 {
     AtomicChessGame game = new AtomicChessGame("rnbqkbnr/pp2pppp/8/1Npp4/8/8/PPPPPPPP/R1BQKBNR w KQkq - 0 3");
     game.ApplyMove(new Move("b5", "a7", Player.White), true);
     Assert.False(game.CanBlackCastleQueenSide);
     Assert.AreEqual("2bqkbnr/1p2pppp/8/2pp4/8/8/PPPPPPPP/R1BQKBNR b KQk - 0 3", game.GetFen());
 }
Ejemplo n.º 11
0
 public void TestFenCastlingFieldAfterRookExplosion_BlackKingside()
 {
     AtomicChessGame game = new AtomicChessGame("rnbqkbnr/ppp3pp/3pp3/5pN1/8/4P3/PPPP1PPP/RNBQKB1R w KQkq - 0 4");
     game.ApplyMove(new Move("g5", "h7", Player.White), true);
     Assert.False(game.CanBlackCastleKingSide);
     Assert.AreEqual("rnbqkb2/ppp3p1/3pp3/5p2/8/4P3/PPPP1PPP/RNBQKB1R b KQq - 0 4", game.GetFen());
 }