コード例 #1
0
 public override void SetDefaultsInFEN(FEN fen)
 {
     if (fen["en-passant"] == "#default")
     {
         fen["en-passant"] = "-";
     }
 }
コード例 #2
0
        // *** EVENT HANDLERS *** //

        public override void SetDefaultsInFEN(FEN fen)
        {
            if (fen[FENSegmentName] == "#default")
            {
                fen[FENSegmentName] = allPrivString;
            }
        }
コード例 #3
0
        public override void PositionLoaded(FEN fen)
        {
            //	read the turn number from the FEN
            if (!Int32.TryParse(fen["turn number"], out turnNumber))
            {
                throw new Exception("FEN parse error - invalid turn number specified: '" + fen["turn number"] + "'");
            }
            //	read the current player from the FEN
            string currentPlayerNotation = fen["current player"];
            bool   notationFound         = false;

            for (int x = 0; x < stateNotations.Length; x++)
            {
                if (currentPlayerNotation == stateNotations[x])
                {
                    currentState     = x;
                    Game.CurrentSide = currentState / 2;
                    notationFound    = true;
                }
            }
            if (!notationFound)
            {
                throw new Exception("FEN parse error - invalid current player specified: '" + currentPlayerNotation + "'");
            }
        }
コード例 #4
0
 public override void SetDefaultsInFEN(FEN fen)
 {
     if (fen["bishop-conversion"] == "#default")
     {
         fen["bishop-conversion"] = allPrivString;
     }
 }
コード例 #5
0
 public override void SetDefaultsInFEN(FEN fen)
 {
     if (fen["kings-leap"] == "#default")
     {
         fen["kings-leap"] = "Kk";
     }
 }
コード例 #6
0
ファイル: CastlingRule.cs プロジェクト: ColinSuess/ChessVFork
 public override void SetDefaultsInFEN(FEN fen)
 {
     if (fen["castling"] == "#default")
     {
         fen["castling"] = allPrivString;
     }
 }
コード例 #7
0
        public override void DoAction(BoardPosition bp, bool back = false)
        {
            //var cmm_classic = fen as ClassicChessMatchModel;
            string captureOnTheIsle = UciConverter.BoardPositionToString(FEN.CaptureOnTheIsle);

            string fen = FEN.GetFEN();

            chessUCIEngine.GoInfinite(fen);

            SearchForMove();
        }
コード例 #8
0
        public override void PositionLoaded(FEN fen)
        {
            string ep = fen["en-passant"];

            if (ep == "-")
            {
                epSquares[0] = -1;
            }
            else
            {
                epSquares[0] = Game.NotationToSquare(ep);
            }
        }
コード例 #9
0
        public override void SavePositionToFEN(FEN fen)
        {
            int epSquare = (Game.GameMoveNumber == 0 ? epSquares[0] : gameHistory[Game.GameMoveNumber - 1]);

            if (epSquare > 0)
            {
                fen["en-passant"] = Game.GetSquareNotation(epSquare);
            }
            else
            {
                fen["en-passant"] = "-";
            }
        }
コード例 #10
0
ファイル: Move50Rule.cs プロジェクト: ColinSuess/ChessVFork
 public override void PositionLoaded(FEN fen)
 {
     try
     {
         searchStackCounter[0] = Convert.ToInt32(fen["half-move clock"]);
         gameHistoryCounter[0] = searchStackCounter[0];
     }
     catch (Exception ex)
     {
         throw new Exceptions.FENParseFailureException("half-move clock", fen["half-move clock"],
                                                       "Cannot parse the half-move count from FEN", ex);
     }
 }
コード例 #11
0
 public override void PositionLoaded(FEN fen)
 {
     foreach (char c in fen["pieces in hand"])
     {
         if (c != '-' && c != '@')
         {
             PieceType type   = Game.GetTypeByNotation(c.ToString());
             int       player = Char.IsUpper(c) ? 0 : 1;
             Location  loc    = new Location(player, -1);
             Piece     piece  = new Piece(Game, player, type, loc);
             Board.Game.AddPiece(piece);
         }
     }
 }
