Exemplo n.º 1
0
    public ResultData GetMoveLine(FenData fen)
    {
        ResultData result = new ResultData();

        try
        {
            result = (new GenerateMoveLine(fen)).GetMoveLine();
        }
        catch (AppException ae)
        {
            result.errorcode = ae.GetMsgCode();
            result.errormsg  = ae.GetMsg();
        }
        catch (Exception e)
        {
            result.errorcode = "99";
            result.errormsg  = e.Message;
        }
        finally
        {
        }
        return(result);
    }
Exemplo n.º 2
0
 public MoveData GetZoufa(FenData fen)
 {
     return((new GenerateZoufa(fen)).Zoufa());
 }
Exemplo n.º 3
0
        public void SetGamePosition(IPerftPosition pp)
        {
            var fp = new FenData(pp.Fen);

            CurrentGame.SetFen(fp);
        }
Exemplo n.º 4
0
 public CheckChess(FenData fen) : base(fen)
 {
     change = new ChangeQipan(fen);
 }
Exemplo n.º 5
0
 public GenerateZoufa(FenData fen) : base(fen)
 {
     sreach = new SreachZoufa(fen);
 }
Exemplo n.º 6
0
    //检查走法合法性
    public ResultData CheckZoufa(FenData fen)
    {
        ResultData result = Zoufamiddleware.CheckZoufa(fen);

        return(result);
    }
Exemplo n.º 7
0
 public ChangeQipan(FenData fen) : base(fen)
 {
 }
Exemplo n.º 8
0
 public GetZoufa(FenData fen) : base(fen)
 {
     sreach = new SreachZoufa((FenData)fen.Clone());
 }
Exemplo n.º 9
0
 public GetMoveLine(FenData fen) : base(fen)
 {
 }
