Game class
Representation of the game.
Contains all information regarding game from logic perspective. The _board
contains current position, _gameHistory
contains move history and provides
option to undo move and also go back and forth between moves.
Constructors
- Game()
-
Creates new
Game
object with default initial_board
and empty_gameHistory
. - Game.fromPosition({required Position position, GameHistory? gameHistory, GameStatus? status})
-
Creates new
Game
object from givenposition
,gameHistory
, andstatus
.
Properties
- blackWon → bool
-
Returns
true
if the game was won by black.no setter - board → Board
-
Returns the current
_board
.no setter - canGoBackward → bool
-
Is there a move in the past?
no setter
- canGoForward → bool
-
Is there a future move?
no setter
- canUndo → bool
-
Is there is a move that can be undone?
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- inProgress → bool
-
Returns
true
if the game is currently in progress.no setter - isGameOver → bool
-
Returns whether the game is over or not.
no setter
-
legalMoves
→ List<
Move> -
no setter
-
movesFromFuture
→ List<
PlayedMove> -
Returns moves that are in the future. That means they were played but
player went backward to explore move history.
no setter
-
movesPlayed
→ List<
PlayedMove> -
Returns moves played until current position.
no setter
- playerOnTurn → PieceColor
-
Returns the color of the playerOnTurn.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → GameStatus
-
Returns the current status of the game.
no setter
- whiteWon → bool
-
Returns
true
if the game was won by white.no setter
Methods
-
backward(
) → PlayedMove? -
Moves one move backward in the
_gameHistory
. -
blackResigned(
) → void - Sets the current status to GameStatus.blackResigned.
-
draw(
) → void - Sets the current status to GameStatus.draw.
-
flagged(
[PieceColor? player]) → void -
Sets the current status to GameStatus.whiteFlagged or
GameStatus.blackFlagged, depending on who the
player
is. -
forward(
) → PlayedMove? -
Moves one move forward in the
_gameHistory
. -
move(
Move m) → PlayedMove? -
Performs a move
m
on the board and updates_gameStatus
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → PlayedMove? - Undoes the last move.
-
whiteResigned(
) → void - Sets the current status to GameStatus.whiteResigned.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited