reversi-core
A simple reversi library for C
Loading...
Searching...
No Matches
RevBoard Struct Reference

Class for a reversi board. More...

#include <reversi.h>

Public Member Functions

RevBoardrevNewBoard ()
 Creates a new board.
 
void revFreeBoard (RevBoard *board)
 Frees the memory of a board object.
 
void revInitBoard (RevBoard *board)
 Initializes a board with the fixed four disks.
 
void revCopyBoard (RevBoard *src, RevBoard *trg)
 Deep copy for board objects.
 
RevDiskType revGetCurrentPlayer (RevBoard *board)
 Gets the current player.
 
RevBitboard revGetBitboard (RevBoard *board, RevDiskType disk_type)
 Gets a bitboard of a player.
 
void revSetBitboard (RevBoard *board, RevDiskType disk_type, RevBitboard b)
 Sets a bitboard of a player.
 
int * revGetBitboardAsArray (RevBoard *board, RevDiskType disk_type)
 Gets a bitboard as an array of positions on a bitboard.
 
int revCountDisks (RevBoard *board, RevDiskType disk_type)
 Gets the number of disks on a board for a player.
 
RevDiskType revGetWinner (RevBoard *board)
 Returns which player has more disks on a board.
 
void revSetDisk (RevBoard *board, RevDiskType disk_type, int pos)
 Sets a disk on a board.
 
void revSetDiskXY (RevBoard *board, RevDiskType disk_type, int x, int y)
 Sets a disk on a board.
 
RevDiskType revGetDisk (RevBoard *board, int pos)
 Gets a disk on a board.
 
RevDiskType revGetDiskXY (RevBoard *board, int x, int y)
 Gets a disk on a board.
 
RevBitboard revGetMobility (RevBoard *board)
 Gets mobility of the current player as a bitboard.
 
int * revGetMobilityAsArray (RevBoard *board)
 Gets mobility of the current player as an array of integers.
 
int revGetMobilityCount (RevBoard *board)
 Gets the number of legal moves for the current player.
 
int revHasLegalMoves (RevBoard *board)
 Returns whether or not the current player has legal moves.
 
int revIsLegalMove (RevBoard *board, int pos)
 Returns whether or not a move is legal.
 
int revIsLegalMoveXY (RevBoard *board, int x, int y)
 Returns whether or not a move is legal.
 
void revPrintBoard (RevBoard *board)
 Outputs a board to stdout.
 
void revPrintBoardWithMobility (RevBoard *board)
 Outputs a board with mobility to stdout.
 
void revUpdateMobility (RevBoard *board)
 Calculates mobility of the current player.
 
void revChangePlayer (RevBoard *board)
 Changes the current player to the opposite player.
 
RevBitboard revMove (RevBoard *board, int pos)
 Flips disks, changes the current player, and calculates mobility.
 
RevBitboard revMoveXY (RevBoard *board, int x, int y)
 Flips disks, changes the current player, and calculates mobility.
 
int revGenMoveRandom (RevBoard *board)
 Generates a random move.
 
void revMoveRandomToEnd (RevBoard *board)
 Plays the game to the end randomly.
 
int revGenMoveMonteCarlo (RevBoard *board, int trials)
 Calls revMoveRandomToEnd() many times for each legal move, and returns the best move that has the highest win rate.
 

Detailed Description

Class for a reversi board.

Member Function Documentation

◆ revChangePlayer()

void revChangePlayer ( RevBoard board)

Changes the current player to the opposite player.

Note
revMove() and revMoveXY() call this method internally.
Parameters
boardRevBoard instance

◆ revCopyBoard()

void revCopyBoard ( RevBoard src,
RevBoard trg 
)

Deep copy for board objects.

It copies a board src to another board trg.

◆ revCountDisks()

int revCountDisks ( RevBoard board,
RevDiskType  disk_type 
)

Gets the number of disks on a board for a player.

Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
Returns
Number of disks.

◆ revFreeBoard()

void revFreeBoard ( RevBoard board)

Frees the memory of a board object.

Note
Every time a board is returned from revNewBoard(), this method should be called.
Parameters
boardThe board to free memory

◆ revGenMoveMonteCarlo()

int revGenMoveMonteCarlo ( RevBoard board,
int  trials 
)

Calls revMoveRandomToEnd() many times for each legal move, and returns the best move that has the highest win rate.

Note
This method requires revInitGenRandom() before calling.
Warning
This is the Monte Carlo Search, not MCTS.
Parameters
boardRevBoard instance
trialsHow many times this function plays the game from the current state to the end.
Returns
a position on a bitboard.

◆ revGenMoveRandom()

int revGenMoveRandom ( RevBoard board)

Generates a random move.

Note
This method requires revInitGenRandom() before calling.
Parameters
boardRevBoard instance
Returns
a position on a bitboard.

◆ revGetBitboard()

RevBitboard revGetBitboard ( RevBoard board,
RevDiskType  disk_type 
)

Gets a bitboard of a player.

Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
Returns
a bitboard of a player

◆ revGetBitboardAsArray()

int * revGetBitboardAsArray ( RevBoard board,
RevDiskType  disk_type 
)

Gets a bitboard as an array of positions on a bitboard.

