Chess Game  1.1.0
A full chess game for Unity
cgChessBoardScript Class Reference

The script attached to the chessboard prefab, should have gameobjects with squarescripts, this class: verifies if the player can drag and drop pieces, handles whether or not the engine should make move, checks whether or not the game is over(and if so shows the game over prefab), flips the board, resets the board etc. More...

Inherits MonoBehaviour.

Public Types

enum  BoardMode {
  Undefined, PlayerVsPlayer, PlayerVsEngine, EngineVsPlayer,
  EngineVsEngine
}
 All possible board modes. More...
 

Public Member Functions

void start (cgBoard customBoard=null, BoardMode mode=BoardMode.Undefined)
 Start the game, with provided board. More...
 
cgSquareScript [] getSquares ()
 Get all cgSquareScripts. More...
 
void placePieces ()
 Place pieces according to the current state of the underlying abstractboard. More...
 
void ResetBoard ()
 Resets the board, called by the menu button called restart. More...
 
void RevertLastMove ()
 Reverts the last move, called by the menu button called revert last move. More...
 
void MainMenu ()
 Instantiates and shows an instance of MainMenuPrefab. Called by menu button called Main Menu More...
 
void FlipBoard ()
 Flips the board so if white is currently on top, it will be at the bottom. Preferable if playing as black. Called by the menu button called Flip Board. More...
 
void SuggestMove ()
 Use the engine to find a suggested move for the current position. Called by the menu button called Suggest Move. More...
 
void playSound (AudioClip clip)
 Play provided sound, adds an audiosource if one does not exist on this gameobject. More...
 
void MakeEngineMove (cgBoard board, bool MoveAsWhiteP, Action< List< cgSimpleMove >> callback)
 Called when the engine should generate a new move. More...
 
void setBoardTo (cgBoard board)
 Set the board to the provided abstract board, write any moves provided in said abstract board to the log, etc. More...
 

Public Attributes

AudioClip moveSound
 A sound to play whenever a move is made. More...
 
AudioClip checkSound
 A sound to play when any player makes a move that checks the king. More...
 
AudioClip winSound
 A sound to play when the game is won. More...
 
AudioClip loseSound
 A sound to play when the game is lost or drawn. More...
 
int movesMade = 0
 The number of moves made. More...
 
GUIText moveLog
 The textfield to log all moves made. More...
 
GameObject engineProgressBar
 The provided loadbar to display how far the analysis is. More...
 
GameObject flipTarget
 The target to flip when the user click the Flip board button. More...
 
GameObject chessPieceHolder
 The target to flip when the user click the Flip board button. More...
 
GameObject chessSquareHolder
 The target to flip when the user click the Flip board button. More...
 
GameObject GameOverPrefab
 Game over prefab, instantiated when the game is won/drawn/lost More...
 
GameObject MainMenuPrefab
 Main menu prefab, instantiated when the user clicks Main menu button. More...
 
GameObject ChessPiecePrefab
 Main menu prefab, instantiated when the user clicks Main menu button. More...
 
bool whiteTurnToMove = true
 Is it whites turn to move? if false then its blacks turn. More...
 
bool highlightLastMove = true
 Should the last move be highlighted on the board? More...
 
bool highlightLegalMoves = true
 Should the all legal moves be highlighted when the player drags a piece? More...
 
bool displayAs3d = true
 Should the pieces be displayed as 3d pieces? More...
 
BoardMode Mode = BoardMode.PlayerVsEngine
 The current board mode. More...
 
Vector3 blackDeadPiecesLocation = new Vector3(4, -2, 0)
 What location should dead black pieces be placed at? More...
 
Vector3 whiteDeadPiecesLocation = new Vector3(3, -2, 0)
 What location should dead white pieces be placed at? More...
 
cgNotation.NotationType NotationType = cgNotation.NotationType.Algebraic
 Which notationtype should be used to notate the game? More...
 
bool randomizeEarlyEngineMoves = true
 Should the early moves of the engine be randomized slightly to allow for a wide array of variations? More...
 
bool startOnLoad = true
 Should the board start on load, or do you want to manually start the board by called Start? More...
 
byte searchDepthWeak = 4
 What depth should the engine search seemingly weak moves to? The higher the value the better the AI and the longer the load time. More...
 
byte searchDepthStrong = 4
 What depth should the engine search seemingly strong moves to? The higher the value the better the AI and the longer the load time. More...
 

Properties

bool playerCanMove [get]
 Can the player drag and move pieces? Yes if a human controls the current color whoms turn it is to move. More...
 
cgEngine getEngine [get]
 Get the engine. More...
 

Detailed Description

The script attached to the chessboard prefab, should have gameobjects with squarescripts, this class: verifies if the player can drag and drop pieces, handles whether or not the engine should make move, checks whether or not the game is over(and if so shows the game over prefab), flips the board, resets the board etc.

Member Enumeration Documentation

◆ BoardMode

All possible board modes.

Member Function Documentation

◆ FlipBoard()

void cgChessBoardScript.FlipBoard ( )

Flips the board so if white is currently on top, it will be at the bottom. Preferable if playing as black. Called by the menu button called Flip Board.

◆ getSquares()

cgSquareScript [] cgChessBoardScript.getSquares ( )

Get all cgSquareScripts.

Returns
All cgSquareScripts

◆ MainMenu()

void cgChessBoardScript.MainMenu ( )

Instantiates and shows an instance of MainMenuPrefab. Called by menu button called Main Menu