コード例 #12
0
 public override void PositionLoaded(FEN fen)
 {
     //	scan the board for the royal pieces
     for (int player = 0; player < Game.NumPlayers; player++)
     {
         List <Piece> piecelist = Game.GetPieceList(player);
         foreach (Piece piece in piecelist)
         {
             if (piece.PieceType == RoyalPieceType)
             {
                 royalPieces[player] = piece;
             }
         }
     }
 }
コード例 #13
0
        public void CanParseTheStartingPosition()
        {
            // Assemble
            string startingString = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

            // Act
            var fen = new FEN(startingString);

            // Assert
            Assert.Equal("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", fen.PiecePlacement);
            Assert.Equal(Side.White, fen.ActiveSide);
            Assert.Equal(CastlingRights.All, fen.CastlingAvailability);
            Assert.Null(fen.EnpassantTargetSquare);
            Assert.Equal(0, fen.HalfmoveClock);
            Assert.Equal(1, fen.FullmoveNumber);
        }
コード例 #14
0
 public override void PositionLoaded(FEN fen)
 {
     searchStackPrivs[0] = 0;
     foreach (char c in fen[FENSegmentName])
     {
         if (privLookup.ContainsKey(c))
         {
             searchStackPrivs[0] |= privLookup[c];
         }
         else
         {
             throw new Exceptions.FENParseFailureException(FENSegmentName, fen[FENSegmentName],
                                                           "Invalid character in FEN " + FENSegmentName + " privileges: " + c);
         }
     }
     gameHistoryPrivs[Game.GameMoveNumber] = searchStackPrivs[0];
 }
コード例 #15
0
        public override void SavePositionToFEN(FEN fen)
        {
            PrivFlags conversionPrivs = (PrivFlags)gameHistory[Game.GameMoveNumber];
            string    privString      = "";

            //	player 0 privs
            if ((conversionPrivs & PrivFlags.p0sq0must) != PrivFlags.none)
            {
                privString += bishopSquares[0][0].ToString().ToUpper() + "+";
            }
            else if ((conversionPrivs & PrivFlags.p0sq1must) != PrivFlags.none)
            {
                privString += bishopSquares[1][0].ToString().ToUpper() + "+";
            }
            else if ((conversionPrivs & PrivFlags.p0sq0can) != PrivFlags.none)
            {
                privString += bishopSquares[0][0].ToString().ToUpper();
            }
            else if ((conversionPrivs & PrivFlags.p0sq1can) != PrivFlags.none)
            {
                privString += bishopSquares[1][0].ToString().ToUpper();
            }
            //	player 1 privs
            if ((conversionPrivs & PrivFlags.p1sq0must) != PrivFlags.none)
            {
                privString += bishopSquares[2][0].ToString() + "+";
            }
            else if ((conversionPrivs & PrivFlags.p1sq1must) != PrivFlags.none)
            {
                privString += bishopSquares[3][0].ToString() + "+";
            }
            else if ((conversionPrivs & PrivFlags.p1sq0can) != PrivFlags.none)
            {
                privString += bishopSquares[2][0].ToString();
            }
            else if ((conversionPrivs & PrivFlags.p1sq1can) != PrivFlags.none)
            {
                privString += bishopSquares[3][0].ToString();
            }
            if (privString == "")
            {
                privString = "-";
            }
            fen["bishop-conversion"] = privString;
        }
コード例 #16
0
ファイル: CastlingRule.cs プロジェクト: ColinSuess/ChessVFork
        public override void SavePositionToFEN(FEN fen)
        {
            int    castlingPriv = gameHistoryPrivs[Game.GameMoveNumber];
            string privString   = "";

            foreach (var pair in privLookup)
            {
                if ((pair.Value & castlingPriv) != 0)
                {
                    privString += pair.Key;
                }
            }
            if (privString == "")
            {
                privString = "-";
            }
            fen["castling"] = privString;
        }
コード例 #17
0
        public int CheckWinLose()
        {
            char lit = 'n';

            if (FEN.IndexOf('0') < 0)
            {
                return(3);
            }
            for (int i = 1; i <= 3; i++)
            {
                if ((FEN[i] == FEN[i + 3]) && (FEN[i + 3] == FEN[i + 6]) && FEN[i] != '0')
                {
                    lit = FEN[i];
                }
            }
            for (int i = 1; i <= 9; i = i + 3)
            {
                if ((FEN[i] == FEN[i + 1]) && (FEN[i + 1] == FEN[i + 2]) && FEN[i] != '0')
                {
                    lit = FEN[i];
                }
            }

            if ((FEN[1] == FEN[5]) && (FEN[5] == FEN[9]) && FEN[5] != '0')
            {
                lit = fen[1];
            }

            else if ((FEN[3] == FEN[5]) && (FEN[5] == FEN[7]) && FEN[5] != '0')
            {
                lit = FEN[3];
            }
            if (lit == '1')
            {
                return(1);
            }
            else if (lit == '2')
            {
                return(2);
            }
            return(0);
        }
コード例 #18
0
 public override void PositionLoaded(FEN fen)
 {
     privs[0] = 0;
     foreach (char c in fen["kings-leap"])
     {
         if (c == 'K')
         {
             privs[0] |= 1;
         }
         else if (c == 'k')
         {
             privs[0] |= 2;
         }
         else
         {
             throw new Exception("Unrecognized character in FEN kings-leap section - " + c);
         }
     }
     gameHistory[Game.GameMoveNumber] = privs[0];
 }
コード例 #19
0
        public override void PositionLoaded(FEN fen)
        {
            //	read the turn number from the FEN
            if (!Int32.TryParse(fen["turn number"], out turnNumber))
            {
                throw new Exception("FEN parse error - invalid turn number specified: '" + fen["turn number"] + "'");
            }
            //	read the current player from the FEN
            string currentPlayerNotation = fen["current player"];
            bool   notationFound         = false;

            for (int x = 0; x < stateNotations.Length; x++)
            {
                if (currentPlayerNotation == stateNotations[x])
                {
                    currentState     = x;
                    Game.CurrentSide = currentState / 2;
                    notationFound    = true;
                }
            }
            if (!notationFound)
            {
                throw new Exception("FEN parse error - invalid current player specified: '" + currentPlayerNotation + "'");
            }
            if (royalPieces != null)
            {
                //	scan the board for the royal pieces
                for (int player = 0; player < Game.NumPlayers; player++)
                {
                    List <Piece> piecelist = Game.GetPieceList(player);
                    foreach (Piece piece in piecelist)
                    {
                        if (piece.PieceType == RoyalPieceType)
                        {
                            royalPieces[player] = piece;
                        }
                    }
                }
            }
        }
コード例 #20
0
ファイル: CastlingRule.cs プロジェクト: ColinSuess/ChessVFork
        public override void PositionLoaded(FEN fen)
        {
            searchStackPrivs[0] = 0;
            string castling = fen["castling"];

            if (castling != "-")
            {
                foreach (char c in castling)
                {
                    if (privLookup.ContainsKey(c))
                    {
                        searchStackPrivs[0] |= privLookup[c];
                    }
                    else
                    {
                        throw new Exceptions.FENParseFailureException("castling", fen["castling"],
                                                                      "Invalid character in FEN castling privileges: " + c);
                    }
                }
            }
            gameHistoryPrivs[Game.GameMoveNumber] = searchStackPrivs[0];
        }
