summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-08-18 10:10:51 +0300
committereug-vs <eugene@eug-vs.xyz>2022-08-18 10:10:51 +0300
commit3a9cdaa176370edd81653d62812c836f9bb00219 (patch)
treeba03b13df886fefa3b7a926758d2269a494a0d3c /src/main.c
parenta389dd0562699e36c196d69c578a1f1c373a12ab (diff)
downloadc-chess-3a9cdaa176370edd81653d62812c836f9bb00219.tar.gz
feat: make game interactive
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index edb553b..c66ab37 100644
--- a/src/main.c
+++ b/src/main.c
@@ -292,8 +292,7 @@ int compute_score(int* board) {
// Value here is white material advantage over black
// Alpha is the best value for maximizer (white)
// Beta is the best value for minimizer (black)
-int find_best_move(int* board, int color, int depth, int alpha, int beta) {
- int best_move[2];
+int find_best_move(int best_move[2], int* board, int color, int depth, int alpha, int beta) {
int fake_board[128];
int is_maximizer = (color == 0);
int best_value = is_maximizer ? -INFINITY : INFINITY;
@@ -319,8 +318,9 @@ int find_best_move(int* board, int color, int depth, int alpha, int beta) {
apply_move(move, fake_board);
+ int dummy[2];
int value = depth < MAX_DEPTH
- ? find_best_move(fake_board, 1 - color, depth + 1, alpha, beta)
+ ? find_best_move(dummy, fake_board, 1 - color, depth + 1, alpha, beta)
: compute_score(fake_board);
if (is_maximizer) {
@@ -365,13 +365,14 @@ int main() {
int move[2];
- int color = 0;
+ int color = WHITE;
while (1) {
- printf("Current score is %i\n", compute_score(board));
- find_best_move(board, color, 0, -INFINITY, +INFINITY);
- printf("Enter a move for %s:\n", COLORS[color]);
- input_move(move);
+ if (color == WHITE) {
+ printf("Current score is %i\n", compute_score(board));
+ printf("Enter a move for %s:\n", COLORS[color]);
+ input_move(move);
+ } else find_best_move(move, board, color, 0, -INFINITY, +INFINITY);
int error = validate_move(move, color, board);
if (error < 0) {