Beispiel #1
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(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);
    }
Beispiel #2
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);
    }