Enum chess_engine::Piece[][src]

pub enum Piece {
    King(ColorPosition),
    Queen(ColorPosition),
    Rook(ColorPosition),
    Bishop(ColorPosition),
    Knight(ColorPosition),
    Pawn(ColorPosition),
}
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

  1. The validity of legal moves
  2. The validity of legal attacks
  3. Move generation
  4. Material and positional value

Variants

King(ColorPosition)

Tuple Fields of King

0: Color1: Position
Queen(ColorPosition)

Tuple Fields of Queen

0: Color1: Position
Rook(ColorPosition)

Tuple Fields of Rook

0: Color1: Position
Bishop(ColorPosition)

Tuple Fields of Bishop

0: Color1: Position
Knight(ColorPosition)

Tuple Fields of Knight

0: Color1: Position
Pawn(ColorPosition)

Tuple Fields of Pawn

0: Color1: Position

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.

Get the color of a given piece.

Get the position of a piece.

Is this piece a king?

Is this piece a queen?

Is this piece a rook?

Is this piece a bishop?

Is this piece a knight?

Is this piece a pawn?

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.