Exemplo 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));
            }
        }
Exemplo n.º 2
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
                }
            }
        }