/// <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; } } }
/// <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; } } }