ColorShapeLinks
An assignment for the AI course unit of the Bachelor in Videogames at Lusófona University
Board Class Reference

Represents the game board. More...

Collaboration diagram for Board:
Collaboration graph

Public Member Functions

 Board (int rows=7, int cols=7, int piecesInSequence=4, int roundPieces=10, int squarePieces=11)
 Creates a new board. More...
 
int DoMove (PShape shape, int col)
 Make a move, return row More...
 
Move UndoMove ()
 Undo last move. More...
 
Winner CheckWinner (Pos[] solution=null)
 Check if there is a winner. More...
 
Board Copy ()
 Returns a copy of this board which can be freely modified by the AI in a different thread. More...
 
int PieceCount (PColor color, PShape shape)
 Get number of remaining pieces with the given color and shape. More...
 
bool IsColumnFull (int col)
 Is the specified column full? More...
 

Public Attributes

readonly int rows
 Number of rows in the board. More...
 
readonly int cols
 Number of columns in the board. More...
 
readonly int piecesInSequence
 How many pieces in sequence to find a winner. More...
 
readonly int roundPieces
 Initial number of round pieces for each player. More...
 
readonly int squarePieces
 Initial number of square pieces for each player. More...
 
readonly IEnumerable< IEnumerable< Pos > > winCorridors
 Array of win corridors, which can be used for building an heuristic. More...
 

Properties

Piecethis[int row, int col] [get]
 Read-only indexer for allowing the board contents to be accessed by external code. More...
 
PColor Turn [get, private set]
 Who's turn is it? More...
 

Detailed Description

Represents the game board.

Definition at line 12 of file Board.cs.

Constructor & Destructor Documentation

◆ Board()

Board ( int  rows = 7,
int  cols = 7,
int  piecesInSequence = 4,
int  roundPieces = 10,
int  squarePieces = 11 
)
inline

Creates a new board.

Parameters
rowsNumber of rows.
colsNumber of columns.
piecesInSequenceNumber of required pieces in a row for player to win.
roundPiecesInitial number of round pieces per player.
squarePiecesInitial number of square pieces per player.

Definition at line 127 of file Board.cs.

Member Function Documentation

◆ CheckWinner()

Winner CheckWinner ( Pos[]  solution = null)
inline

Check if there is a winner.

Parameters
solutionOptional parameter where solution will be placed if there is a winner.
Returns
The Winner of the current game, if any.

Definition at line 418 of file Board.cs.

◆ Copy()

Board Copy ( )
inline

Returns a copy of this board which can be freely modified by the AI in a different thread.

Returns
A copy of this board.

Definition at line 471 of file Board.cs.

◆ DoMove()

int DoMove ( PShape  shape,
int  col 
)
inline

Make a move, return row

Parameters
shapeShape of piece used in move (color is obtained from Board.Turn).
colColumn where to drop piece.
Returns
Row where piece was placed or -1 if move is invalid.

Definition at line 305 of file Board.cs.

◆ IsColumnFull()

bool IsColumnFull ( int  col)

Is the specified column full?

Parameters
colThe column to check if it's full.
Returns
true if the column is full, false otherwise.

◆ PieceCount()

int PieceCount ( PColor  color,
PShape  shape 
)

Get number of remaining pieces with the given color and shape.

Parameters
colorPieces color.
shapePieces shape.
Returns
Number of remaining pieces with the given color and shape.

◆ UndoMove()

Move UndoMove ( )
inline

Undo last move.

Returns
The Move that was undone.

Definition at line 374 of file Board.cs.

Member Data Documentation

◆ cols

readonly int cols

Number of columns in the board.

Definition at line 53 of file Board.cs.

◆ piecesInSequence

readonly int piecesInSequence

How many pieces in sequence to find a winner.

Definition at line 56 of file Board.cs.

◆ roundPieces

readonly int roundPieces

Initial number of round pieces for each player.

Definition at line 59 of file Board.cs.

◆ rows

readonly int rows

Number of rows in the board.

Definition at line 50 of file Board.cs.

◆ squarePieces

readonly int squarePieces

Initial number of square pieces for each player.

Definition at line 62 of file Board.cs.

◆ winCorridors

readonly IEnumerable<IEnumerable<Pos> > winCorridors

Array of win corridors, which can be used for building an heuristic.

Definition at line 67 of file Board.cs.

Property Documentation

◆ this[int row, int col]

Piece? this[int row, int col]
get

Read-only indexer for allowing the board contents to be accessed by external code.

Parameters
rowBoard row to access.
colBoard column to access.
Returns
The piece in the specified board position, or null if no piece is in the given position.
Exceptions
System.IndexOutOfRangeExceptionThrown when the given position is invalid (outside the board).

Definition at line 28 of file Board.cs.

◆ Turn

PColor Turn
getprivate set

Who's turn is it?

The color of the player who's currently playing.

Definition at line 47 of file Board.cs.


The documentation for this class was generated from the following file: