Esempio n. 1
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done by a move when its carried out.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                for (int i = 0; i < m_directions.Length; ++i)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    while (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPiece() == Piece.None)
                        {
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                        }
                        else
                        {
                            if (m_iterator.CurrentPieceColor() != m_color)
                            {
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                            }

                            break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done by a move when its carried out.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                //Basic moves
                for (int i = 0; i < m_directions.Length; ++i)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    if (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPieceColor() != m_color)
                        {
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                        }
                    }
                }

                //Castling moves
                switch (m_color)
                {
                case PieceColor.White:
                    if (board.State.WhiteCanCastleLong &&
                        board.IsPathClear(Square.E1, Square.A1) &&
                        !board.IsSquareAttacted(PieceColor.Black, Square.E1) &&
                        !board.IsSquareAttacted(PieceColor.Black, Square.D1))
                    {
                        moves.Add(new Move(board, Square.E1, Square.C1, Square.A1, Square.D1));
                    }

                    if (board.State.WhiteCanCastleShort &&
                        board.IsPathClear(Square.E1, Square.H1) &&
                        !board.IsSquareAttacted(PieceColor.Black, Square.E1) &&
                        !board.IsSquareAttacted(PieceColor.Black, Square.F1))
                    {
                        moves.Add(new Move(board, Square.E1, Square.G1, Square.H1, Square.F1));
                    }
                    break;

                case PieceColor.Black:
                    if (board.State.BlackCanCastleLong &&
                        board.IsPathClear(Square.E8, Square.A8) &&
                        !board.IsSquareAttacted(PieceColor.White, Square.E8) &&
                        !board.IsSquareAttacted(PieceColor.White, Square.D8))
                    {
                        moves.Add(new Move(board, Square.E8, Square.C8, Square.A8, Square.D8));
                    }

                    if (board.State.BlackCanCastleShort &&
                        board.IsPathClear(Square.E8, Square.H8) &&
                        !board.IsSquareAttacted(PieceColor.White, Square.E8) &&
                        !board.IsSquareAttacted(PieceColor.White, Square.F8))
                    {
                        moves.Add(new Move(board, Square.E8, Square.G8, Square.H8, Square.F8));
                    }
                    break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done in MoveOrganizer when adding a move.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                //Basic moves
                for (int i = 0; i < m_directions.Length; i++)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    if (m_iterator.Next())
                        if (m_iterator.CurrentPieceColor() != m_color)
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                }

                //Castling moves
                switch (m_color)
                {
                    case PieceColor.White:
                        if (board.State.WhiteCanCastleLong &&
                            board.IsPathClear(Square.E1, Square.A1) &&
                            !board.IsSquareAttacted(PieceColor.Black, Square.E1) &&
                            !board.IsSquareAttacted(PieceColor.Black, Square.D1))
                        {
                            moves.Add(new CastlingMove(board, Square.E1, Square.C1));
                        }

                        if (board.State.WhiteCanCastleShort &&
                            board.IsPathClear(Square.E1, Square.H1) &&
                            !board.IsSquareAttacted(PieceColor.Black, Square.E1) &&
                            !board.IsSquareAttacted(PieceColor.Black, Square.F1))
                        {
                            moves.Add(new CastlingMove(board, Square.E1, Square.G1));
                        }
                    break;

                    case PieceColor.Black:
                        if (board.State.BlackCanCastleLong &&
                            board.IsPathClear(Square.E8, Square.A8) &&
                            !board.IsSquareAttacted(PieceColor.White, Square.E8) &&
                            !board.IsSquareAttacted(PieceColor.White, Square.D8))
                        {
                            moves.Add(new CastlingMove(board, Square.E8, Square.C8));
                        }

                        if (board.State.BlackCanCastleShort &&
                            board.IsPathClear(Square.E8, Square.H8) &&
                            !board.IsSquareAttacted(PieceColor.White, Square.E8) &&
                            !board.IsSquareAttacted(PieceColor.White, Square.F8))
                        {
                            moves.Add(new CastlingMove(board, Square.E8, Square.G8));
                        }
                    break;
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Generate moves a FlyweightPiece can make.
 /// This method does not varifies if a move puts its own king in check.
 /// This is done in MoveOrganizer when adding a move.
 /// </summary>
 /// <param name="board">Board to generate moves for.</param>
 /// <param name="location">Location of the piece.</param>
 /// <param name="moves">Container class to which all generated moves are added.</param>
 public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
 {
     if (m_color == board.State.ColorToPlay)
     {
         for (int i = 0; i < m_directions.Length; i++)
         {
             m_iterator.Reset(board, location, m_directions[i]);
             if (m_iterator.Next(m_directions[(i + 0) % m_directions.Length]) &&
                 m_iterator.Next(m_directions[(i + 1) % m_directions.Length]) &&
                 m_iterator.Next(m_directions[(i + 2) % m_directions.Length]))
             {
                 if (m_iterator.CurrentPieceColor() != m_color)
                     moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
             }
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Generate moves a FlyweightPiece can make.
 /// This method does not varifies if a move puts its own king in check.
 /// This is done in MoveOrganizer when adding a move.
 /// </summary>
 /// <param name="board">Board to generate moves for.</param>
 /// <param name="location">Location of the piece.</param>
 /// <param name="moves">Container class to which all generated moves are added.</param>
 public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
 {
     if (m_color == board.State.ColorToPlay)
     {
         for (int i = 0; i < m_directions.Length; i++)
         {
             m_iterator.Reset(board, location, m_directions[i]);
             if (m_iterator.Next(m_directions[(i + 0) % m_directions.Length]) &&
                 m_iterator.Next(m_directions[(i + 1) % m_directions.Length]) &&
                 m_iterator.Next(m_directions[(i + 2) % m_directions.Length]))
             {
                 if (m_iterator.CurrentPieceColor() != m_color)
                 {
                     moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                 }
             }
         }
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Generate moves a FlyweightPiece can make.
 /// This method does not varifies if a move puts its own king in check.
 /// This is done by a move when its carried out.
 /// </summary>
 /// <param name="board">Board to generate moves for.</param>
 /// <param name="location">Location of the piece.</param>
 /// <param name="moves">Container class to which all generated moves are added.</param>
 public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
 {
     if (m_color == board.State.ColorToPlay)
     {
         for (int i = 0; i < KNIGHT_MOVES; ++i)
         {
             m_iterator.Reset(board, location, m_directions[i]);
             m_iterator.Next(m_directions[i + 0]);
             m_iterator.Next(m_directions[i + 1]);
             if (m_iterator.Next(m_directions[i + 2]))
             {
                 if (m_iterator.CurrentPieceColor() != m_color)
                 {
                     moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                 }
             }
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done in MoveOrganizer when adding a move.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                for (int i = 0; i < m_directions.Length; i++)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    while (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPiece() == Piece.None)
                        {
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                        }
                        else
                        {
                            if (m_iterator.CurrentPieceColor() != m_color)
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));

                            break;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done in MoveOrganizer when adding a move.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                for (int i = 0; i < m_directions.Length; i++)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    if (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPiece() == Piece.None &&
                            (m_iterator.CurrentDirection() == Direction.Up || m_iterator.CurrentDirection() == Direction.Down))
                        {
                            //Non hitting moves
                            switch (Board.Rank(m_iterator.CurrentSquare()))
                            {
                                case 0:
                                    //Black non hitting promotion move
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                                break;

                                case 7:
                                    //White non hitting promotion move
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                                break;

                                default:
                                    //Basic non hitting move
                                    moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                break;
                            }

                            if ((Board.Rank(m_iterator.CurrentSquare()) == 2 && m_iterator.CurrentDirection() == Direction.Up) ||
                                (Board.Rank(m_iterator.CurrentSquare()) == 5 && m_iterator.CurrentDirection() == Direction.Down))
                            {   //Two squares forward opening move
                                m_iterator.Next();
                                if (m_iterator.CurrentPiece() == Piece.None)
                                    moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                            }
                        }
                        else if (m_iterator.CurrentPiece() != Piece.None && m_iterator.CurrentPieceColor() != m_color &&
                                 m_iterator.CurrentDirection() != Direction.Up && m_iterator.CurrentDirection() != Direction.Down)
                        {
                            //Hitting moves
                            switch (Board.Rank(m_iterator.CurrentSquare()))
                            {
                                case 0:
                                    //Black hitting promotion move
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                                break;

                                case 7:
                                    //White hitting promotion move
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                                    moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                                break;

                                default:
                                    //Basic hitting move
                                    moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                break;
                            }
                        }
                    }
                }

                //EnPassant moves
                if (board.State.EnPassantTarget != Square.None &&
                    Math.Abs(board.State.EnPassantTarget - location) == 1 &&
                    Board.Rank(board.State.EnPassantTarget) == Board.Rank(location))
                {
                    switch (m_color)
                    {
                        case PieceColor.White:
                            moves.Add(new EnPassantCaptureMove(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) + 1)));
                        break;

                        case PieceColor.Black:
                            moves.Add(new EnPassantCaptureMove(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) - 1)));
                        break;
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done by a move when its carried out.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
              {
            //Non hitting moves
            m_iterator.Reset(board, location, m_directions[0]);
            if (m_iterator.Next())
            {
              if (m_iterator.CurrentPiece() == Piece.None)
              {
            switch (Board.Rank(m_iterator.CurrentSquare()))
            {
              case 0:
                //Black non hitting promotion move
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                break;

              case 7:
                //White non hitting promotion move
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                break;

              default:
                //Basic non hitting move
                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                break;
            }

            //Two squares forward opening move
            if (Board.Rank(m_iterator.CurrentSquare()) == moveAgainRow)
            {
              m_iterator.Next();
              if (m_iterator.CurrentPiece() == Piece.None)
                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
            }
              }
            }

            //Hitting moves to the left and right
            for (int i = 1; i < m_directions.Length; ++i)
            {
              m_iterator.Reset(board, location, m_directions[i]);
              if (m_iterator.Next())
              {
            if (m_iterator.CurrentPieceColor() == m_opponentColor)
            {
              switch (Board.Rank(m_iterator.CurrentSquare()))
              {
                case 0:
                  //Black hitting promotion move
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                  break;

                case 7:
                  //White hitting promotion move
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                  break;

                default:
                  //Basic hitting move
                  moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                  break;
              }
            }
              }
            }

            //EnPassant moves
            if (Math.Abs(board.State.EnPassantTarget - location) == 1)
            {
              switch (m_color)
              {
            case PieceColor.White:
              moves.Add(new Move(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) + 1), board.State.EnPassantTarget));
              break;

            case PieceColor.Black:
              moves.Add(new Move(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) - 1), board.State.EnPassantTarget));
              break;
              }
            }
              }
        }
