sgffile_recordboard(sgftree.root);
}
+/*
+ * Communication with second player.
+ */
+
+static int
+twoplayer_recv_move(int fd)
+{
+ int move;
+ printf("\nWaiting to receive move from other player...\n");
+ if (read(fd, &move, sizeof(move)) != sizeof(int)) {
+ printf("\n");
+ printf(WHITECOLOR " " RESETCOLOR);
+ printf("\n");
+ printf(WHITECOLOR " " RESETCOLOR);
+ printf("Unrecoverable error. Save game if desired, then quit.");
+ printf(WHITECOLOR " " RESETCOLOR);
+ printf("\n");
+ printf(WHITECOLOR " " RESETCOLOR);
+ printf("\n");
+ printf("\n");
+ move = NO_MOVE;
+ }
+ return move;
+}
+
+static void
+twoplayer_send_move(int move, int fd)
+{
+ write(fd, &move, sizeof(move));
+}
+
/*
* Generate the computer move.
*/
static int
-computer_move(Gameinfo* gameinfo, int* passes, int transmit_fifo_fd, int receive_fifo_fd)
+computer_move(Gameinfo* gameinfo, int* passes, int receive_fifo_fd)
{
int move;
- float move_value;
- int resign;
int resignation_declined = 0;
float upper_bound, lower_bound;
init_sgf(gameinfo);
- /* Generate computer move. */
- if (autolevel_on)
- adjust_level_offset(gameinfo->to_move);
- move = genmove(gameinfo->to_move, &move_value, &resign);
- if (resignation_allowed && resign) {
- int state = twoplayer_endgame(gameinfo, 2);
- if (state != -1)
- return state;
-
- /* The opponent declined resignation. Remember not to resign again. */
- resignation_allowed = 0;
- resignation_declined = 1;
- }
+ move = twoplayer_recv_move(receive_fifo_fd);
if (showscore) {
gnugo_estimate_score(&upper_bound, &lower_bound);
*passes = 0;
gnugo_play_move(move, gameinfo->to_move);
- sgffile_add_debuginfo(sgftree.lastnode, move_value);
sgftreeAddPlay(&sgftree, gameinfo->to_move, I(move), J(move));
if (resignation_declined)
sgftreeAddComment(&sgftree, "GNU Go resignation was declined");
return 0;
}
+ twoplayer_send_move(move,transmit_fifo_fd);
+
*passes = 0;
TRACE("\nyour move: %1m\n\n", move);
init_sgf(gameinfo);
if (opt_showboard) {
twoplayer_showboard();
- printf("GNU Go is thinking...\n");
}
if (force) {
}
gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
- return computer_move(gameinfo, passes, transmit_fifo_fd, receive_fifo_fd);
+ return computer_move(gameinfo, passes, receive_fifo_fd);
}
/*
do_pass(Gameinfo* gameinfo, int* passes, int force,
int transmit_fifo_fd, int receive_fifo_fd)
{
+ twoplayer_send_move(NO_MOVE,transmit_fifo_fd);
+
(*passes)++;
init_sgf(gameinfo);
gnugo_play_move(PASS_MOVE, gameinfo->to_move);
return 0;
}
- return computer_move(gameinfo, passes, transmit_fifo_fd, receive_fifo_fd);
+ return computer_move(gameinfo, passes, receive_fifo_fd);
}
/*
int sz;
int transmit_fifo_fd, receive_fifo_fd;
- printf("DEBUG: Attempting to setup connection with other player.\n");
if (mknod(MASTER_FIFO_NAME, S_IFIFO | 0666, 0) == 0) {
- printf("DEBUG: We are the master. Created %s.\n", MASTER_FIFO_NAME);
gameinfo->computer_player = WHITE; // We are black, so our opponent is white.
- printf("DEBUG: Waiting for other player to connect.\n");
+ printf("Waiting for other player to connect.\n");
transmit_fifo_fd = open(MASTER_FIFO_NAME, O_WRONLY);
- printf("DEBUG: Slave connected to our FIFO. Now we connect to the slave's FIFO.\n");
receive_fifo_fd = open(SLAVE_FIFO_NAME, O_RDONLY);
- printf("DEBUG: Bidirectional communication established.\n");
} else {
- printf("DEBUG: Failed to create master FIFO. Perhaps we are the slave?\n");
gameinfo->computer_player = BLACK; // We are white, so our opponent is black.
if (mknod(SLAVE_FIFO_NAME, S_IFIFO | 0666, 0) == 0) {
- printf("DEBUG: We are the slave. Created %s.\n", SLAVE_FIFO_NAME);
receive_fifo_fd = open(MASTER_FIFO_NAME, O_RDONLY);
- printf("DEBUG: We connected to master's FIFO. Now we wait for master's connection to our FIFO.\n");
transmit_fifo_fd = open(SLAVE_FIFO_NAME, O_WRONLY);
- printf("DEBUG: Bidirectional communication established.\n");
} else {
- printf("DEBUG: Failed to create slave FIFO. This is an unrecoverable error.\n");
+ printf("ERROR: Failed to create both master and slave FIFO.\n");
exit(EXIT_FAILURE);
}
}
// this is a best-effort situation for now.
unlink(MASTER_FIFO_NAME);
unlink(SLAVE_FIFO_NAME);
-while(1){sleep(1);}
-exit(EXIT_SUCCESS);
setvbuf(stdout, (char*)NULL, _IONBF, 0); /* No buffering. */
/* Does the computer play first? If so, make a move. */
if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes, transmit_fifo_fd, receive_fifo_fd);
+ state = computer_move(gameinfo, &passes, receive_fifo_fd);
/* main ANSI Play loop */
while (state == 0) {
/* Get the command or move. */
switch (get_command(command)) {
case RESIGN:
- state = twoplayer_endgame(gameinfo, 1);
+ //state = twoplayer_endgame(gameinfo, 1);
break;
case END:
break;
}
- if (passes >= 2)
+ if (passes >= 2) {
+ twoplayer_send_move(NO_MOVE,transmit_fifo_fd);
state = twoplayer_endgame(gameinfo, 0);
+ }
}
#if READLINE
free(line_ptr);