void ALEState::reset(int numResetSteps) { // reset the rom m_settings->reset(); // Reset the paddles default_paddles(); // Reset the emulator m_osystem->console().system().reset(); // NOOP for 60 steps for (int i = 0; i < 60; i++) { apply_action(PLAYER_A_NOOP, PLAYER_B_NOOP); simulate(); // Don't count these frames frame_number--; } // reset for n steps for (int i = 0; i < numResetSteps; i++) { apply_action(RESET, PLAYER_B_NOOP); simulate(); // Don't count these frames frame_number--; } // Apply necessary actions specified by the rom itself ActionVect startingActions = m_settings->getStartingActions(); for (int i = 0; i < startingActions.size(); i++) { apply_action(startingActions[i], PLAYER_B_NOOP); simulate(); frame_number--; } }
void updateGameAIPause(GUI *g, Controls *c, game_t *gm) { NOT(g); NOT(c); NOT(gm); if (!gm->player[gm->turn].aiShare.shareStart) { pthread_t thread; gm->player[gm->turn].aiShare.shareStart = true; gm->player[gm->turn].aiShare.shareEnd = false; gm->player[gm->turn].aiShare.loading = 0.f; gm->player[gm->turn].aiShare.game = gm; if (pthread_create(&thread, NULL, cbUpdateAi, &gm->player[gm->turn].aiShare) != 0) { exit(2); } } if (gm->player[gm->turn].aiShare.shareEnd) { gm->player[gm->turn].aiShare.shareStart = false; gm->player[gm->turn].aiShare.shareEnd = false; gm->player[gm->turn].aiShare.loading = 1.f; addActionToTextLog(&g->gameGui.textLog, &gm->player[gm->turn].aiShare.action); actionToLastMove(&g->gameGui.lastMove, &gm->player[gm->turn].aiShare.action); apply_action(&gm->player[gm->turn].aiShare.action, gm); next_turn(gm); g->next = nextGUIFocusByplayer_tag_t(gm->player[gm->turn].type); } }
void updateGameAreYouSureQuit(GUI *g, game_t *gm, Controls *c) { updateMenuWidget(&g->gameAreYouSureQuit, c); if (submitted(c)) { g->next = guiFocusGameMenu; if (g->gameAreYouSureQuit.focus == yes) { move_t m; action_t a; g->next = guiFocusGameOver; m.type = MOVE_QUIT; m.playerIdx = gm->turn; mk_action(gm, &m, &a); assert(a.type == ACTION_QUIT); apply_action(&a, gm); } return; } if (goBack(c)) g->next = guiFocusGameMenu; }
static int traverse_file(Elf *elf, GElf_Ehdr * ehdr, char *cur_file, Cmd_Info *cmd_info) { Elf_Scn * scn; Elf_Scn * temp_scn; Elf_Data * data; GElf_Shdr * shdr; char *temp_name; section_info_table * sinfo; GElf_Xword x; int ret = 0, SYM = 0; /* used by strip command */ int phnum = ehdr->e_phnum; unsigned int i, scn_index; size_t shstrndx, shnum; Sect_exists = 0; if (elf_getshnum(elf, &shnum) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (elf_getshstrndx(elf, &shstrndx) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } scn = 0; scn_index = 1; sinfo = &sec_table[scn_index]; while ((scn = elf_nextscn(elf, scn)) != 0) { char *name; shdr = &(sinfo->shdr); if (gelf_getshdr(scn, shdr) == NULL) { error_message(NO_SECT_TABLE_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog, cur_file); return (FAILURE); } else { name = elf_strptr(elf, shstrndx, (size_t)shdr->sh_name); if (name == NULL) name = "_@@@###"; } sinfo->scn = scn; sinfo->secno = scn_index; sinfo->osecno = scn_index; SET_ACTION(sinfo->flags, ACT_NOP); sinfo->name = name; if (ehdr->e_phnum == 0) SET_LOC(sinfo->flags, NOSEG); else SET_LOC(sinfo->flags, scn_location(scn, elf)); if (shdr->sh_type == SHT_GROUP) { if (list_appendc(&cmd_info->sh_groups, sinfo) == 0) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } } /* * If the target section is pointed by a section * holding relocation infomation, then the * pointing section would be useless if the * target section is removed. */ if ((shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA) && (shdr->sh_info != SHN_UNDEF && (temp_scn = elf_getscn(elf, shdr->sh_info)) != 0)) { GElf_Shdr tmp_shdr; if (gelf_getshdr(temp_scn, &tmp_shdr) != NULL) { temp_name = elf_strptr(elf, shstrndx, (size_t)tmp_shdr.sh_name); sinfo->rel_name = temp_name; sinfo->rel_scn_index = shdr->sh_info; if (phnum == 0) sinfo->rel_loc = NOSEG; else sinfo->rel_loc = scn_location(temp_scn, elf); } } data = 0; if ((data = elf_getdata(scn, data)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } sinfo->data = data; /* * Check if this section is a candidate for * action to be processes. */ if (sectcmp(name) == 0) { SET_CANDIDATE(sinfo->flags); /* * This flag just shows that there was a * candidate. */ Sect_exists++; } /* * Any of the following section types should * also be removed (if possible) if invoked via * the 'strip' command. */ if (CHK_OPT(cmd_info, I_AM_STRIP) && ((shdr->sh_type == SHT_SUNW_DEBUG) || (shdr->sh_type == SHT_SUNW_DEBUGSTR))) { SET_CANDIDATE(sinfo->flags); Sect_exists++; } /* * Zap this file ? */ if ((cmd_info->flags & zFLAG) && (shdr->sh_type == SHT_PROGBITS)) { SET_CANDIDATE(sinfo->flags); Sect_exists++; } x = GET_LOC(sinfo->flags); /* * Remeber the note sections index so that we can * reset the NOTE segments offset to point to it. * * It may have been assigned a new location in the * resulting output elf image. */ if (shdr->sh_type == SHT_NOTE) notesctndx = scn_index; if (x == IN || x == PRIOR) off_table[scn_index] = shdr->sh_offset; if (shdr->sh_type == SHT_NOBITS) nobits_table[scn_index] = 1; /* * If this section satisfies the condition, * apply the actions specified. */ if (ISCANDIDATE(sinfo->flags)) { ret += apply_action(sinfo, cur_file, cmd_info); } /* * If I am strip command, determine if symtab can go or not. */ if (CHK_OPT(cmd_info, I_AM_STRIP) && (CHK_OPT(cmd_info, xFLAG) == 0) && (CHK_OPT(cmd_info, lFLAG) == 0)) { if (shdr->sh_type == SHT_SYMTAB && GET_LOC(sinfo->flags) == AFTER) { SYM = scn_index; } } scn_index++; sinfo++; } sinfo->scn = (Elf_Scn *) -1; /* * If there were any errors traversing the file, * just return error. */ if (ret != 0) return (FAILURE); /* * Remove symbol table if possible */ if (CHK_OPT(cmd_info, I_AM_STRIP) && SYM != 0) { GElf_Shdr tmp_shdr; (void) gelf_getshdr(sec_table[SYM].scn, &tmp_shdr); sec_table[SYM].secno = (GElf_Word)DELETED; ++(cmd_info->no_of_nulled); if (Sect_exists == 0) ++Sect_exists; SET_ACTION(sec_table[SYM].flags, ACT_DELETE); off_table[SYM] = 0; /* * Can I remove section header * string table ? */ if ((tmp_shdr.sh_link < shnum) && (tmp_shdr.sh_link != SHN_UNDEF) && (tmp_shdr.sh_link != shstrndx) && (GET_LOC(sec_table[tmp_shdr.sh_link].flags) == AFTER)) { sec_table[tmp_shdr.sh_link].secno = (GElf_Word)DELETED; ++(cmd_info->no_of_nulled); if (Sect_exists == 0) ++Sect_exists; SET_ACTION(sec_table[tmp_shdr.sh_link].flags,\ ACT_DELETE); off_table[tmp_shdr.sh_link] = 0; } } /* * If I only printed the contents, then * just report so. */ if (CHK_OPT(cmd_info, pFLAG) && !CHK_OPT(cmd_info, MIGHT_CHG)) return (DONT_BUILD); /* don't bother creating a new file */ /* since the file has not changed */ /* * I might need to add a new section. Check it. */ if (Sect_exists == 0 && CHK_OPT(cmd_info, aFLAG)) { int act = 0; new_sec_string = calloc(1, cmd_info->str_size + 1); if (new_sec_string == NULL) return (FAILURE); for (act = 0; act < actmax; act++) { if (Action[act].a_action == ACT_APPEND) { (void) strcat(new_sec_string, Action[act].a_string); (void) strcat(new_sec_string, "\n"); cmd_info->no_of_append = 1; } } } /* * If I did not append any new sections, and I did not * modify/delete any sections, then just report so. */ if ((Sect_exists == 0 && cmd_info->no_of_append == 0) || !CHK_OPT(cmd_info, MIGHT_CHG)) return (DONT_BUILD); /* * Found at least one section which was processed. * Deleted or Appended or Compressed. */ if (Sect_exists) { /* * First, handle the deleted sections. */ if (cmd_info->no_of_delete != 0 || cmd_info->no_of_nulled != 0) { int acc = 0; int rel_idx; /* * Handle relocation/target * sections. */ sinfo = &(sec_table[0]); for (i = 1; i < shnum; i++) { sinfo++; rel_idx = sinfo->rel_scn_index; if (rel_idx == 0) continue; /* * If I am removed, then remove my * target section. */ if (((sinfo->secno == (GElf_Word)DELETED) || (sinfo->secno == (GElf_Word)NULLED)) && sinfo->rel_loc != IN) { if (GET_LOC(sec_table[rel_idx].flags) == PRIOR) sec_table[rel_idx].secno = (GElf_Word)NULLED; else sec_table[rel_idx].secno = (GElf_Word)DELETED; SET_ACTION(sec_table[rel_idx].flags,\ ACT_DELETE); } /* * I am not removed. Check if my target is * removed or nulled. If so, let me try to * remove my self. */ if (((sec_table[rel_idx].secno == (GElf_Word)DELETED) || (sec_table[rel_idx].secno == (GElf_Word)NULLED)) && (GET_LOC(sinfo->flags) != IN)) { if (GET_LOC(sinfo->flags) == PRIOR) sinfo->secno = (GElf_Word)NULLED; else sinfo->secno = (GElf_Word)DELETED; SET_ACTION(sinfo->flags,\ ACT_DELETE); } } /* * Now, take care of DELETED sections */ sinfo = &(sec_table[1]); for (i = 1; i < shnum; i++) { shdr = &(sinfo->shdr); if (sinfo->secno == (GElf_Word)DELETED) { acc++; /* * The SHT_GROUP section which this section * is a member may be able to be removed. * See post_process(). */ if (shdr->sh_flags & SHF_GROUP) cmd_info->flags |= SHF_GROUP_DEL; } else { /* * The data buffer of SHT_GROUP this section * is a member needs to be updated. * See post_process(). */ sinfo->secno -= acc; if ((shdr->sh_flags & SHF_GROUP) && (acc != 0)) cmd_info->flags |= SHF_GROUP_MOVE; } sinfo++; } } } /* * I know that the file has been modified. * A new file need to be created. */ return (SUCCESS); }
void updateGameGUI(GUI *g, Controls *c, game_t *gm) { Cmd cmd; move_t m; action_t a; Log l; GameGUI *gg; TransMove *tm; NOT(g); NOT(c); NOT(gm); gg = &g->gameGui; tm = &g->transMove; if (c->hardware.key[hardwareKeyStart].type == KEY_STATE_PRESSED) { g->next = guiFocusGameMenu; return; } if (tm->type == transMoveInvalid) { resetNewGameGui(g, gm); } switch (gg->focus) { case gameGUIFocusBoard: boardWidgetControls(&cmd, gg, c); break; case gameGUIFocusRack: rackWidgetControls(&cmd, gg, c); break; default: break; } updateGameGUIViaCmd(gg, &cmd, tm->type); switch (cmd.type) { case cmdFocusTop: { if (tm->type == transMovePlace || tm->type == transMovePlaceEnd || tm->type == transMovePlacePlay) { gg->focus = gameGUIFocusBoard; } break; } case cmdFocusBottom: { if (tm->type == transMovePlaceWild) { break; } gg->focus = gameGUIFocusRack; break; } case cmdBoard: { if (tm->type == transMoveDiscard || tm->type == transMoveDiscardPlay) { break; } gg->focus = gameGUIFocusBoard; gg->boardWidget.index = cmd.data.board; break; } case cmdRack: { if (tm->type == transMoveSkip) { break; } gg->focus = gameGUIFocusRack; gg->rackWidget.index.x = cmd.data.rack; gg->rackWidget.index.y = 0; break; } default: break; } if (cmd.type == cmdInvalid) { gg->lastInput += SPF; } else { gg->lastInput = 0; } /* printCmd(&c); */ if (updateTransMove(tm, &cmd, &gm->board, &gm->player[gm->turn])) { /* printTransMove(&e->transMove); */ updateBoardWidget(&gg->boardWidget, tm, &gm->board); updateRackWidget(&gg->rackWidget, tm); if (tm->type == transMoveDiscard) { gg->focus = gameGUIFocusRack; } } transMoveToMove(&m, tm); mk_action(gm, &m, &a); apply_action(&a, gm); if (cmd.type == cmdPlay || cmd.type == cmdQuit) mkLog(&a, &l); if (a.type != ACTION_INVALID) { addActionToTextLog(&gg->textLog, &a); actionToLastMove(&gg->lastMove, &a); apply_adjust(tm->adjust.data.tile, &gm->player[a.playerIdx]); /* log action */ if (end_game(gm)) { g->next = guiFocusGameOver; /* log game over */ } else { next_turn(gm); clrTransMove(tm, gm->turn, &gm->player[gm->turn], &gm->board); g->next = nextGUIFocusByplayer_tag_t(gm->player[gm->turn].type); } tm->type = transMoveInvalid; } else { if (m.type != MOVE_INVALID) { /* printActionErr(a.type); */ } } if (cmd.type == cmdPlay) { gg->validPlay = a.type != ACTION_INVALID ? yes : no; } else { gg->validPlay = yesNoInvalid; } updateScoreBoard(&g->scoreBoard, gm, SPF); }