Note
Arrays that are returned from this method should be freed with free().
Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
Returns
An array of integers. The size of the array is equal to revCountDisks().

◆ revGetCurrentPlayer()

RevDiskType revGetCurrentPlayer ( RevBoard board)

Gets the current player.

Parameters
boardRevBoard instance
Returns
RevDiskType of the current player

◆ revGetDisk()

RevDiskType revGetDisk ( RevBoard board,
int  pos 
)

Gets a disk on a board.

Parameters
boardRevBoard instance
posa position on a bitboard. pos = x + y * 8
Returns
DISK_BLACK, DISK_WHITE or DISK_NONE

◆ revGetDiskXY()

RevDiskType revGetDiskXY ( RevBoard board,
int  x,
int  y 
)

Gets a disk on a board.

Parameters
boardRevBoard instance
xx-coordinate on a board.
yy-coordinate on a board.
Returns
DISK_BLACK, DISK_WHITE or DISK_NONE

◆ revGetMobility()

RevBitboard revGetMobility ( RevBoard board)

Gets mobility of the current player as a bitboard.

Parameters
boardRevBoard instance
Returns
Mobility as a bitboard

◆ revGetMobilityAsArray()

int * revGetMobilityAsArray ( RevBoard board)

Gets mobility of the current player as an array of integers.

Note
Arrays that are returned from this method should be freed with free().
Parameters
boardRevBoard instance
Returns
An array of positions on a bitboard. The size of the array is equal to revGetMobilityCount().

◆ revGetMobilityCount()

int revGetMobilityCount ( RevBoard board)

Gets the number of legal moves for the current player.

Parameters
boardRevBoard instance
Returns
Number of legal moves.

◆ revGetWinner()

RevDiskType revGetWinner ( RevBoard board)

Returns which player has more disks on a board.

Parameters
boardRevBoard instance
Returns
DISK_BLACK, DISK_WHITE, or DISK_NONE

◆ revHasLegalMoves()

int revHasLegalMoves ( RevBoard board)

Returns whether or not the current player has legal moves.

Parameters
boardRevBoard instance
Returns
TRUE if the current player has legal moves, FALSE otherwise.

◆ revInitBoard()

void revInitBoard ( RevBoard board)

Initializes a board with the fixed four disks.

Note
This method is not required. revNewBoard() calls it.
Parameters
boardRevBoard instance

◆ revIsLegalMove()

int revIsLegalMove ( RevBoard board,
int  pos 
)

Returns whether or not a move is legal.

Parameters
boardRevBoard instance
posa position on a bitboard. pos = x + y * 8
Returns
TRUE if the move is legal, FALSE otherwise.

◆ revIsLegalMoveXY()

int revIsLegalMoveXY ( RevBoard board,
int  x,
int  y 
)

Returns whether or not a move is legal.

Parameters
boardRevBoard instance
xx-coordinate on a board.
yy-coordinate on a board.
Returns
TRUE if the move is legal, FALSE otherwise.

◆ revMove()

RevBitboard revMove ( RevBoard board,
int  pos 
)

Flips disks, changes the current player, and calculates mobility.

Parameters
boardRevBoard instance
posa position on a bitboard. pos = x + y * 8
Returns
a bitboard that represents flipped disks.

◆ revMoveRandomToEnd()

void revMoveRandomToEnd ( RevBoard board)

Plays the game to the end randomly.

Note
This method requires revInitGenRandom() before calling.
Parameters
boardRevBoard instance

◆ revMoveXY()

RevBitboard revMoveXY ( RevBoard board,
int  x,
int  y 
)

Flips disks, changes the current player, and calculates mobility.

Parameters
boardRevBoard instance
xx-coordinate on a board.
yy-coordinate on a board.
Returns
a bitboard that represents flipped disks.

◆ revNewBoard()

RevBoard * revNewBoard ( )

Creates a new board.

◆ revPrintBoard()

void revPrintBoard ( RevBoard board)

Outputs a board to stdout.

Parameters
boardRevBoard instance

◆ revPrintBoardWithMobility()

void revPrintBoardWithMobility ( RevBoard board)

Outputs a board with mobility to stdout.

Parameters
boardRevBoard instance

◆ revSetBitboard()

void revSetBitboard ( RevBoard board,
RevDiskType  disk_type,
RevBitboard  b 
)

Sets a bitboard of a player.

Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
ba new bitboard

◆ revSetDisk()

void revSetDisk ( RevBoard board,
RevDiskType  disk_type,
int  pos 
)

Sets a disk on a board.

Note
This method does NOT flip disks.
Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
posa position on a bitboard. pos = x + y * 8

◆ revSetDiskXY()

void revSetDiskXY ( RevBoard board,
RevDiskType  disk_type,
int  x,
int  y 
)

Sets a disk on a board.

Note
This method does NOT flip disks.
Parameters
boardRevBoard instance
disk_typeDISK_BLACK or DISK_WHITE
xx-coordinate on a board.
yy-coordinate on a board.

◆ revUpdateMobility()

void revUpdateMobility ( RevBoard board)

Calculates mobility of the current player.

You should call this method after editing bitboards. You can get the result with revGetMobility() or revGetMobilityAsArray().

Note
revMove(), revMoveXY(), and revChangePlayer() call this method internally.
Parameters
boardRevBoard instance

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