/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { Square square; switch (movesType) { case Moves.MoveListNames.All: for (int i = 0; i < moveVectors.Length; i++) { square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } break; case Moves.MoveListNames.CapturesPromotions: for (int i = 0; i < moveVectors.Length; i++) { square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } break; } }
/// <summary> /// Generate "lazy" moves for all pieces. Lazy means we include moves that put our own king in check. /// </summary> /// <param name="moves"> /// Move list to be filled with moves. /// </param> /// <param name="movesType"> /// Type of moves to be generated. e.g. all or just captures. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { foreach (Piece piece in this.Pieces) { piece.GenerateLazyMoves(moves, movesType); } }
/// <summary> /// The append piece path. /// </summary> /// <param name="moves"> /// The moves. /// </param> /// <param name="piece"> /// The piece. /// </param> /// <param name="player"> /// The player. /// </param> /// <param name="offset"> /// The offset. /// </param> /// <param name="movesType"> /// The moves type. /// </param> public static void AppendPiecePath( Moves moves, Piece piece, Player player, int offset, Moves.MoveListNames movesType) { int intOrdinal = piece.Square.Ordinal; Square square; intOrdinal += offset; while ((square = GetSquare(intOrdinal)) != null) { if (square.Piece == null) { if (movesType == Moves.MoveListNames.All) { moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, null, 0, 0); } } else if (square.Piece.Player.Colour != player.Colour && square.Piece.IsCapturable) { moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, square.Piece, 0, 0); break; } else { break; } intOrdinal += offset; } }
/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { for (int i = 0; i < moveVectors.Length; i++) { Board.AppendPiecePath(moves, this.Base, this.Base.Player, moveVectors[i], movesType); } }
/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { Board.AppendPiecePath(moves, this.Base, this.Base.Player, 17, movesType); Board.AppendPiecePath(moves, this.Base, this.Base.Player, 15, movesType); Board.AppendPiecePath(moves, this.Base, this.Base.Player, -15, movesType); Board.AppendPiecePath(moves, this.Base, this.Base.Player, -17, movesType); }
/// <summary> /// The generate lazy moves. /// </summary> /// <param name="depth"> /// The depth. /// </param> /// <param name="moves"> /// The moves. /// </param> /// <param name="movesType"> /// The moves type. /// </param> /// <param name="squareAttacking"> /// The square attacking. /// </param> public void GenerateLazyMoves(int depth, Moves moves, Moves.MoveListNames movesType, Square squareAttacking) { // if (squareAttacking==null) // { // All moves as defined by movesType foreach (Piece piece in this.Pieces) { piece.GenerateLazyMoves(moves, movesType); /* * if (movesType != Moves.MoveListNames.All) * { * int intIndex; * for (intIndex = moves.Count - 1; intIndex >= 0; intIndex--) * { * Move move = moves[intIndex]; * if (!( * move.Name == Move.MoveNames.PawnPromotionQueen * && * move.PieceCaptured == null * (move.Name == Move.MoveNames.Standard * && move.From.Piece.BasicValue < move.To.Piece.BasicValue) || || (move.Name == Move.MoveNames.Standard || && !move.To.PlayerCanMoveToThisSquare(move.Piece.Player.OtherPlayer)) || || move.To.Ordinal==squareAttacking.Ordinal || )) || { || moves.Remove(move); || } || } ||} */ } // } // else // { // Just re-capture moves // squareAttacking.AttackerMoveList(moves, this); // } }
/* * private Move.enmName MoveName(Player.enmColour colourPlayer, Square squareTo) * { * if (colourPlayer==Player.enmColour.White && squareTo.Rank==7 || colourPlayer==Player.enmColour.Black && squareTo.Rank==0) * { * return Move.enmName.PawnPromotion; * } * else * { * return Move.enmName.Standard; * } * } */ #region Public Methods /// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { // Types of promotion to generate. Removed bishop and Rook. Move.MoveNames[] promotionTypes = { Move.MoveNames.PawnPromotionQueen, Move.MoveNames.PawnPromotionKnight // Move.MoveNames.PawnPromotionBishop, Move.MoveNames.PawnPromotionRook // Why bother? }; Square square; bool isPromotion = (this.Base.Player.Colour == Player.PlayerColourNames.White && this.Base.Square.Rank == 6) || (this.Base.Player.Colour == Player.PlayerColourNames.Black && this.Base.Square.Rank == 1); int intMovesToGenerate = isPromotion ? promotionTypes.Length : 1; for (int intIndex = 0; intIndex < intMovesToGenerate; intIndex++) { // Take right if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset)) != null) { if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable) { moves.Add( 0, 0, isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } // Take left if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset)) != null) { if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable) { moves.Add( 0, 0, isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } // Forward one if (movesType == Moves.MoveListNames.All || isPromotion) { if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null) { moves.Add( 0, 0, isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } } // Forward two if (movesType == Moves.MoveListNames.All) { if (!this.Base.HasMoved) { // Check one square ahead is not occupied if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null) { if ( (square = Board.GetSquare( this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null) { moves.Add( 0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } } } } // En Passent if ((this.Base.Square.Rank == 4 && this.Base.Player.Colour == Player.PlayerColourNames.White) || (this.Base.Square.Rank == 3 && this.Base.Player.Colour == Player.PlayerColourNames.Black)) { Piece piecePassed; // Left if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1 && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn && piecePassed.Player.Colour != this.Base.Player.Colour) { square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset); moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0); } // Right if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1 && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn && piecePassed.Player.Colour != this.Base.Player.Colour) { square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset); moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0); } } }
/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { this.Top.GenerateLazyMoves(moves, movesType); }
/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { Square square; switch (movesType) { case Moves.MoveListNames.All: square = Board.GetSquare(this.Base.Square.Ordinal - 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } if (this.CanCastleKingSide) { moves.Add(0, 0, Move.MoveNames.CastleKingSide, this.Base, this.Base.Square, Board.GetSquare(this.Base.Square.Ordinal + 2), null, 0, 0); } if (this.CanCastleQueenSide) { moves.Add(Game.TurnNo, this.Base.LastMoveTurnNo, Move.MoveNames.CastleQueenSide, this.Base, this.Base.Square, Board.GetSquare(this.Base.Square.Ordinal - 2), null, 0, 0); } break; case Moves.MoveListNames.CapturesPromotions: square = Board.GetSquare(this.Base.Square.Ordinal - 1); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 15); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 16); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 17); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 1); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 15); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 16); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 17); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } break; } }
/// <summary> /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check. /// </summary> /// <param name="moves"> /// Moves list that will be populated with lazy moves. /// </param> /// <param name="movesType"> /// Types of moves to include. e.g. All, or captures-only. /// </param> public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType) { Square square; switch (movesType) { case Moves.MoveListNames.All: square = Board.GetSquare(this.Base.Square.Ordinal + 33); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 18); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 14); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 31); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 33); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 18); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 14); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 31); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } break; case Moves.MoveListNames.CapturesPromotions: square = Board.GetSquare(this.Base.Square.Ordinal + 33); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 18); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 14); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 31); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 33); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal - 18); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 14); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } square = Board.GetSquare(this.Base.Square.Ordinal + 31); if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0); } break; } }