Skip to content

Commit

Permalink
fix: bump build version, fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Aug 2, 2024
1 parent c5f522b commit 5710cd8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- develop

env:
firmware_version: '0.101.2'
firmware_version: '0.104.0'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+'

env:
firmware_version: '0.101.2'
firmware_version: '0.104.0'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![FLIPR](https://github.com/xtruan/flipper-chess/blob/main/icons/FLIPR_128x64.png)

## Chess game for Flipper Zero
- Built against `0.101.2` Flipper Zero firmware release
- Built against `0.104.0` Flipper Zero firmware release
- Uses [smallchesslib](https://codeberg.org/drummyfish/smallchesslib)

### Installation
Expand Down
144 changes: 85 additions & 59 deletions chess/smallchesslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
board).
*/
#define SCL_CHESS_PIECE_MAX_MOVES 25
#define SCL_BOARD_SQUARES 64
#define SCL_BOARD_SQUARES 64

typedef uint8_t (*SCL_RandomFunction)(void);

#if SCL_COUNT_EVALUATED_POSITIONS
#if defined(SCL_COUNT_EVALUATED_POSITIONS) && SCL_COUNT_EVALUATED_POSITIONS
uint32_t SCL_positionsEvaluated = 0; /**< If enabled by
SCL_COUNT_EVALUATED_POSITIONS, this
will increment with every
Expand Down Expand Up @@ -119,8 +119,7 @@ void SCL_randomBetterSeed(uint16_t seed);
*/
typedef uint8_t SCL_SquareSet[8];

#define SCL_SQUARE_SET_EMPTY \
{ 0, 0, 0, 0, 0, 0, 0, 0 }
#define SCL_SQUARE_SET_EMPTY {0, 0, 0, 0, 0, 0, 0, 0}

void SCL_squareSetClear(SCL_SquareSet squareSet);
void SCL_squareSetAdd(SCL_SquareSet squareSet, uint8_t square);
Expand Down Expand Up @@ -211,23 +210,35 @@ uint8_t SCL_squareSetGetRandom(const SCL_SquareSet squareSet, SCL_RandomFunction
typedef char SCL_Board[SCL_BOARD_STATE_SIZE];

#define SCL_BOARD_ENPASSANT_CASTLE_BYTE 64
#define SCL_BOARD_PLY_BYTE 65
#define SCL_BOARD_MOVE_COUNT_BYTE 66
#define SCL_BOARD_EXTRA_BYTE 67
#define SCL_BOARD_PLY_BYTE 65
#define SCL_BOARD_MOVE_COUNT_BYTE 66
#define SCL_BOARD_EXTRA_BYTE 67

#if SCL_960_CASTLING
#define _SCL_EXTRA_BYTE_VALUE (0 | (7 << 3)) // rooks on classic positions
#else
#define _SCL_EXTRA_BYTE_VALUE 0
#endif

#define SCL_BOARD_START_STATE \
{ \
82, 78, 66, 81, 75, 66, 78, 82, 80, 80, 80, 80, 80, 80, 80, 80, 46, 46, 46, 46, 46, 46, \
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, \
46, 46, 46, 46, 46, 112, 112, 112, 112, 112, 112, 112, 112, 114, 110, 98, 113, 107, \
98, 110, 114, (char)0xff, 0, 0, _SCL_EXTRA_BYTE_VALUE, 0 \
}
#define SCL_BOARD_START_STATE \
{82, 78, 66, 81, \
75, 66, 78, 82, \
80, 80, 80, 80, \
80, 80, 80, 80, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
46, 46, 46, 46, \
112, 112, 112, 112, \
112, 112, 112, 112, \
114, 110, 98, 113, \
107, 98, 110, 114, \
(char)0xff, 0, 0, _SCL_EXTRA_BYTE_VALUE, \
0}

#define SCL_FEN_START "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"

Expand All @@ -254,22 +265,22 @@ typedef struct {
en passant */
} SCL_MoveUndo;

#define SCL_GAME_STATE_PLAYING 0x00
#define SCL_GAME_STATE_WHITE_WIN 0x01
#define SCL_GAME_STATE_BLACK_WIN 0x02
#define SCL_GAME_STATE_DRAW 0x10 ///< further unspecified draw
#define SCL_GAME_STATE_DRAW_STALEMATE 0x11 ///< draw by stalemate
#define SCL_GAME_STATE_PLAYING 0x00
#define SCL_GAME_STATE_WHITE_WIN 0x01
#define SCL_GAME_STATE_BLACK_WIN 0x02
#define SCL_GAME_STATE_DRAW 0x10 ///< further unspecified draw
#define SCL_GAME_STATE_DRAW_STALEMATE 0x11 ///< draw by stalemate
#define SCL_GAME_STATE_DRAW_REPETITION 0x12 ///< draw by repetition
#define SCL_GAME_STATE_DRAW_50 0x13 ///< draw by 50 move rule
#define SCL_GAME_STATE_DRAW_DEAD 0x14 ///< draw by dead position
#define SCL_GAME_STATE_END 0xff ///< end without known result
#define SCL_GAME_STATE_DRAW_50 0x13 ///< draw by 50 move rule
#define SCL_GAME_STATE_DRAW_DEAD 0x14 ///< draw by dead position
#define SCL_GAME_STATE_END 0xff ///< end without known result

/**
Converts square in common notation (e.g. 'c' 8) to square number. Only accepts
lowercase column.
*/
#define SCL_SQUARE(colChar, rowInt) (((rowInt)-1) * 8 + ((colChar) - 'a'))
#define SCL_S(c, r) SCL_SQUARE(c, r)
#define SCL_SQUARE(colChar, rowInt) (((rowInt) - 1) * 8 + ((colChar) - 'a'))
#define SCL_S(c, r) SCL_SQUARE(c, r)

void SCL_boardInit(SCL_Board board);
void SCL_boardCopy(const SCL_Board boardFrom, SCL_Board boardTo);
Expand Down Expand Up @@ -412,11 +423,11 @@ uint8_t SCL_boardMoveIsLegal(SCL_Board board, uint8_t squareFrom, uint8_t square
*/
uint8_t SCL_boardMovePossible(SCL_Board board);

#define SCL_POSITION_NORMAL 0x00
#define SCL_POSITION_CHECK 0x01
#define SCL_POSITION_MATE 0x02
#define SCL_POSITION_NORMAL 0x00
#define SCL_POSITION_CHECK 0x01
#define SCL_POSITION_MATE 0x02
#define SCL_POSITION_STALEMATE 0x03
#define SCL_POSITION_DEAD 0x04
#define SCL_POSITION_DEAD 0x04

uint8_t SCL_boardGetPosition(SCL_Board board);

Expand Down Expand Up @@ -513,10 +524,10 @@ static inline uint8_t SCL_coordsToSquare(uint8_t row, uint8_t column);
*/
typedef uint8_t SCL_Record[SCL_RECORD_MAX_SIZE];

#define SCL_RECORD_CONT 0x00
#define SCL_RECORD_CONT 0x00
#define SCL_RECORD_W_WIN 0x40
#define SCL_RECORD_B_WIN 0x80
#define SCL_RECORD_END 0xc0
#define SCL_RECORD_END 0xc0

#define SCL_RECORD_PROM_Q 0x00
#define SCL_RECORD_PROM_R 0x40
Expand Down Expand Up @@ -626,10 +637,10 @@ void SCL_recordApply(const SCL_Record r, SCL_Board b, uint16_t moves);
int16_t SCL_pieceValue(char piece);
int16_t SCL_pieceValuePositive(char piece);

#define SCL_PRINT_FORMAT_NONE 0
#define SCL_PRINT_FORMAT_NORMAL 1
#define SCL_PRINT_FORMAT_COMPACT 2
#define SCL_PRINT_FORMAT_UTF8 3
#define SCL_PRINT_FORMAT_NONE 0
#define SCL_PRINT_FORMAT_NORMAL 1
#define SCL_PRINT_FORMAT_COMPACT 2
#define SCL_PRINT_FORMAT_UTF8 3
#define SCL_PRINT_FORMAT_COMPACT_UTF8 4

/**
Expand Down Expand Up @@ -764,7 +775,8 @@ void SCL_randomBetterSeed(uint16_t seed) {
}

void SCL_squareSetClear(SCL_SquareSet squareSet) {
for(uint8_t i = 0; i < 8; ++i) squareSet[i] = 0;
for(uint8_t i = 0; i < 8; ++i)
squareSet[i] = 0;
}

uint8_t SCL_stringToSquare(const char* square) {
Expand Down Expand Up @@ -877,7 +889,8 @@ void SCL_boardInit(SCL_Board board) {
*b2 = 'p';
}

for(uint8_t i = 0; i < 32; ++i, b++) *b = '.';
for(uint8_t i = 0; i < 32; ++i, b++)
*b = '.';

b += 8;

Expand All @@ -898,7 +911,8 @@ void SCL_boardInit(SCL_Board board) {
*b = 'r';
b++;

for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE - SCL_BOARD_SQUARES; ++i, ++b) *b = 0;
for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE - SCL_BOARD_SQUARES; ++i, ++b)
*b = 0;

board[SCL_BOARD_ENPASSANT_CASTLE_BYTE] = (char)0xff;

Expand Down Expand Up @@ -970,7 +984,8 @@ void SCL_boardInit960(SCL_Board board, uint16_t positionNumber) {

_SCL_boardPlaceOnNthAvailable(board, 0, rooks == 2 ? 'N' : 'R');

for(uint8_t i = 0; i < 8; ++i) board[56 + i] = SCL_pieceToColor(board[i], 0);
for(uint8_t i = 0; i < 8; ++i)
board[56 + i] = SCL_pieceToColor(board[i], 0);

#if SCL_960_CASTLING
_SCL_board960RememberRookPositions(board);
Expand Down Expand Up @@ -1048,7 +1063,8 @@ void SCL_recordFromPGN(SCL_Record r, const char* pgn) {

uint8_t ranks = 0, files = 0;

for(uint8_t i = 0; i < 4; ++i) coords[i] = -1;
for(uint8_t i = 0; i < 4; ++i)
coords[i] = -1;

while(*pgn != ' ' && *pgn != '\n' && *pgn != '\t' && *pgn != '{' && *pgn != 0) {
if(*pgn == '=') promotion = 1;
Expand Down Expand Up @@ -1129,7 +1145,8 @@ void SCL_recordFromPGN(SCL_Record r, const char* pgn) {

while(*pgn == ' ' || *pgn == '\n' || *pgn == '\t' || *pgn == '{') {
if(*pgn == '{')
while(*pgn != '}') pgn++;
while(*pgn != '}')
pgn++;

pgn++;
}
Expand Down Expand Up @@ -1159,7 +1176,8 @@ uint16_t SCL_recordLength(const SCL_Record r) {

uint16_t result = 0;

while((r[result] & 0xc0) == 0) result += 2;
while((r[result] & 0xc0) == 0)
result += 2;

return (result / 2) + 1;
}
Expand Down Expand Up @@ -1565,7 +1583,8 @@ uint8_t SCL_squareSetGetRandom(const SCL_SquareSet squareSet, SCL_RandomFunction
}

void SCL_boardCopy(const SCL_Board boardFrom, SCL_Board boardTo) {
for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE; ++i) boardTo[i] = boardFrom[i];
for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE; ++i)
boardTo[i] = boardFrom[i];
}

uint8_t SCL_boardSquareAttacked(SCL_Board board, uint8_t square, uint8_t byWhite) {
Expand Down Expand Up @@ -1965,7 +1984,8 @@ void SCL_boardGetMoves(SCL_Board board, uint8_t pieceSquare, SCL_SquareSet resul

SCL_squareSetClear(allMoves);

for(uint8_t i = 0; i < 8; ++i) result[i] = 0;
for(uint8_t i = 0; i < 8; ++i)
result[i] = 0;

SCL_boardGetPseudoMoves(board, pieceSquare, 1, allMoves);

Expand Down Expand Up @@ -2125,7 +2145,8 @@ void SCL_printBoard(
uint8_t labels,
uint8_t blackDown) {
if(labels) {
for(uint8_t i = 0; i < offset + 2; ++i) putCharFunc(' ');
for(uint8_t i = 0; i < offset + 2; ++i)
putCharFunc(' ');

for(uint8_t i = 0; i < 8; ++i) {
if((format != SCL_PRINT_FORMAT_COMPACT) && (format != SCL_PRINT_FORMAT_COMPACT_UTF8))
Expand All @@ -2146,7 +2167,8 @@ void SCL_printBoard(
}

for(int8_t row = 0; row < 8; ++row) {
for(uint8_t j = 0; j < offset; ++j) putCharFunc(' ');
for(uint8_t j = 0; j < offset; ++j)
putCharFunc(' ');

if(labels) {
putCharFunc(!blackDown ? ('8' - row) : ('1' + row));
Expand Down Expand Up @@ -2306,16 +2328,16 @@ int16_t SCL_pieceValue(char piece) {
return 0;
}

#define ATTACK_BONUS 3
#define MOBILITY_BONUS 10
#define CENTER_BONUS 7
#define CHECK_BONUS 5
#define KING_CASTLED_BONUS 30
#define KING_BACK_BONUS 15
#define ATTACK_BONUS 3
#define MOBILITY_BONUS 10
#define CENTER_BONUS 7
#define CHECK_BONUS 5
#define KING_CASTLED_BONUS 30
#define KING_BACK_BONUS 15
#define KING_NOT_CENTER_BONUS 15
#define PAWN_NON_DOUBLE_BONUS 3
#define PAWN_PAIR_BONUS 3
#define KING_CENTERNESS 10
#define PAWN_PAIR_BONUS 3
#define KING_CENTERNESS 10

int16_t _SCL_rateKingEndgamePosition(uint8_t position) {
int16_t result = 0;
Expand Down Expand Up @@ -2543,7 +2565,7 @@ int16_t _SCL_boardEvaluateDynamic(
int8_t depth,
int16_t alphaBeta,
int8_t takenSquare) {
#if SCL_COUNT_EVALUATED_POSITIONS
#if defined(SCL_COUNT_EVALUATED_POSITIONS) && SCL_COUNT_EVALUATED_POSITIONS
SCL_positionsEvaluated++;
#endif

Expand Down Expand Up @@ -3248,7 +3270,8 @@ void SCL_printPGN(SCL_Record r, SCL_PutCharFunction putCharFunc, SCL_Board initi
SCL_Board board;

if(initialState != 0)
for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE; ++i) board[i] = initialState[i];
for(uint8_t i = 0; i < SCL_BOARD_STATE_SIZE; ++i)
board[i] = initialState[i];
else
SCL_boardInit(board);

Expand Down Expand Up @@ -3356,7 +3379,8 @@ void SCL_printPGN(SCL_Record r, SCL_PutCharFunction putCharFunc, SCL_Board initi
}

void SCL_recordCopy(SCL_Record recordFrom, SCL_Record recordTo) {
for(uint16_t i = 0; i < SCL_RECORD_MAX_SIZE; ++i) recordTo[i] = recordFrom[i];
for(uint16_t i = 0; i < SCL_RECORD_MAX_SIZE; ++i)
recordTo[i] = recordFrom[i];
}

void SCL_gameInit(SCL_Game* game, const SCL_Board startState) {
Expand All @@ -3369,7 +3393,8 @@ void SCL_gameInit(SCL_Game* game, const SCL_Board startState) {

SCL_recordInit(game->record);

for(uint8_t i = 0; i < 14; ++i) game->prevMoves[i] = 0;
for(uint8_t i = 0; i < 14; ++i)
game->prevMoves[i] = 0;

game->state = SCL_GAME_STATE_PLAYING;
game->ply = 0;
Expand Down Expand Up @@ -3419,7 +3444,8 @@ void SCL_gameMakeMove(SCL_Game* game, uint8_t squareFrom, uint8_t squareTo, char

game->ply++;

for(uint8_t i = 0; i < 14 - 2; ++i) game->prevMoves[i] = game->prevMoves[i + 2];
for(uint8_t i = 0; i < 14 - 2; ++i)
game->prevMoves[i] = game->prevMoves[i + 2];

game->prevMoves[12] = squareFrom;
game->prevMoves[13] = squareTo;
Expand Down Expand Up @@ -3489,4 +3515,4 @@ uint8_t SCL_boardMoveIsLegal(SCL_Board board, uint8_t squareFrom, uint8_t square
return SCL_squareSetContains(moves, squareTo);
}

#endif // guard
#endif // guard

0 comments on commit 5710cd8

Please sign in to comment.