Piece

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

A piece architecture. This is not an abstract class because empty squares will be filled with piece with the "_" color.

Value parameters

c

The color of the piece

p

The position of the piece

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Bishop
class King
class Knight
class Pawn
class Queen
class Rook
Show all

Members list

Value members

Concrete methods

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

The color of the piece.

The color of the piece.

Attributes

Returns

The color of the 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.

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

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

The position of the piece.

The position of the piece.

Attributes

Returns

The position of the 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
Any

Concrete 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