Enum chess_engine::Piece [−][src]
pub enum Piece {
King(Color, Position),
Queen(Color, Position),
Rook(Color, Position),
Bishop(Color, Position),
Knight(Color, Position),
Pawn(Color, Position),
}
Expand description
A piece on a board.
Every piece has both a color and a position. These, combined with the type of piece it is, determine things like
- The validity of legal moves
- The validity of legal attacks
- Move generation
- Material and positional value
Variants
Implementations
Get the name of the piece such as "pawn"
or "king"
.
All names are lowercase.
Get the material value for a piece. | Name | Value | |-|-| | King | 99999 | | Queen | 9 | | Rook | 5 | | Bishop | 3 | | Knight | 3 | | Pawn | 1 |
Get the weighted value of a piece. This simply factors in position to the pieces value. For example, a knight that is in the center is more favorable than a knight on the side of the board. Similarly, a king in the center of the board is highly unfavorable compared to a king its respective side.
Additionally, the weighted value of the piece is 10 times greater than its material value, plus or minus a weight ranging between 5.0 and -5.0.
Get the color of a given piece.
Is this piece a starting pawn?
A starting pawn is a pawn that has not been pushed yet whatsoever.
Is this piece in the starting position for the queenside rook?
This method will only return true for rooks that are in the position of the queenside rook, not for any particular rook.
Is this piece in the starting position for the kingside rook?
This method will only return true for rooks that are in the position of the kingside rook, not for any particular rook.
Change the position of this piece to a new position.
For example, Pawn(Color::White, E4).move_to(E5)
will result in
Pawn(Color::White, E5)
. This does not check for move legality,
it merely creates a new piece with the same color and type, but
with a new position.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Piece
impl UnwindSafe for Piece
Blanket Implementations
Mutably borrows from an owned value. Read more