◆ MakeEngineMove()

void cgChessBoardScript.MakeEngineMove ( cgBoard  board,
bool  MoveAsWhiteP,
Action< List< cgSimpleMove >>  callback 
)

Called when the engine should generate a new move.

Parameters
boardThe current board state.
MoveAsWhitePMove as white(true) or black(false).
callbackWhere the prefered move will be returned.

◆ placePieces()

void cgChessBoardScript.placePieces ( )

Place pieces according to the current state of the underlying abstractboard.

◆ playSound()

void cgChessBoardScript.playSound ( AudioClip  clip)

Play provided sound, adds an audiosource if one does not exist on this gameobject.

Parameters
clip

◆ ResetBoard()

void cgChessBoardScript.ResetBoard ( )

Resets the board, called by the menu button called restart.

◆ RevertLastMove()

void cgChessBoardScript.RevertLastMove ( )

Reverts the last move, called by the menu button called revert last move.

◆ setBoardTo()

void cgChessBoardScript.setBoardTo ( cgBoard  board)

Set the board to the provided abstract board, write any moves provided in said abstract board to the log, etc.

Parameters
board

◆ start()

void cgChessBoardScript.start ( cgBoard  customBoard = null,
BoardMode  mode = BoardMode.Undefined 
)

Start the game, with provided board.

Parameters
customBoardThe abstract board that we should match, if none specified we use existing one, if none exists we generate an 8x8 board
modeWhich mode the game is in, player vs player, player vs engine, engine vs engine etc.

◆ SuggestMove()

void cgChessBoardScript.SuggestMove ( )

Use the engine to find a suggested move for the current position. Called by the menu button called Suggest Move.

Member Data Documentation

◆ blackDeadPiecesLocation

Vector3 cgChessBoardScript.blackDeadPiecesLocation = new Vector3(4, -2, 0)

What location should dead black pieces be placed at?

◆ checkSound

AudioClip cgChessBoardScript.checkSound

A sound to play when any player makes a move that checks the king.

◆ chessPieceHolder

GameObject cgChessBoardScript.chessPieceHolder

The target to flip when the user click the Flip board button.

◆ ChessPiecePrefab

GameObject cgChessBoardScript.ChessPiecePrefab

Main menu prefab, instantiated when the user clicks Main menu button.

◆ chessSquareHolder

GameObject cgChessBoardScript.chessSquareHolder

The target to flip when the user click the Flip board button.

◆ displayAs3d

bool cgChessBoardScript.displayAs3d = true

Should the pieces be displayed as 3d pieces?

◆ engineProgressBar

GameObject cgChessBoardScript.engineProgressBar

The provided loadbar to display how far the analysis is.

◆ flipTarget

GameObject cgChessBoardScript.flipTarget

The target to flip when the user click the Flip board button.

◆ GameOverPrefab

GameObject cgChessBoardScript.GameOverPrefab

Game over prefab, instantiated when the game is won/drawn/lost

◆ highlightLastMove

bool cgChessBoardScript.highlightLastMove = true

Should the last move be highlighted on the board?

◆ highlightLegalMoves

bool cgChessBoardScript.highlightLegalMoves = true

Should the all legal moves be highlighted when the player drags a piece?

◆ loseSound

AudioClip cgChessBoardScript.loseSound

A sound to play when the game is lost or drawn.

◆ MainMenuPrefab

GameObject cgChessBoardScript.MainMenuPrefab

Main menu prefab, instantiated when the user clicks Main menu button.

◆ Mode

BoardMode cgChessBoardScript.Mode = BoardMode.PlayerVsEngine

The current board mode.

◆ moveLog

GUIText cgChessBoardScript.moveLog

The textfield to log all moves made.

◆ movesMade

int cgChessBoardScript.movesMade = 0

The number of moves made.

◆ moveSound

AudioClip cgChessBoardScript.moveSound

A sound to play whenever a move is made.

◆ NotationType

cgNotation.NotationType cgChessBoardScript.NotationType = cgNotation.NotationType.Algebraic

Which notationtype should be used to notate the game?

◆ randomizeEarlyEngineMoves

bool cgChessBoardScript.randomizeEarlyEngineMoves = true

Should the early moves of the engine be randomized slightly to allow for a wide array of variations?

◆ searchDepthStrong

byte cgChessBoardScript.searchDepthStrong = 4

What depth should the engine search seemingly strong moves to? The higher the value the better the AI and the longer the load time.

◆ searchDepthWeak

byte cgChessBoardScript.searchDepthWeak = 4

What depth should the engine search seemingly weak moves to? The higher the value the better the AI and the longer the load time.

◆ startOnLoad

bool cgChessBoardScript.startOnLoad = true

Should the board start on load, or do you want to manually start the board by called Start?

◆ whiteDeadPiecesLocation

Vector3 cgChessBoardScript.whiteDeadPiecesLocation = new Vector3(3, -2, 0)

What location should dead white pieces be placed at?

◆ whiteTurnToMove

bool cgChessBoardScript.whiteTurnToMove = true

Is it whites turn to move? if false then its blacks turn.

◆ winSound

AudioClip cgChessBoardScript.winSound

A sound to play when the game is won.

Property Documentation

◆ getEngine

cgEngine cgChessBoardScript.getEngine
get

Get the engine.

◆ playerCanMove

bool cgChessBoardScript.playerCanMove
get

Can the player drag and move pieces? Yes if a human controls the current color whoms turn it is to move.


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