Pawn

Pawn
class Pawn(c: String, p: Position) extends Piece

King piece.

A pawn is a piece that can only go forward (facing its forward from its color pieces)

If a pawn make it to the other side of the board, it promotes in either a queen, a bishop, a knight or a rook.

Value parameters

c

The color of the piece.

p

The position of the piece.

Attributes

Graph
Supertypes
class Piece
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def availableMovements(friendlyPieces: List[Piece], enemiesPieces: List[Piece]): List[Position]

The available movements of pawn.

The available movements of pawn.

A pawn can move forward of one square if the path is clear, or capture an enemy piece in its direct diagonal forward vicinity.

If a pawn makes its first move, it can move two squares at once if the path is clear.

Value parameters

enemiesPieces

Enemies pieces.

friendlyPieces

Allies pieces.

Attributes

Returns

Available movements of the pawn.

Definition Classes
def enPassant: Boolean

Indicates if en passant is possible for this pawn.

Indicates if en passant is possible for this pawn.

Attributes

Returns

true if it is possible, false otherwise.

def enPassant_(target: Boolean): Unit
def promote(kind: String): Piece

The pawn can promote when it reaches the last row.

The pawn can promote when it reaches the last row.

Value parameters

kind

The piece name into which promotes.

Attributes

Returns

The wanted piece.

override def toString(): String

Overriding the toString method.

Overriding the toString method.

Neutral piece will be printed as blank space.

Attributes

Returns

The blank space

Definition Classes
Piece -> Any

Inherited methods

def color: String

The color of the piece.

The color of the piece.

Attributes

Returns

The color of the piece.

Inherited from:
Piece
def isValidMovement(targetPosition: Position, friendlyPieces: List[Piece], enemiesPieces: List[Piece], friendlyKing: King): Boolean

A piece cannot move if it puts its king in check.

A piece cannot move if it puts its king in check.

This function filters valid moves from invalid ones. It verifies if the king is not the direct target of enemies pieces once the piece has moved.

The function does not modify any of the parameters, neither the piece itself.

Value parameters

enemiesPieces

The enemies pieces.

friendlyKing

The ally king.

friendlyPieces

The allies pieces.

targetPosition

The square the piece wants to go.

Attributes

Returns

true if the move is valid, false otherwise.

Inherited from:
Piece
def move(newRow: Int, newColumn: Int): Unit

Move a piece.

Move a piece.

This function moves a piece by moving its given position.

Value parameters

newColumn

The new position column

newRow

The new position row

Attributes

Inherited from:
Piece
def move(newPos: Position): Unit

Move a piece.

Move a piece.

This function moves a piece by moving its given position.

Value parameters

newPos

The new position

Attributes

Inherited from:
Piece

The position of the piece.

The position of the piece.

Attributes

Returns

The position of the piece.

Inherited from:
Piece

Inherited fields

val longRangeMovements: (List[Piece], List[Piece], Int, Int) => List[Position]

Movements for long range pieces.

Movements for long range pieces.

Returns a list containing all the squares in the given direction from the piece Position until it reaches either the end of the board or a piece.

If the last square is an enemy piece, keep it to the list (because it can be captured)

Attributes

Inherited from:
Piece