Esempio n. 1
0
    /**
     * 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]));
    }
Esempio n. 2
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));
    }
Esempio n. 3
0
    /**
     * 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(StateObservation 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);
    }
Esempio n. 4
0
    public override void AgentReset()
    {
        //NOTE: with the ResetOnDone = false, this is probably not needed.
        //TODO: implement agent reset... eg. reset game?

        if (IsMaxStepReached())
        {
            //Log the result as a timeout.
            runner.LogResult(true);
        }

        lastScore           = 0;
        lastGameObservation = null;

        var academy = FindObjectOfType <MLAgentVGDLAcademy>();

        runner.RunGame(academy.GetNextGameAndLevel());
    }
Esempio n. 5
0
    public void run(StateObservation stateObs)
    {
        state = stateObs;
        grid  = stateObs.getObservationGrid();
        astar = new AStar(this);

        init();
        runAll();

        if (VERBOSE)
        {
            foreach (var pathId in astar.pathCache.Keys)
            {
                var nodes = astar.pathCache[pathId];
                astar.printPath(pathId, nodes);
            }
        }
    }
Esempio n. 6
0
    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);
    }
Esempio n. 7
0
    /**
     * Returns an exact copy of the state observation object.
     *
     * @return a copy of the state observation.
     */
    public StateObservation copy()
    {
        StateObservation copyObs = new StateObservation(model.copy(), this.playerID);

        return(copyObs);
    }
Esempio n. 8
0
 public override VGDLAvatarActions act(StateObservation stateObs, ElapsedCpuTimer elapsedTimer)
 {
     return(stateObs.getAvailableActions().RandomElement());
 }
Esempio n. 9
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(StateObservation stateObs, ElapsedCpuTimer elapsedCpuTimer)
 {
 }
Esempio n. 10
0
 /**
  * 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.
  * Single 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(StateObservation stateObs, ElapsedCpuTimer elapsedTimer);