Exemplo n.º 10
0
        /// <summary>
        /// Apply a FEN string board setup to the board structure.
        /// *EXCEPTION FREE FUNCTION*
        /// </summary>
        /// <param name="fenString">The string to set</param>
        /// <param name="validate">If true, the fen string is validated, otherwise not</param>
        /// <returns>
        /// 0 = all ok.
        /// -1 = Error in piece file layout parsing
        /// -2 = Error in piece rank layout parsing
        /// -3 = Unknown piece detected
        /// -4 = Error while parsing moving side
        /// -5 = Error while parsing castleling
        /// -6 = Error while parsing en-passant square
        /// -9 = FEN length exceeding maximum
        /// </returns>
        public FenError SetFen(string fenString, bool validate = false)
        {
            // TODO : Replace with stream at some point

            // basic validation, catches format errors
            if (validate)
            {
                Fen.Fen.Validate(fenString);
            }

            foreach (var square in Occupied)
            {
                Position.RemovePiece(square, Position.BoardLayout[square.AsInt()]);
            }

            //for (var i = 0; i <= PositionIndex; i++)
            //    _stateList[i].Clear();

            Position.Clear();

            var fen = new FenData(fenString);

            Player player;
            var    c = fen.GetAdvance;

            var f = 1; // file (column)
            var r = 8; // rank (row)

            // map pieces to data structure
            while (c != 0 && !(f == 9 && r == 1))
            {
                if (char.IsDigit(c))
                {
                    f += c - '0';
                    if (f > 9)
                    {
                        return(new FenError(-1, fen.Index));
                    }

                    c = fen.GetAdvance;
                    continue;
                }

                if (c == '/')
                {
                    if (f != 9)
                    {
                        return(new FenError(-2, fen.Index));
                    }

                    r--;
                    f = 1;
                    c = fen.GetAdvance;
                    continue;
                }

                var pieceIndex = PieceExtensions.PieceChars.IndexOf(c);

                if (pieceIndex == -1)
                {
                    return(new FenError(-3, fen.Index));
                }

                player = char.IsLower(PieceExtensions.PieceChars[pieceIndex]);

                var square = new Square(r - 1, f - 1);

                AddPiece(square, player, (EPieceType)pieceIndex);

                c = fen.GetAdvance;

                f++;
            }

            if (!Fen.Fen.IsDelimiter(c))
            {
                return(new FenError(-4, fen.Index));
            }

            c = fen.GetAdvance;

            player = c == 'w' ? 0 : 1;

            if (player == -1)
            {
                return(new FenError(-4, fen.Index));
            }

            if (!Fen.Fen.IsDelimiter(fen.GetAdvance))
            {
                return(new FenError(-5, fen.Index));
            }

            if (!SetupCastleling(fen))
            {
                return(new FenError(-5, fen.Index));
            }

            if (!Fen.Fen.IsDelimiter(fen.GetAdvance))
            {
                return(new FenError(-6, fen.Index));
            }

            State.EnPassantSquare = fen.GetEpSquare();

            // temporary.. the whole method should be using this, but this will do for now.

            var moveCounters = fen.Fen.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var first  = moveCounters[moveCounters.Length - 2];
            var second = moveCounters[moveCounters.Length - 1];

            second.ToIntegral(out int number);

            if (number > 0)
            {
                number -= 1;
            }

            PositionIndex = PositionStart = number;

            first.ToIntegral(out number);

            State = Position.State = _stateList[PositionIndex];

            State.ReversibleHalfMoveCount = number;

            State.SideToMove = player;

            if (player.IsBlack())
            {
                var zobristSide = Zobrist.GetZobristSide();
                State.Key ^= zobristSide;
                State.PawnStructureKey ^= zobristSide;
            }

            State.Key ^= Zobrist.GetZobristCastleling(State.CastlelingRights);

            if (State.EnPassantSquare != ESquare.none)
            {
                State.Key ^= Zobrist.GetZobristEnPessant(State.EnPassantSquare.File().AsInt());
            }

            Position.InCheck = Position.IsAttacked(Position.GetPieceSquare(EPieceType.King, State.SideToMove), ~State.SideToMove);

            //State.GenerateMoves(true);

            return(0);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Apply a FEN string board setup to the board structure.
        /// </summary>
        /// <param name="fenString">The string to set</param>
        /// <param name="validate">If true, the fen string is validated, otherwise not</param>
        /// <returns>
        /// 0 = all ok.
        /// -1 = Error in piece file layout parsing
        /// -2 = Error in piece rank layout parsing
        /// -3 = Unknown piece detected
        /// -4 = Error while parsing moving side
        /// -5 = Error while parsing castleling
        /// -6 = Error while parsing en-passant square
        /// -9 = FEN length exceeding maximum
        /// </returns>
        public FenError SetFen(FenData fen, bool validate = false)
        {
            if (validate)
            {
                Fen.Fen.Validate(fen.Fen.ToString());
            }

            // correctly clear all pieces and invoke possible notification(s)
            var bb = Occupied;

            while (bb)
            {
                var square = bb.Lsb();
                Position.RemovePiece(square, Position.BoardLayout[square.AsInt()]);
                BitBoards.ResetLsb(ref bb);
            }

            var chunk = fen.Chunk();

            if (chunk.IsEmpty)
            {
                return(new FenError());
            }

            var    f = 1; // file (column)
            var    r = 8; // rank (row)
            Player player;

            foreach (var c in chunk)
            {
                if (char.IsDigit(c))
                {
                    f += c - '0';
                    if (f > 9)
                    {
                        return(new FenError(-1, fen.Index));
                    }
                }
                else if (c == '/')
                {
                    if (f != 9)
                    {
                        return(new FenError(-2, fen.Index));
                    }

                    r--;
                    f = 1;
                }
                else
                {
                    var pieceIndex = PieceExtensions.PieceChars.IndexOf(c);

                    if (pieceIndex == -1)
                    {
                        return(new FenError(-3, fen.Index));
                    }

                    player = char.IsLower(PieceExtensions.PieceChars[pieceIndex]);

                    var square = new Square(r - 1, f - 1);

                    AddPiece(square, player, (EPieceType)pieceIndex);

                    f++;
                }
            }

            // player
            chunk = fen.Chunk();

            if (chunk.IsEmpty || chunk.Length != 1)
            {
                return(new FenError(-3, fen.Index));
            }

            player = (chunk[0] != 'w').ToInt();

            // castleling
            chunk = fen.Chunk();

            if (!SetupCastleling(chunk))
            {
                return(new FenError(-5, fen.Index));
            }

            // en-passant
            chunk = fen.Chunk();

            if (chunk.Length == 1 || chunk[0] == '-' || !chunk[0].InBetween('a', 'h'))
            {
                State.EnPassantSquare = ESquare.none;
            }
            else
            {
                State.EnPassantSquare = chunk[1].InBetween('3', '6') ? ESquare.none : new Square(chunk[1] - '1', chunk[0] - 'a').Value;
            }

            // move number
            chunk = fen.Chunk();

            var moveNum     = 0;
            var halfMoveNum = 0;

            if (!chunk.IsEmpty)
            {
                chunk.ToIntegral(out halfMoveNum);

                // half move number
                chunk = fen.Chunk();

                chunk.ToIntegral(out moveNum);

                if (moveNum > 0)
                {
                    moveNum--;
                }
            }

            PositionIndex = PositionStart = moveNum;

            Position.State = _stateList[PositionIndex];

            State.ReversibleHalfMoveCount = halfMoveNum;

            State.SideToMove = player;

            if (player.IsBlack())
            {
                State.Key ^= Zobrist.GetZobristSide();
                State.PawnStructureKey ^= Zobrist.GetZobristSide();
            }

            State.Key ^= State.CastlelingRights.GetZobristCastleling();

            if (State.EnPassantSquare != ESquare.none)
            {
                State.Key ^= State.EnPassantSquare.File().GetZobristEnPessant();
            }

            Position.InCheck = Position.IsAttacked(Position.GetPieceSquare(EPieceType.King, player), ~player);

            return(0);
        }
Exemplo n.º 12
0
 public FenError SetFen(FenData fenData) => SetFen(fenData.Fen);
Exemplo n.º 13
0
 public GenerateMoveLine(FenData fen) : base(fen)
 {
 }
Exemplo n.º 14
0
 public static void AssertSinglePiece(this FenData fenData, int rank, char file, PieceType type, PieceColor color)
 {
     Assert.Single(fenData.PieceInfos, p => p.Rank == rank && p.File == file && p.Type == type && p.Color == color);
 }
Exemplo n.º 15
0
 public static void AddZouFa(FenData fen)
 {
     history.ZouFa.Add(Utility.ConvertQiPanToString(fen), fen.moves[0]);
 }
Exemplo n.º 16
0
 protected BaseZoufa(FenData fen)
 {
     this.fen = fen;
 }
Exemplo n.º 17
0
 public SreachZoufa(FenData fen) : base(fen)
 {
     create   = new CreateZoufa(fen);
     evaluate = new EvaluateZoufa(fen);
     change   = new ChangeQipan(fen);
 }
Exemplo n.º 18
0
 public EvaluateZoufa(FenData fen) : base(fen)
 {
 }
Exemplo n.º 19
0
    //获取棋子路线
    public ResultData GetMoveLine(FenData fen)
    {
        ResultData result = Zoufamiddleware.GetMoveLine(fen);

        return(result);
    }
Exemplo n.º 20
0
//    private static ILogger log = Debug.unityLogger;

    public CreateZoufa(FenData fen) : base(fen)
    {
    }
Exemplo n.º 21
0
 public CheckZoufa(FenData fen) : base(fen)
 {
     change = new ChangeQipan(fen);
 }
Exemplo n.º 22
0
 public void SetFenData(FenData fen)
 {
     Fen = fen;
 }