Esempio n. 10
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done in MoveOrganizer when adding a move.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                for (int i = 0; i < m_directions.Length; i++)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    if (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPiece() == Piece.None &&
                            (m_iterator.CurrentDirection() == Direction.Up || m_iterator.CurrentDirection() == Direction.Down))
                        {
                            //Non hitting moves
                            switch (Board.Rank(m_iterator.CurrentSquare()))
                            {
                            case 0:
                                //Black non hitting promotion move
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                                break;

                            case 7:
                                //White non hitting promotion move
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                                break;

                            default:
                                //Basic non hitting move
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                break;
                            }

                            if ((Board.Rank(m_iterator.CurrentSquare()) == 2 && m_iterator.CurrentDirection() == Direction.Up) ||
                                (Board.Rank(m_iterator.CurrentSquare()) == 5 && m_iterator.CurrentDirection() == Direction.Down))
                            {   //Two squares forward opening move
                                m_iterator.Next();
                                if (m_iterator.CurrentPiece() == Piece.None)
                                {
                                    moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                }
                            }
                        }
                        else if (m_iterator.CurrentPiece() != Piece.None && m_iterator.CurrentPieceColor() != m_color &&
                                 m_iterator.CurrentDirection() != Direction.Up && m_iterator.CurrentDirection() != Direction.Down)
                        {
                            //Hitting moves
                            switch (Board.Rank(m_iterator.CurrentSquare()))
                            {
                            case 0:
                                //Black hitting promotion move
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                                break;

                            case 7:
                                //White hitting promotion move
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                                moves.Add(new PawnPromotionMove(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                                break;

                            default:
                                //Basic hitting move
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                break;
                            }
                        }
                    }
                }

                //EnPassant moves
                if (board.State.EnPassantTarget != Square.None &&
                    Math.Abs(board.State.EnPassantTarget - location) == 1 &&
                    Board.Rank(board.State.EnPassantTarget) == Board.Rank(location))
                {
                    switch (m_color)
                    {
                    case PieceColor.White:
                        moves.Add(new EnPassantCaptureMove(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) + 1)));
                        break;

                    case PieceColor.Black:
                        moves.Add(new EnPassantCaptureMove(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) - 1)));
                        break;
                    }
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Generate moves a FlyweightPiece can make.
 /// This method does not varifies if a move puts its own king in check.
 /// This is done by a move when its carried out.
 /// </summary>
 /// <param name="board">Board to generate moves for.</param>
 /// <param name="location">Location of the piece.</param>
 /// <param name="moves">Container class to which all generated moves are added.</param>
 public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
 {
     if (m_color == board.State.ColorToPlay)
       {
     for (int i = 0; i < KNIGHT_MOVES; ++i)
     {
       m_iterator.Reset(board, location, m_directions[i]);
       m_iterator.Next(m_directions[i + 0]);
       m_iterator.Next(m_directions[i + 1]);
       if (m_iterator.Next(m_directions[i + 2]))
       {
     if (m_iterator.CurrentPieceColor() != m_color)
       moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
       }
     }
       }
 }
