public ElapsedCpuTimer copy() { var newTimer = new ElapsedCpuTimer(); newTimer.oldTime = this.oldTime; newTimer.maxTime = this.maxTime; return(newTimer); }
/** * Picks an action. This function is called every game step to request an * action from the player. The action returned must be contained in the * actions accessible from stateObs.getAvailableActions(), or no action * will be applied. * Multi player method. * @param stateObs Observation of the current state. * @param elapsedTimer Timer when the action returned is due. * @return An action for the current state */ public VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) { lastGameObservation = stateObs; if (lastVectorAction == null || lastVectorAction.Length < 1) { return(VGDLAvatarActions.ACTION_NIL); } return((VGDLAvatarActions)Mathf.RoundToInt(lastVectorAction[0])); }
/** * Function called when the game is over. This method must finish before CompetitionParameters.TEAR_DOWN_TIME, * or the agent will be DISQUALIFIED * @param stateObs the game state at the end of the game * @param elapsedCpuTimer timer when this method is meant to finish. */ public void result(StateObservationMulti stateObs, ElapsedCpuTimer elapsedCpuTimer) { Done(); var diff = stateObs.getGameScore(PlayerID) - lastScore; AddReward(diff); lastScore = stateObs.getGameScore(PlayerID); lastGameObservation = stateObs; //SetReward(stateObs.getGameScore(PlayerID)); }
public void RunGame(VGDLGameAndLevel gameToRun, int randomSeed = -1) { if (numberOfRunsToEvaluate > 0 && runs >= numberOfRunsToEvaluate) { return; } InitializeGame(gameToRun, randomSeed); started = true; StartTime = new ElapsedCpuTimer(); ticks = 0; renderTicks = 0; }
/** * Requests the controller's input, setting the game.ki.action mask with the processed data. * @param game */ protected VGDLAvatarActions requestAgentInput(VGDLGame game) { var ect = new ElapsedCpuTimer(); ect.setMaxTimeMilliseconds(ACTION_TIME); var action = VGDLAvatarActions.ACTION_NIL; if (game.no_players > 1) { action = player.act(game.getObservationMulti(playerID), ect.copy()); } else { action = player.act(game.getObservation(), ect.copy()); } if (TIME_CONSTRAINED && ect.exceededMaxTime()) { var exceeded = -ect.remainingTimeMilliseconds(); if (ect.ElapsedMilliseconds > ACTION_TIME_DISQ) { //The agent took too long to replay. The game is over and the agent is disqualified Debug.Log("Too long: " + playerID + "(exceeding " + (exceeded) + "ms): controller disqualified."); game.disqualify(playerID); } else { Debug.Log("Overspent: " + playerID + "(exceeding " + (exceeded) + "ms): applying ACTION_NIL."); } action = VGDLAvatarActions.ACTION_NIL; } if (action == VGDLAvatarActions.ACTION_ESCAPE) { game.Abort(); } else if (!actions.Contains(action)) { action = VGDLAvatarActions.ACTION_NIL; } player.logAction(action); game.avatarLastAction[playerID] = action; return(action); }
public void passResult(VGDLGame game) { var ect = new ElapsedCpuTimer(); ect.setMaxTimeMilliseconds(TEAR_DOWN_TIME); if (game.no_players > 1) { player.result(game.getObservationMulti(playerID), ect.copy()); } else { player.result(game.getObservation(), ect.copy()); } }
public void RunGame(VGDLPlayerInterface[] players, int randomSeed, bool saveFrames = false) { game.prepareGame(players, randomSeed); totalTime = new ElapsedCpuTimer(); started = true; this.saveFrames = saveFrames; //TODO: think about headless vs saveFrames, should we be able to saveFrames with headless. if (this.saveFrames && !headless) { //TODO: select a better output location for frames. var path = Path.Combine(Application.dataPath, Path.Combine("Frames", "frame" + game.gameTick + ".png")); StartCoroutine(SavePNG(path)); } }
/** * Picks an action. This function is called every game step to request an * action from the player. * @param stateObs Observation of the current state. * @param elapsedTimer Timer when the action returned is due. * @return An action for the current state */ public override VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) { var action = actions[actionIdx]; actionIdx++; var remaining = elapsedTimer.remainingTimeMilliseconds(); while (remaining > 1) { //This allows visualization of the replay. remaining = elapsedTimer.remainingTimeMilliseconds(); } return(action); }
public override VGDLAvatarActions act(StateObservation stateObs, ElapsedCpuTimer elapsedTimer) { var keyhandler = stateObs.getKeyHandler(0); var move = keyhandler.ProcessPlayerMovement(0); var useOn = keyhandler.ProcessUseInput(0); //In the keycontroller, move has preference. var action = AvatarAction.fromVector(move); //if(action == Types.ACTIONS.ACTION_NIL && useOn) if (useOn) //This allows switching to Use when moving. { action = VGDLAvatarActions.ACTION_USE; } return(action); }
public override VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) { //int id = (getPlayerID() + 1) % stateObs.getNoPlayers(); var keyhandler = stateObs.getKeyHandler(PlayerID); var move = keyhandler.ProcessPlayerMovement(PlayerID); var useOn = keyhandler.ProcessUseInput(PlayerID); //In the keycontroller, move has preference. VGDLAvatarActions action = AvatarAction.fromVector(move); if (action == VGDLAvatarActions.ACTION_NIL && useOn) { action = VGDLAvatarActions.ACTION_USE; } return(action); }
public override VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) { return(stateObs.getAvailableActions().RandomElement()); }
public void result(StateObservationMulti stateObs, ElapsedCpuTimer elapsedCpuTimer) { }
/** * Picks an action. This function is called every game step to request an * action from the player. The action returned must be contained in the * actions accessible from stateObs.getAvailableActions(), or no action * will be applied. * Multi player method. * @param stateObs Observation of the current state. * @param elapsedTimer Timer when the action returned is due. * @return An action for the current state */ public abstract VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer);