ref: 89075ea71723a00674b3c74cb42b1a3e7213544a
parent: a0266a89597a4b65947dd39fd01d519c1f50766c
author: zamfofex <zamfofex@twdb.moe>
date: Wed Nov 15 16:19:32 EST 2023
replace ‘time()’ with ‘clock()’
--- a/main.c
+++ b/main.c
@@ -93,7 +93,7 @@
btime = time;
}
- moonfish_best_move(ctx, &move, wtime / 1000, btime / 1000);
+ moonfish_best_move(ctx, &move, wtime, btime);
moonfish_to_uci(name, &move, ctx->chess.white);
printf("bestmove %s\n", name);}
--- a/search.c
+++ b/search.c
@@ -2,6 +2,8 @@
/* copyright 2023 zamfofex */
#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "moonfish.h"
@@ -45,9 +47,7 @@
#ifdef MOONFISH_HAS_PTHREAD
#include <pthread.h>
-#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include <unistd.h>
#include <errno.h>
@@ -209,20 +209,36 @@
#endif
+static clock_t moonfish_clock(struct moonfish *ctx)
+{+ clock_t t;
+ t = clock();
+ if (t < 0)
+ {+ fprintf(stderr, "%s: unknown clock\n", ctx->argv0);
+ exit(1);
+ }
+ return t;
+}
+
int moonfish_best_move(struct moonfish *ctx, struct moonfish_move *best_move, long int our_time, long int their_time)
{- long int d;
- time_t t;
+ clock_t t, d;
int i;
int score;
- d = our_time - their_time + our_time / 16;
+ our_time *= CLOCKS_PER_SEC;
+ their_time *= CLOCKS_PER_SEC;
+
+ d = our_time - their_time;
if (d < 0) d = 0;
+ d += our_time / 16;
+ d /= 1000;
i = 3;
- t = time(NULL);
+ t = moonfish_clock(ctx);
score = moonfish_best_move_depth(ctx, best_move, i);
- t = time(NULL) - t + 2;
+ t = moonfish_clock(ctx) - t + CLOCKS_PER_SEC / 4;
for (;;)
{--
⑨