コード例 #21
0
        public override void PositionLoaded(FEN fen)
        {
            string ep = fen["en-passant"];

            if (ep == "-")
            {
                epCaptureSquares[0] = epMoverSquares[0] = -1;
            }
            else
            {
                //	We need to split the notation into the two squares.
                //	We will not assume there are two characters for each since
                //	one could put Berolina Pawns on a board with 10 or more ranks.
                int splitpoint;
                for (splitpoint = 1; ep[splitpoint] >= '0' && ep[splitpoint] <= '9'; splitpoint++)
                {
                    ;
                }
                epCaptureSquares[0] = Game.NotationToSquare(ep.Substring(0, splitpoint));
                epMoverSquares[0]   = Game.NotationToSquare(ep.Substring(splitpoint));
            }
        }
コード例 #22
0
ファイル: Engine.cs プロジェクト: wattson-coder/TD
 /// <summary>
 /// Get the fen from the board.
 /// </summary>
 public string GetFen()
 {
     return(FEN.FenFromBoard(board));
 }
コード例 #23
0
        public override void PositionLoaded(FEN fen)
        {
            string bc = fen["bishop-conversion"];

            if (bc == "-")
            {
                privs[0] = 0;
            }
            else
            {
                int cursor = 0;
                while (cursor < bc.Length)
                {
                    if (Char.IsUpper(bc[cursor]))
                    {
                        //	upper-case so this is a player 0 privilege
                        if (Char.ToLower(bc[cursor]) == Game.GetSquareNotation(p0square0)[0])
                        {
                            privs[0] |= (int)PrivFlags.p0sq0can;
                            if (cursor + 1 < bc.Length && bc[cursor + 1] == '+')
                            {
                                privs[0] |= (int)PrivFlags.p0sq0must;
                                cursor++;
                            }
                        }
                        else if (Char.ToLower(bc[cursor]) == Game.GetSquareNotation(p0square1)[0])
                        {
                            privs[0] |= (int)PrivFlags.p0sq1can;
                            if (cursor + 1 < bc.Length && bc[cursor + 1] == '+')
                            {
                                privs[0] |= (int)PrivFlags.p0sq1must;
                                cursor++;
                            }
                        }
                        else
                        {
                            throw new Exceptions.FENParseFailureException("bishop-conversion", bc, "Unexpected character in bishop conversion notation: " + bc[cursor]);
                        }
                    }
                    else
                    {
                        //	lower-case so this is a player 1 privilege
                        if (bc[cursor] == Game.GetSquareNotation(p1square0)[0])
                        {
                            privs[0] |= (int)PrivFlags.p1sq0can;
                            if (cursor + 1 < bc.Length && bc[cursor + 1] == '+')
                            {
                                privs[0] |= (int)PrivFlags.p1sq0must;
                                cursor++;
                            }
                        }
                        else if (bc[cursor] == Game.GetSquareNotation(p1square1)[0])
                        {
                            privs[0] |= (int)PrivFlags.p1sq1can;
                            if (cursor + 1 < bc.Length && bc[cursor + 1] == '+')
                            {
                                privs[0] |= (int)PrivFlags.p1sq1must;
                                cursor++;
                            }
                        }
                        else
                        {
                            throw new Exceptions.FENParseFailureException("bishop-conversion", bc, "Unexpected character in bishop conversion notation: " + bc[cursor]);
                        }
                    }
                    cursor++;
                }
            }
            gameHistory[Game.GameMoveNumber] = privs[0];
        }
コード例 #24
0
 public override void SavePositionToFEN(FEN fen)
 {
     fen["turn number"]    = turnNumber.ToString();
     fen["current player"] = stateNotations[currentState];
 }
コード例 #25
0
ファイル: Move50Rule.cs プロジェクト: ColinSuess/ChessVFork
 public override void SavePositionToFEN(FEN fen)
 {
     fen["half-move clock"] = gameHistoryCounter[Game.GameMoveNumber].ToString();
 }