reversi-core
A simple reversi library for C
Loading...
Searching...
No Matches
reversi.h
Go to the documentation of this file.
1#ifndef __REVERSI_INCLUDE_REVERSI_H__
2#define __REVERSI_INCLUDE_REVERSI_H__
3#include <stdlib.h>
4#include <stdint.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#ifndef _REV_EXTERN
11#ifdef _WIN32
12#define _REV_EXTERN __declspec(dllexport) extern
13#else
14#define _REV_EXTERN __attribute__((visibility("default"))) extern
15#endif
16#endif
17
18#define _REV_ENUM(s) typedef unsigned int s; enum
19
20// Version info
21#define REV_VERSION "0.1.0"
22#define REV_VERSION_INT 100
23
30_REV_EXTERN const char* revGetVersion();
31
39_REV_EXTERN int revGetVersionAsInt();
40
46typedef uint64_t RevBitboard;
47
57
64_REV_EXTERN int revCountOnes(RevBitboard b);
65
73_REV_EXTERN int revXYToPos(int x, int y);
74
82_REV_EXTERN int revIsTrueAt(RevBitboard b, int pos);
83
92_REV_EXTERN int revIsTrueAtXY(RevBitboard b, int x, int y);
93
102_REV_EXTERN int* revBitboardToArray(RevBitboard b);
103
110_REV_EXTERN RevBitboard revArrayToBitboard(int *array, int size);
111
121};
122
128typedef struct RevBoard RevBoard;
129
135_REV_EXTERN RevBoard *revNewBoard();
136
145_REV_EXTERN void revFreeBoard(RevBoard *board);
146
155_REV_EXTERN void revInitBoard(RevBoard *board);
156
163_REV_EXTERN void revCopyBoard(RevBoard *src, RevBoard *trg);
164
173
182_REV_EXTERN RevBitboard revGetBitboard(RevBoard *board, RevDiskType disk_type);
183
192_REV_EXTERN void revSetBitboard(RevBoard *board, RevDiskType disk_type, RevBitboard b);
193
204_REV_EXTERN int *revGetBitboardAsArray(RevBoard *board, RevDiskType disk_type);
205
214_REV_EXTERN int revCountDisks(RevBoard *board, RevDiskType disk_type);
215
224
235_REV_EXTERN void revSetDisk(RevBoard *board, RevDiskType disk_type, int pos);
236
248_REV_EXTERN void revSetDiskXY(RevBoard *board, RevDiskType disk_type, int x, int y);
249
258_REV_EXTERN RevDiskType revGetDisk(RevBoard *board, int pos);
259
269_REV_EXTERN RevDiskType revGetDiskXY(RevBoard *board, int x, int y);
270
279
289_REV_EXTERN int *revGetMobilityAsArray(RevBoard *board);
290
298_REV_EXTERN int revGetMobilityCount(RevBoard *board);
299
307_REV_EXTERN int revHasLegalMoves(RevBoard *board);
308
317_REV_EXTERN int revIsLegalMove(RevBoard *board, int pos);
318
328_REV_EXTERN int revIsLegalMoveXY(RevBoard *board, int x, int y);
329
336_REV_EXTERN void revPrintBoard(RevBoard *board);
337
344_REV_EXTERN void revPrintBoardWithMobility(RevBoard *board);
345
356_REV_EXTERN void revUpdateMobility(RevBoard *board);
357
366_REV_EXTERN void revChangePlayer(RevBoard *board);
367
376_REV_EXTERN RevBitboard revMove(RevBoard *board, int pos);
377
387_REV_EXTERN RevBitboard revMoveXY(RevBoard *board, int x, int y);
388
394_REV_EXTERN void revInitGenRandom(uint32_t seed);
395
406_REV_EXTERN int revGenIntRandom(int min, int max);
407
417_REV_EXTERN int revGenMoveRandom(RevBoard *board);
418
427_REV_EXTERN void revMoveRandomToEnd(RevBoard *board);
428
441_REV_EXTERN int revGenMoveMonteCarlo(RevBoard *board, int trials);
442
443#ifdef __cplusplus
444}
445#endif
446
447#endif // __REVERSI_INCLUDE_REVERSI_H__
int revXYToPos(int x, int y)
Returns x + y * 8.
void revInitGenRandom(uint32_t seed)
Initialize a random number generator.
int revCountOnes(RevBitboard b)
Counts number of positive bits in a bitboard.
int revGetVersionAsInt()
Gets the version of reversi-core as an integer.
#define _REV_ENUM(s)
Definition: reversi.h:18
uint64_t RevBitboard
Type for a bitboard.
Definition: reversi.h:46
const char * revGetVersion()
Gets the version of reversi-core.
int revIsTrueAt(RevBitboard b, int pos)
Returns a bit of a bitboard.
int * revBitboardToArray(RevBitboard b)
Converts a bitboard to an array of positions.
RevDiskType
Color of disk.
Definition: reversi.h:117
@ DISK_BLACK
Black disk.
Definition: reversi.h:118
@ DISK_WHITE
White disk.
Definition: reversi.h:119
@ DISK_NONE
Empty.
Definition: reversi.h:120
int revIsTrueAtXY(RevBitboard b, int x, int y)
Returns a bit of a bitboard.
int revCountFirstZeros(RevBitboard b)
Counts leading zeros of a bitboard.
int revGenIntRandom(int min, int max)
Generates a random integer with the mersenne twister.
RevBitboard revArrayToBitboard(int *array, int size)
Creates a bitboard from an array of positions.
Class for a reversi board.
void revMoveRandomToEnd(RevBoard *board)
Plays the game to the end randomly.
RevBitboard revMoveXY(RevBoard *board, int x, int y)
Flips disks, changes the current player, and calculates mobility.
void revFreeBoard(RevBoard *board)
Frees the memory of a board object.
void revSetDiskXY(RevBoard *board, RevDiskType disk_type, int x, int y)
Sets a disk on a board.
int revCountDisks(RevBoard *board, RevDiskType disk_type)
Gets the number of disks on a board for a player.
void revPrintBoard(RevBoard *board)
Outputs a board to stdout.
RevDiskType revGetDisk(RevBoard *board, int pos)
Gets a disk on a board.
int revGetMobilityCount(RevBoard *board)
Gets the number of legal moves for the current player.
void revPrintBoardWithMobility(RevBoard *board)
Outputs a board with mobility to stdout.
void revChangePlayer(RevBoard *board)
Changes the current player to the opposite player.
int revIsLegalMove(RevBoard *board, int pos)
Returns whether or not a move is legal.
void revUpdateMobility(RevBoard *board)
Calculates mobility of the current player.
RevBitboard revGetBitboard(RevBoard *board, RevDiskType disk_type)
Gets a bitboard of a player.
void revCopyBoard(RevBoard *src, RevBoard *trg)
Deep copy for board objects.
int * revGetBitboardAsArray(RevBoard *board, RevDiskType disk_type)
Gets a bitboard as an array of positions on a bitboard.
RevDiskType revGetWinner(RevBoard *board)
Returns which player has more disks on a board.
void revInitBoard(RevBoard *board)
Initializes a board with the fixed four disks.
int revGenMoveRandom(RevBoard *board)
Generates a random move.
int * revGetMobilityAsArray(RevBoard *board)
Gets mobility of the current player as an array of integers.
int revHasLegalMoves(RevBoard *board)
Returns whether or not the current player has legal moves.
void revSetBitboard(RevBoard *board, RevDiskType disk_type, RevBitboard b)
Sets a bitboard of a player.
RevBitboard revMove(RevBoard *board, int pos)
Flips disks, changes the current player, and calculates mobility.
int revIsLegalMoveXY(RevBoard *board, int x, int y)
Returns whether or not a move is legal.
void revSetDisk(RevBoard *board, RevDiskType disk_type, int pos)
Sets a disk on a board.
RevBoard * revNewBoard()
Creates a new 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 revGenMoveMonteCarlo(RevBoard *board, int trials)
Calls revMoveRandomToEnd() many times for each legal move, and returns the best move that has the hig...
RevDiskType revGetCurrentPlayer(RevBoard *board)
Gets the current player.