void vehicle::move() { direction d = NO_DIRECTION; if (plan != -1) { cout << "there is a plan! "<< plan << " \n"; if (location->moves()[plan](location->neighbor(plan),this,plan) != NULL) { d = direction(plan); plan = -1; } // else wait for plan to be possible } else d = select_move(); if (d != NO_DIRECTION) { roadlet *r; location->depart(); r = location->neighbor(d); r->arrive(this); location = r; if ((d == N) || (d == S) || (d == E) || (d == W)) dir = d; // else = lane change only } }
void select_assign(Node var_node, Node expr_node, Symbol type_name) /*;select_assign*/ { Symbol var_name, expr_name; var_name = N_UNQ(var_node); expr_name = N_UNQ(expr_node); if (is_simple_type(type_name) && is_simple_name(var_node) && !is_renaming(var_name) ) { if ((is_simple_name(expr_node) && N_KIND(expr_node) != as_null && !is_renaming(expr_name)) || (N_KIND(expr_node) == as_selector || N_KIND(expr_node) == as_index || N_KIND(expr_node) == as_all)) { gen_address(expr_node); gen_ks(I_INDIRECT_POP, kind_of(type_name), var_name); } else { gen_value(expr_node); gen_ks(I_POP, kind_of(type_name), var_name); } } else { gen_address(var_node); select_move(expr_node, type_name); } }
int main(int argc, char *argv[]) { parse_options(argc, argv); initialize(); if (opt_time_test) { int v; double t0 = now(); max_depth = 16; best_value = NO_VALUE; num_moves = 0; v = evaluate(0, -INF, +INF); printf("max_depth=%d num_moves=%d v=%d best_move=%s\n", max_depth, num_moves, v, best_move_buf); printf("Execution time: %.3f (CPU: %.3f)\n", now() - t0, clock()/1e6); return 0; } while (played < 100) { if (!fgets(move_buf, sizeof(move_buf), stdin)) { fprintf(stderr, "ERROR: premature end of input!\n"); return 1; } if (strchr(move_buf, '\n')) *strchr(move_buf, '\n') = '\0'; /* Execute opponent's move */ if (strcmp(move_buf, "Start") != 0) { execute(move_buf); if (opt_verbose) dump(stderr); } /* Pick my move */ select_move(); if (best_value == NO_VALUE) { fprintf(stderr, "No moves available! Exiting.\n"); break; } fprintf(stderr, "Best move: [%s]; value: %d\n", best_move_buf, best_value); fflush(stderr); fprintf(stdout, "%s\n", best_move_buf); fflush(stdout); execute(best_move_buf); if (opt_verbose) dump(stderr); } return 0; }