stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 1551ef43fd7d3952a4369f57820bef742b65d365
parent 0461b5c531b538c2eb77226061a8003a632f4db7
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun, 25 Sep 2022 20:43:43 +0200

get_time_ms() function

Diffstat:
Minclude/utils.h | 2++
Msrc/engine.c | 6++++--
Msrc/utils.c | 15+++++++++++++++
3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/include/utils.h b/include/utils.h @@ -68,4 +68,6 @@ enum enumPiece { PAWN = 0, KNIGHT, BISHOP, ROOK, QUEEN, KING }; typedef enum enumColor eColor; typedef enum enumPiece ePiece; +int get_time_ms(void); + #endif diff --git a/src/engine.c b/src/engine.c @@ -354,7 +354,7 @@ int CBoard_move_make(CBoard_T self, Move move, int flag) { if (Move_capture(move)) { bit_pop(self->colorBB[!Piece->color], target); - for (int i = 0; i < 6; i++) + for (ePiece i = 0; i < 6; i++) if (i != Piece->piece && bit_get(self->pieceBB[i], target)) { bit_pop(self->pieceBB[i], target); break; @@ -516,6 +516,8 @@ int main(void) { board = CBoard_fromFEN(NULL, "r3k2r/pP1pqpb1/bn2pnp1/2pPN3/1p2P3/" "2N2Q1p/PPPBBPpP/R3K2R w KQkq c6 0 1 "); moves = CBoard_move_generate(board); + + int start = get_time_ms(); for (int i = 0; i < moves->count; i++) { struct CBoard_T backup = *board; if (!CBoard_move_make(board, moves->moves[i], 0)) { @@ -523,12 +525,12 @@ int main(void) { continue; } CBoard_print(board); - getc(stdin); *board = backup; /* CBoard_print(board); */ /* getc(stdin); */ } + printf("Executed in: %dms\n", get_time_ms() - start); return 0; } diff --git a/src/utils.c b/src/utils.c @@ -1,4 +1,9 @@ #include <stdio.h> +#ifdef WIN64 +#include <widnows.h> +#else +#include <sys/time.h> +#endif #include "utils.h" @@ -66,3 +71,13 @@ void bitboard_print(U64 bitboard) { printf("\n A B C D E F G H\n\n"); printf(" Bitboard: %llud\n\n", bitboard); } + +int get_time_ms(void) { +#ifdef WIN64 + return GetTickCount(); +#else + struct timeval time; + gettimeofday(&time, NULL); + return time.tv_sec * 1000 + time.tv_usec / 1000; +#endif +}