#include "sgftree.h"
#define DEBUG_COMMANDS "\
-capture <pos> try to capture indicated group\n\
-dead Toggle display of dead stones\n\
-defend <pos> try to defend indicated group\n\
-listdragons print dragon info \n\
-showarea display area\n\
-showdragons display dragons\n\
-showmoyo display moyo\n\
-showterri display territory\n\
+No debug commands in two player mode\n\
"
#define MASTER_FIFO_NAME "/tmp/sgkgo-fifo-master"
show_commands(void)
{
printf("\nCommands:\n");
- printf(" back Take back your last move\n");
- printf(" boardsize Set boardsize (on move 1 only)\n");
printf(" comment Write a comment to outputfile\n");
printf(" depth <num> Set depth for reading\n");
printf(" display Display game board\n");
printf(" exit Exit GNU Go\n");
- printf(" force <move> Force a move for current color\n");
- printf(" forward Go to next node in game tree\n");
- printf(" goto <movenum> Go to movenum in game tree\n");
printf(" level <amount> Playing level (default = 10)\n");
- printf(" handicap <num> Set fixed handicap (on move 1 only)\n");
- printf(" freehandicap <num> Place free handicap (on move 1 only)\n");
- printf(" Omit <num> to place handicap yourself\n");
printf(" help Display this help menu\n");
printf(" helpdebug Display debug help menu\n");
printf(" info Display program settings\n");
- printf(" komi Set komi (on move 1 only)\n");
- printf(" last Goto last node in game tree\n");
printf(" pass Pass on your move\n");
- printf(" play <num> Play <num> moves\n");
- printf(" playblack Play as Black (switch if White)\n");
- printf(" playwhite Play as White (switch if Black)\n");
printf(" quit Exit GNU Go\n");
- printf(" resign Resign the current game\n");
printf(" save <file> Save the current game\n");
- printf(" load <file> Load a game from file\n");
printf(" score Toggle display of score On/Off\n");
printf(" showboard Toggle display of board On/Off\n");
- printf(" switch Switch the color you are playing\n");
- printf(" undo Take the last move back (same as back)\n");
printf(" <move> A move of the format <letter><number>");
printf("\n");
}
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);