Struct shogi::piece::Piece[][src]

pub struct Piece {
    pub piece_type: PieceType,
    pub color: Color,
}
Expand description

Represents a piece on the game board.

Fields

piece_type: PieceTypecolor: Color

Implementations

Creates a new instance of Piece from SFEN formatted string.

Returns an instance of Piece after promotion.

Examples

use shogi::{Color, PieceType, Piece};

let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::ProPawn, color: Color::Black};

assert_eq!(Some(pc2), pc1.promote());
assert_eq!(None, pc2.promote());

Returns an instance of Piece before promotion.

Examples

use shogi::{Color, PieceType, Piece};

let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::ProPawn, color: Color::Black};

assert_eq!(Some(pc1), pc2.unpromote());
assert_eq!(None, pc1.unpromote());

Returns an instance of Piece with the reversed color.

Examples

use shogi::{Color, PieceType, Piece};

let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::Pawn, color: Color::White};

assert_eq!(pc2, pc1.flip());
assert_eq!(pc1, pc2.flip());

Tests if it is legal to place this piece at the given square.

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

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

This method tests for !=.

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.