void play_controller::process_keyup_event(const SDL_Event& event) { // If the user has pressed 1 through 9, we want to show // how far the unit can move in that many turns if(event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9') { const int new_path_turns = (event.type == SDL_KEYDOWN) ? event.key.keysym.sym - '1' : 0; if(new_path_turns != mouse_handler_.get_path_turns()) { mouse_handler_.set_path_turns(new_path_turns); const unit_map::iterator u = mouse_handler_.selected_unit(); if(u.valid()) { // if it's not the unit's turn, we reset its moves unit_movement_resetter move_reset(*u, u->side() != current_side()); mouse_handler_.set_current_paths(pathfind::paths(*u, false, true, gamestate().board_.teams_[gui_->viewing_team()], mouse_handler_.get_path_turns())); gui_->highlight_reach(mouse_handler_.current_paths()); } else { mouse_handler_.select_hex(mouse_handler_.get_selected_hex(), false, false, false); } } } else if (event.key.keysym.sym == SDLK_TAB) { static CKey keys; if (!keys[SDLK_TAB]) { whiteboard_manager_->set_invert_behavior(false); } } }
void mainloop(Robot* robot) { /*** Initialisation ***/ rb = robot; oldE = 0.0f; /* Generate a random genom */ genom = 0; for(int i = 0; i < 3; ++i) { GENOM_SET (genom, rand_act(), i); } /* First movement */ move_reset(); switch(rand_act()) { case ACT_TURN_RIGHT: move_turn(PI/2.0f); break; case ACT_TURN_LEFT: move_turn(-PI/2.0f); break; } move_go(); /*** Loop ***/ for(;;) { if(rb->discover()) { char buffer[256]; int size; move_stop(); buffer[0] = 0xaa; rb->send(buffer, 1); size = rb->receive(buffer, 256); if(size != 1) { /* Taille invalide, on ignore */ rb->close(); move_go(); continue; } else { if(buffer[0] == (char)0xFF) { /* Connection à l'ordi central */ /* TODO */ rb->close(); move_go(); continue; } else { float E = evalue(); buffer[0] = ((genom & 0x3f) << 1); rb->memcpy(buffer + 1, &dist, 4); rb->memcpy(buffer + 5, &E, 4); rb->send(buffer, 9); float rdist; size = rb->receive(buffer, 256); rb->close(); if(size != 9 || (buffer[0] & 0x7e) != 0) { move_go(); continue; } rb->memcpy(&rdist, buffer + 1, 4); rb->memcpy(&E, buffer + 5, 4); if(evolve((buffer[0] & 0x3f) >> 1, E, rdist)) { move_reset(); } move_go(); continue; } } } float sc = rb->scan(); Action act; if(sc < DNEXT) { act = GENOM_GET(genom, NEXT); move_stop(); switch(act) { case ACT_TURN_RIGHT: move_turn(PI/2.0f); break; case ACT_TURN_LEFT: move_turn(-PI/2.0f); break; case ACT_STRAIGHT: move_turn(PI); break; } move_go(); } else if(sc < DNEAR) { act = GENOM_GET(genom, NEAR); move_stop(); switch(act) { case ACT_TURN_RIGHT: move_turn(PI/2.0f); break; case ACT_TURN_LEFT: move_turn(-PI/2.0f); break; } move_go(); } else if(sc < DFAR) { act = GENOM_GET(genom, FAR); move_stop(); switch(act) { case ACT_TURN_RIGHT: move_turn(PI/2.0f); break; case ACT_TURN_LEFT: move_turn(-PI/2.0f); break; } move_go(); } }