X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=src%2Frrsolve.c;h=5e92cbb94a5edb16cbb996e96e9ee7fbf6ed0b1d;hb=a278d8f2b6534fc46e035d6a2a9984407c2c7aba;hp=1057481222568558e3f3f787f03820a5fe40a908;hpb=596aa30835a89015415d42a16c9e07c7dbd382b8;p=rrsolve diff --git a/src/rrsolve.c b/src/rrsolve.c index 1057481..5e92cbb 100644 --- a/src/rrsolve.c +++ b/src/rrsolve.c @@ -85,8 +85,10 @@ main (int argc, char *argv[]) for (i = 0; args.files[i]; i++) { board = rr_board_create_from_file (args.files[i]); - if (board == NULL) + if (board == NULL) { + fprintf (stderr, "Failed to parse board in %s\n", args.files[i]); continue; + } rrs_solution_init (&solution); solve_board (board, &solution); rrs_solution_print (&solution); @@ -165,18 +167,8 @@ handle_events (rr_client_t *client) } switch (notice->type) { - /* XXX: The processing needed for GAMEOVER, JOIN, and TURN - is a mess right now. There should be one NOTICE to say - the board has changed and one to say a TURN has started, - rather than the current mess. */ - case RR_NOTICE_GAMEOVER: - status = rr_client_show (client, &diagram); - if (status) { - fprintf (stderr, "Error in rr_client_show: %s\n", rr_status_str (status)); - goto DONE; - } - rr_board_parse (board, diagram); - free (diagram); + case RR_NOTICE_BOARD: + rr_board_parse (board, notice->u.string); break; case RR_NOTICE_TURN: rr_board_set_goal_target (board, notice->u.target); @@ -206,19 +198,21 @@ handle_events (rr_client_t *client) rr_client_nobid (client); break; case RR_NOTICE_POSITION: - rr_board_position_robot (board, - notice->u.position.robot, - notice->u.position.x, - notice->u.position.y); + rr_board_add_robot (board, + notice->u.position.robot, + notice->u.position.x, + notice->u.position.y); break; case RR_NOTICE_GAMESTATE: - if (notice->u.gamestate == RR_GAMESTATE_SHOW) { + if (notice->u.gamestate == RR_GAMESTATE_DONE + || notice->u.gamestate == RR_GAMESTATE_SHOW) { if (solution.num_moves) { printf ("My solution (%d moves):", solution.num_moves); rrs_solution_print (&solution); } } break; + case RR_NOTICE_GAMEOVER: case RR_NOTICE_GAME: case RR_NOTICE_USER: case RR_NOTICE_JOIN: @@ -291,11 +285,13 @@ rrs_state_set_board (rrs_state_t state, rr_board_t *board) int i; int x, y; + for (i=0; i < RR_NUM_ROBOTS; i++) + rr_board_remove_robot (board, rr_robot_from_idx (i)); + for (i=0; i < RR_NUM_ROBOTS; i++) { RRS_STATE_GET_ROBOT (state, i, x, y); - rr_board_position_robot (board, rr_robot_from_idx (i), x, y); + rr_board_add_robot (board, rr_robot_from_idx (i), x, y); } - } static rr_status_t @@ -420,7 +416,7 @@ trace_solution (rr_board_t *board, rr_status_t status; int i, j; rrs_state_buf_t *buf; - int found_move; + int found_move = 0; rr_robot_t robot, robot_found, last_robot_found = RR_ROBOT_NONE; rr_direction_t dir, dir_found; rrs_state_t state_found; @@ -547,6 +543,9 @@ rrs_find_new_states (rr_board_t *board, state = initial->state[i]; rrs_state_set_board (state, board); + + if (state == 0x611a4350) + printf ("I'm within one move now\n"); for (ri = 0; ri < RR_NUM_ROBOTS; ri++) { robot = rr_robot_from_idx (ri); for (dir = RR_DIRECTION_NORTH; dir <= RR_DIRECTION_EAST; dir++) {