Ejemplo n.º 1
0
        public void UndoMove(Move m)
        {
            Square from    = m.From();
            Square to      = m.To();
            bool   promote = m.Promote();

            // 手番変更
            sideToMove = (sideToMove == Color.BLACK) ? Color.WHITE : Color.BLACK;

            int tKind = square[(int)to];
            int fKind = IsDrop(from) ? sideToMove == Color.BLACK ? (int)from : (int)from + Piece.WhiteBit
                                      : (promote ? tKind - Piece.PromoteBit : tKind);
            int capture = m.Capture();

            square[(int)to] = capture;

            if (IsDrop(from))
            {
                stand[(int)sideToMove][(int)from]++;
            }
            else
            {
                square[(int)from] = fKind;
                int capKind = Piece.Abs(capture);
                if (capture != Piece.Empty && capKind != Piece.BK)
                {
                    if (capKind == Piece.BPP)
                    {
                        capKind -= Piece.PromoteBit;
                    }
                    stand[(int)sideToMove][capKind]--;
                }
                if (Piece.Abs(tKind) == Piece.BK)
                {
                    kingPos[(int)sideToMove] = from;
                }
            }

            Debug.Assert(SquareIs(KingPos(Color.BLACK)) == Piece.BK);
            Debug.Assert(SquareIs(KingPos(Color.WHITE)) == Piece.WK);
        }
Ejemplo n.º 2
0
        public bool DoMove(Move m)
        {
            Square from    = m.From();
            Square to      = m.To();
            bool   promote = m.Promote();

            int fKind = IsDrop(from) ? sideToMove == Color.BLACK ? (int)from : (int)from + Piece.WhiteBit
                                      : square[(int)from];
            int tKind   = fKind + (promote ? Piece.PromoteBit : 0);
            int capture = square[(int)to];

            square[(int)to] = tKind;

            // 2回書き込まないようにする
            if (m.Capture() == 0)
            {
                m.AddCapture(capture);
            }

            if (IsDrop(from))
            {
                stand[(int)sideToMove][(int)from]--;
            }
            else
            {
                square[(int)from] = Piece.Empty;
                if (capture != Piece.Empty)
                {
                    if (Piece.Abs(capture) != Piece.BK)
                    {
                        if (Piece.Abs(capture) != Piece.BPP)
                        {
                            stand[(int)sideToMove][Piece.Abs(capture)]++;
                        }
                        else
                        {
                            stand[(int)sideToMove][Piece.BP]++;
                        }
                    }
                }

                if (Piece.Abs(fKind) == Piece.BK)
                {
                    kingPos[(int)sideToMove] = to;
                }
            }

            Debug.Assert((Piece.Abs(capture) == Piece.BK) || SquareIs(KingPos(Color.BLACK)) == Piece.BK);
            Debug.Assert((Piece.Abs(capture) == Piece.BK) || SquareIs(KingPos(Color.WHITE)) == Piece.WK);

            // 手番変更
            sideToMove = (sideToMove == Color.BLACK) ? Color.WHITE : Color.BLACK;

            // トライ勝ち
            if (Piece.Abs(fKind) == Piece.BK)
            {
                if (sideToMove == Color.WHITE && Square.SQ_08 < to && to < Square.SQ_12)
                {
                    return(true);
                }
                if (sideToMove == Color.BLACK && Square.SQ_20 < to && to < Square.SQ_24)
                {
                    return(true);
                }
            }

            return((capture == Piece.BK || capture == Piece.WK) ? true : false);
        }