Esempio n. 1
0
        private void PawnMoves(ref List <Move> list, BitBoard active)
        {
            int direction = player ? -1 : 1;

            //moving 1
            BitBoard finalPos = active.Offset(0, direction) & ~AllPieces;

            list.AddRange(Move.GetMoves(Category.Pawn, 0, direction, finalPos, false));
            //moving 2
            finalPos.Move(0, direction);
            list.AddRange(Move.GetMoves(Category.Pawn, 0, direction * 2, finalPos & ~AllPieces & (player ? BlackPawns : WhitePawns), false));

            //kill right
            finalPos = active.Offset(1, direction);
            list.AddRange(Move.GetMoves(Category.Pawn, 1, direction, finalPos & (player ? white : black), true));
            //kill left
            finalPos = active.Offset(-1, direction);
            list.AddRange(Move.GetMoves(Category.Pawn, -1, direction, finalPos & (player ? white : black), true));

            //en passant
            if (lastMove.Category == Category.Pawn && Math.Abs(lastMove.Start.Y - lastMove.End.Y) == 2)
            {
                //kill right
                finalPos = active.Offset(1, direction) & new BitBoard(lastMove.End).Offset(0, direction);
                list.AddRange(Move.GetMoves(Category.Pawn, 1, direction, finalPos, true));
                //kill left
                finalPos = active.Offset(-1, direction) & new BitBoard(lastMove.End).Offset(0, direction);
                list.AddRange(Move.GetMoves(Category.Pawn, -1, direction, finalPos, true));
            }
        }
Esempio n. 2
0
        private void TryMoveOrKill(ref List <Move> list, BitBoard active, int dx, int dy, Category c)
        {
            if (!active.Empty)
            {
                BitBoard finalPos;
                //pieces that are out of bounce are no more active
                finalPos = active.Offset(dx, dy);

                list.AddRange(Move.GetMoves(c, dx, dy, finalPos & ~AllPieces, false));
                list.AddRange(Move.GetMoves(c, dx, dy, finalPos & (player ? white : black), true));
            }
        }
Esempio n. 3
0
        //voids
        public static List <Move> GetMoves(State.Category _cat, int dx, int dy, BitBoard _endPos, bool _kill)
        {
            List <Position> buffer = GetPos(_endPos.Value);
            List <Move>     ret    = new List <Move>(buffer.Count);

            for (int i = 0; i < buffer.Count; i++)
            {
                if (_cat == State.Category.Pawn && buffer[i].Y % 7 == 0)
                {
                    ret.Add(new Move(_cat, buffer[i].Offset(-dx, -dy), buffer[i], _kill, State.Category.Knight));
                    ret.Add(new Move(_cat, buffer[i].Offset(-dx, -dy), buffer[i], _kill, State.Category.Bishop));
                    ret.Add(new Move(_cat, buffer[i].Offset(-dx, -dy), buffer[i], _kill, State.Category.Rook));
                    ret.Add(new Move(_cat, buffer[i].Offset(-dx, -dy), buffer[i], _kill, State.Category.Queen));
                }
                else
                {
                    ret.Add(new Move(_cat, buffer[i].Offset(-dx, -dy), buffer[i], _kill));
                }
            }
            return(ret);
        }
Esempio n. 4
0
        //private functions
        private void TryMoveOrKill(ref List <Move> list, ref BitBoard active, int dx, int dy, Category c)
        {
            if (!active.Empty)
            {
                BitBoard coll, move, finalPos;
                //pieces that are out of bounce are no more active
                active.Move(dx, dy); active.Move(-dx, -dy);
                finalPos = active.Offset(dx, dy);
                //marks all  collisions points
                coll = finalPos & AllPieces;
                if (!coll.Empty)
                {
                    //are there pieces that dont collide?
                    if (coll != finalPos)
                    {                       //add all pieces that are active and dont collide
                        list.AddRange(Move.GetMoves(c, dx, dy, finalPos & ~coll, false));
                        //remove all not colliding pieces from collider
                        coll.RemoveAt(finalPos & ~coll);
                    }

                    //colliding with opposite color?
                    move = coll & (player ? white : black);
                    if (!move.Empty)
                    {
                        //adding all pieces that kill another
                        list.AddRange(Move.GetMoves(c, dx, dy, move, true));
                        //pieces that collide here are no more active
                        active.RemoveAt(move.Offset(-dx, -dy));
                    }
                    //pieces that collide with the same color are no more active
                    active.RemoveAt((coll & (player ? black : white)).Offset(-dx, -dy));
                }
                else
                {
                    list.AddRange(Move.GetMoves(c, dx, dy, finalPos, false));                  //no collision at all
                }
            }
        }
Esempio n. 5
0
        public State(State _s, Move _m)
        {
            lastMove = new Move(Category.Pawn, new Position(), new Position(), false);
            white    = _s.white;
            black    = _s.black;
            pawn     = _s.pawn;
            knight   = _s.knight;
            bishop   = _s.bishop;
            rook     = _s.rook;
            queen    = _s.queen;
            king     = _s.king;

            WhiteARookMoved = _s.WhiteARookMoved;
            WhiteHRookMoved = _s.WhiteHRookMoved;

            BlackARookMoved = _s.BlackARookMoved;
            BlackHRookMoved = _s.BlackHRookMoved;

            WhiteKingMoved = _s.WhiteKingMoved;
            BlackKingMoved = _s.BlackKingMoved;

            player = _s.player;
            DoMove(_m);
        }
Esempio n. 6
0
        //constructor
        public State()
        {
            lastMove = new Move(Category.Pawn, new Position(), new Position(), false);

            #region Standart
            white = new BitBoard(new byte[8]
            {
                255, 255, 0, 0,
                0, 0, 0, 0
            });
            black = new BitBoard(new byte[8]
            {
                0, 0, 0, 0,
                0, 0, 255, 255
            });
            pawn = new BitBoard(new byte[8]
            {
                0, 255, 0, 0,
                0, 0, 255, 0
            });
            rook = new BitBoard(new byte[8]
            {
                129, 0, 0, 0,
                0, 0, 0, 129
            });
            knight = new BitBoard(new byte[8]
            {
                66, 0, 0, 0,
                0, 0, 0, 66
            });
            bishop = new BitBoard(new byte[8]
            {
                36, 0, 0, 0,
                0, 0, 0, 36
            });
            queen = new BitBoard(new byte[8]
            {
                8, 0, 0, 0,
                0, 0, 0, 8
            });
            king = new BitBoard(new byte[8]
            {
                16, 0, 0, 0,
                0, 0, 0, 16
            });
            #endregion

            #region custom
//			white = new BitBoard(new byte[8]
//{
//				0, 1, 0, 0, 0, 0, 0, 0
//});
//			black = new BitBoard(new byte[8]{
//				0, 0, 0, 2, 0, 0, 0, 0
//			});
//			pawn = new BitBoard(new byte[8]
//			{
//				0, 1, 0, 2, 0, 0, 0, 0
//			});
//			knight = new BitBoard();
//			bishop = new BitBoard();
//			king = new BitBoard();
//			queen = new BitBoard();
//			rook = new BitBoard();
            #endregion


            CalcSoftMoves();
        }
Esempio n. 7
0
 public void RemoveAt(BitBoard _val)
 {
     this &= ~_val;
 }