rsmc
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (c) 2026 01eksa
3
10#ifndef RSMC_CORE_H
11#define RSMC_CORE_H
12
13#include "version.h"
14
15#include <assert.h>
16#include <stdbool.h>
17#include <stdint.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23typedef uint32_t RsmcVersion;
24static inline RsmcVersion rsmc_build_version(void)
25{
26 const RsmcVersion version = 0;
27 static_assert((RSMC_VERSION_MAJOR & 0xFF) == RSMC_VERSION_MAJOR, "Major version out of range");
28 static_assert((RSMC_VERSION_MINOR & 0xFF) == RSMC_VERSION_MINOR, "Minor version out of range");
29 static_assert((RSMC_VERSION_PATCH & 0xFFFF) == RSMC_VERSION_PATCH, "Patch version out of range");
30 return version | RSMC_VERSION_PATCH | (RSMC_VERSION_MINOR << 16) | (RSMC_VERSION_MAJOR << 24);
31}
32
33// enums
34
35enum {
65};
66
70typedef uint8_t RsmcPlayer;
71enum {
75};
82static inline bool rsmc_player_is_valid(const RsmcPlayer player)
83{
84 return player < RsmcPlayerCount;
85}
86
90typedef uint8_t RsmcGameStatus;
91enum {
97};
104static inline bool rsmc_game_status_is_valid(const RsmcGameStatus status)
105{
106 return status < RsmcGameStatusCount;
107}
108
109// structs
110
114typedef uint8_t RsmcPlayerScore;
122static_assert(sizeof(RsmcPlayersScore) == sizeof(RsmcPlayerScore) * 2, "unexpected padding in RsmcPlayersScore");
123
131static_assert(sizeof(RsmcGameState) == 3, "unexpected padding in RsmcGameState");
132
133typedef uint64_t RsmcBitMap;
134typedef uint64_t RsmcBitMask;
135
139typedef struct {
140 union {
141 struct {
144 };
145 RsmcBitMap by_player[2];
146 };
147} RsmcBoard;
148static_assert(sizeof(RsmcBoard) == sizeof(uint64_t) * 2, "unexpected padding in RsmcBoard");
149
150#ifdef __cplusplus
151}
152#endif
153
154#endif // RSMC_CORE_H
uint8_t RsmcPlayer
Player's color.
Definition core.h:70
uint64_t RsmcBitMask
Definition core.h:134
uint64_t RsmcBitMap
Definition core.h:133
uint8_t RsmcPlayerScore
Definition core.h:114
@ RsmcPlayerCount
Definition core.h:74
@ RsmcPlayerWhite
Definition core.h:73
@ RsmcPlayerBlack
Definition core.h:72
uint32_t RsmcVersion
Definition core.h:23
@ RsmcGameStatusContinue
Definition core.h:92
@ RsmcGameStatusWhiteWin
Definition core.h:95
@ RsmcGameStatusBlackWin
Definition core.h:94
@ RsmcGameStatusDraw
Definition core.h:93
@ RsmcGameStatusCount
Definition core.h:96
uint8_t RsmcGameStatus
Game status (continue, draw, black win, white win).
Definition core.h:90
@ RsmcMinCoord
Minimal possible value for index on the 2-dimensional board.
Definition core.h:47
@ RsmcMaxCoord
Maximal possible value for index on the 2-dimensional board.
Definition core.h:51
@ RsmcMaxCellIndex
Maximal possible value for index on the 1-dimensional board.
Definition core.h:59
@ RsmcMaxValidMoves
Maximal possible count of valid moves. Proven by Takizawa, Hiroki in 2023.
Definition core.h:64
@ RsmcBoardArea
Count of cells on the board.
Definition core.h:43
@ RsmcBoardSize
Size of one side of the board.
Definition core.h:39
@ RsmcMinCellIndex
Minimal possible value for index on the 1-dimensional board.
Definition core.h:55
Stores board as two RsmcBitMap for each player pieces.
Definition core.h:139
RsmcBitMap black
Definition core.h:142
RsmcBitMap white
Definition core.h:143
Stores score for both players and game status.
Definition core.h:127
RsmcPlayersScore score
Definition core.h:128
RsmcGameStatus game_status
Definition core.h:129
Stores score fot both players.
Definition core.h:118
RsmcPlayerScore white_score
Definition core.h:120
RsmcPlayerScore black_score
Definition core.h:119
Macros for rsmc version.
#define RSMC_VERSION_PATCH
Definition version.h:16
#define RSMC_VERSION_MAJOR
Definition version.h:14
#define RSMC_VERSION_MINOR
Definition version.h:15