reversi-core
A simple reversi library for C
Loading...
Searching...
No Matches
reversi.h File Reference
#include <stdlib.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define _REV_ENUM(s)   typedef unsigned int s; enum
 
#define REV_VERSION   "0.1.0"
 
#define REV_VERSION_INT   100
 

Typedefs

typedef uint64_t RevBitboard
 Type for a bitboard.
 
typedef enum RevDiskType RevDiskType
 
typedef struct RevBoard RevBoard
 

Enumerations

enum  RevDiskType { DISK_BLACK = 0 , DISK_WHITE , DISK_NONE }
 Color of disk. More...
 

Functions

const char * revGetVersion ()
 Gets the version of reversi-core.
 
int revGetVersionAsInt ()
 Gets the version of reversi-core as an integer.
 
int revCountFirstZeros (RevBitboard b)
 Counts leading zeros of a bitboard.
 
int revCountOnes (RevBitboard b)
 Counts number of positive bits in a bitboard.
 
int revXYToPos (int x, int y)
 Returns x + y * 8.
 
int revIsTrueAt (RevBitboard b, int pos)
 Returns a bit of a bitboard.
 
int revIsTrueAtXY (RevBitboard b, int x, int y)
 Returns a bit of a bitboard.
 
int * revBitboardToArray (RevBitboard b)
 Converts a bitboard to an array of positions.
 
RevBitboard revArrayToBitboard (int *array, int size)
 Creates a bitboard from an array of positions.
 
void revInitGenRandom (uint32_t seed)
 Initialize a random number generator.
 
int revGenIntRandom (int min, int max)
 Generates a random integer with the mersenne twister.
 

Macro Definition Documentation

◆ _REV_ENUM

#define _REV_ENUM (   s)    typedef unsigned int s; enum

◆ REV_VERSION

#define REV_VERSION   "0.1.0"

◆ REV_VERSION_INT

#define REV_VERSION_INT   100

Typedef Documentation

◆ RevBitboard

Type for a bitboard.

It's actually a 64bit uint.

◆ RevBoard

typedef struct RevBoard RevBoard

◆ RevDiskType

typedef enum RevDiskType RevDiskType

Enumeration Type Documentation

◆ RevDiskType

Color of disk.

Enumerator
DISK_BLACK 

Black disk.

DISK_WHITE 

White disk.

DISK_NONE 

Empty.

Function Documentation

◆ revArrayToBitboard()

RevBitboard revArrayToBitboard ( int *  array,
int  size 
)

Creates a bitboard from an array of positions.

Parameters
arrayAn array of positions on a bitboard.
sizeThe size of the array.
Returns
A bitboard.

◆ revBitboardToArray()

int * revBitboardToArray ( RevBitboard  b)

Converts a bitboard to an array of positions.

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

◆ revCountFirstZeros()

int revCountFirstZeros ( RevBitboard  b)

Counts leading zeros of a bitboard.

Note
This method returns 64 when the input is zero.
Parameters
bRevBitboard instance
Returns
Number of leading zeros of a bitboard.

◆ revCountOnes()

int revCountOnes ( RevBitboard  b)

Counts number of positive bits in a bitboard.

Parameters
bRevBitboard instance
Returns
Number of positive bits in a bitboard.

◆ revGenIntRandom()

int revGenIntRandom ( int  min,
int  max 
)

Generates a random integer with the mersenne twister.

Note
This method requires revInitGenRandom() before calling.
Parameters
minThe lowest value to return.
maxThe highest value to return.
Returns
A pseudo random value between min and max.

◆ revGetVersion()

const char * revGetVersion ( )

Gets the version of reversi-core.

It should be of the form x.x.x.

Returns
A string that represents the version.

◆ revGetVersionAsInt()

int revGetVersionAsInt ( )

Gets the version of reversi-core as an integer.

The value should be major * 100 + minor * 100 + patch. If revGetVersion() == "1.2.3" then revGetVersionAsInt() == 10203.

Returns
An integer that represents the version.

◆ revInitGenRandom()

void revInitGenRandom ( uint32_t  seed)

Initialize a random number generator.

Parameters
seedseed of a random number generator.

◆ revIsTrueAt()

int revIsTrueAt ( RevBitboard  b,
int  pos 
)

Returns a bit of a bitboard.

Parameters
bRevBitboard instance
posa position on a bitboard. pos = x + y * 8
Returns
A bit of a bitboard.

◆ revIsTrueAtXY()

int revIsTrueAtXY ( RevBitboard  b,
int  x,
int  y 
)

Returns a bit of a bitboard.

Parameters
bRevBitboard instance
xx-coordinate on a board.
yy-coordinate on a board.
Returns
A bit of a bitboard.

◆ revXYToPos()

int revXYToPos ( int  x,
int  y 
)

Returns x + y * 8.

Parameters
xx-coordinate on a board.
yy-coordinate on a board.
Returns
a position on a bitboard.