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
|
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "bitboard.h"
#include "engine/moves.h"
#include "fen.h"
#include "fcntl.h"
#include "uci.h"
#include "ipc.h"
// struct sqrstr {
// char data[2];
// };
// struct sqrstr sqr_to_str(int i) {
// assert(i < 64);
// return (struct sqrstr) { .data = {(i / 10) + '0', (i % 10) + '0' } };
// }
int main(int argc, char** argv) {
comms *state = create_shared_memory(sizeof(comms));
printf("ENGINE: %p\n", state);
state->uci_message_ready = 69;
if (fork() == 0) {
return uci(state);
}
while (1) {}
// while (1) {
// char* x = read_queue(rx);
// log_infof("Received: %s", x);
//
// moves_t moves = moves_init();
// struct fen_load result = load_fen(x);
// free(x);
//
// if (result.failed) {
// log_warnf("Invalid fen");
// send_queue(tx, "Failed", 7);
// return 0;
// }
// log_infof("Valid fen");
//
// position_t position = result.position;
//
// get_moves(&moves, position);
// send_queue(tx, "Sending", 8);
// char buf[65];
// int k = 0;
// for (int i = 0; i < moves.length; i++) {
// struct sqrstr from_str = sqr_to_str(moves.moves[i].from);
// struct sqrstr to_str = sqr_to_str(moves.moves[i].to);
// buf[k++] = from_str.data[0];
// buf[k++] = from_str.data[1];
// buf[k++] = to_str.data[0];
// buf[k++] = to_str.data[1];
// if (k != 64) continue;
// buf[k] = 0;
// send_queue(tx, buf, sizeof(buf));
// k = 0;
// }
// if (k != 0) send_queue(tx, buf, sizeof(buf));
// char end_transmission[] = "END-TRANSMISSION";
// int n = strlen(end_transmission);
// log_infof("%s", end_transmission);
// send_queue(tx, end_transmission, n + 1);
// }
return 0;
}
#include "engine/moves.c"
|