Esempio n. 12
0
        /// <summary>
        /// Generate moves a FlyweightPiece can make.
        /// This method does not varifies if a move puts its own king in check.
        /// This is done by a move when its carried out.
        /// </summary>
        /// <param name="board">Board to generate moves for.</param>
        /// <param name="location">Location of the piece.</param>
        /// <param name="moves">Container class to which all generated moves are added.</param>
        public void GenerateMoves(Board board, Square location, MoveOrganizer moves)
        {
            if (m_color == board.State.ColorToPlay)
            {
                //Non hitting moves
                m_iterator.Reset(board, location, m_directions[0]);
                if (m_iterator.Next())
                {
                    if (m_iterator.CurrentPiece() == Piece.None)
                    {
                        switch (Board.Rank(m_iterator.CurrentSquare()))
                        {
                        case 0:
                            //Black non hitting promotion move
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                            break;

                        case 7:
                            //White non hitting promotion move
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                            break;

                        default:
                            //Basic non hitting move
                            moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                            break;
                        }

                        //Two squares forward opening move
                        if (Board.Rank(m_iterator.CurrentSquare()) == moveAgainRow)
                        {
                            m_iterator.Next();
                            if (m_iterator.CurrentPiece() == Piece.None)
                            {
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                            }
                        }
                    }
                }

                //Hitting moves to the left and right
                for (int i = 1; i < m_directions.Length; ++i)
                {
                    m_iterator.Reset(board, location, m_directions[i]);
                    if (m_iterator.Next())
                    {
                        if (m_iterator.CurrentPieceColor() == m_opponentColor)
                        {
                            switch (Board.Rank(m_iterator.CurrentSquare()))
                            {
                            case 0:
                                //Black hitting promotion move
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackBishop));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackKnight));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackQueen));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.BlackRook));
                                break;

                            case 7:
                                //White hitting promotion move
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteBishop));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteKnight));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteQueen));
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare(), Piece.WhiteRook));
                                break;

                            default:
                                //Basic hitting move
                                moves.Add(new Move(board, location, m_iterator.CurrentSquare()));
                                break;
                            }
                        }
                    }
                }

                //EnPassant moves
                if (Math.Abs(board.State.EnPassantTarget - location) == 1)
                {
                    switch (m_color)
                    {
                    case PieceColor.White:
                        moves.Add(new Move(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) + 1), board.State.EnPassantTarget));
                        break;

                    case PieceColor.Black:
                        moves.Add(new Move(board, location, Board.Position(Board.File(board.State.EnPassantTarget), Board.Rank(location) - 1), board.State.EnPassantTarget));
                        break;
                    }
                }
            }
        }