-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.c
79 lines (64 loc) · 2.82 KB
/
logic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "logic.h"
#include "internal/containers/arraylist.h"
#include "internal/generators/generate.h"
#include "internal/update.h"
#include "internal/eval.h"
#include <string.h>
#define minus_inf -2147483647
#define plus_inf 2147483647
#define DEPTH 4
void do_internal_logic(controller_t *controller, board_t *board)
{
if (is_set(controller, C_NEW)) {
// if a new game has begun, clear the board
clear_board(board);
// turn off the flag
clear_flag(controller, C_NEW);
}
if (!is_set(controller, C_FORCE)) {
if (strlen(get_in_buffer(controller)) != 0) {
// a move has been given to the engine
move_t in_move = to_move(get_in_buffer(controller));
update(board, is_set(controller, C_ES), in_move, 0U);
// cleaning in buffer after move is made
memset(get_in_buffer(controller), 0, IN_BUF_SIZE);
}
if (!is_set(controller, C_FORCE) && (is_set(controller, C_STM) == is_set(controller, C_ES))) {
arraylist_t *available_moves = generate_moves(board, is_set(controller, C_ES));
if (size(available_moves) == 0) {
// no move to make, set resign flag
set_flag(controller, C_RESIGN);
return;
}
// move_t best_move = select_move(board, eval, is_set(controller, C_ES), alpha=minus_inf, beta=plus_inf, depth, &best_move);
//move_t best_move = select_move(board, eval, is_set(controller, C_ES), minus_inf, plus_inf, DEPTH, &best_move);
// decides best move
move_t best_move;
// best_move = (select_move()) -> move;
best_move = (select_move(board, eval, available_moves, is_set(controller, C_ES),
minus_inf, plus_inf, DEPTH)).move;
/*print_move(best_move);
printf("primary fnc checks:\n");
printf("\n%d\n", get_white_checks_num(board));
printf("%d\n\n", get_black_checks_num(board));*/
// updating board
update(board, is_set(controller, C_ES), 0U, best_move);
// setting has move flag
set_flag(controller, C_HAS_MOVE);
// writing move to output buffer
to_string(get_out_buffer(controller), best_move);
// changing side to move
toggle_flag(controller, C_STM);
// destroying list of moves
//destroy_list(&available_moves);
}
} else {
if (strlen(get_in_buffer(controller)) != 0) {
// a move has been given to the engine
move_t in_move = to_move(get_in_buffer(controller));
update(board, is_set(controller, C_STM), in_move, 0U);
// cleaning in buffer after move is made
memset(get_in_buffer(controller), 0, IN_BUF_SIZE);
}
}
}