Пример #1
0
    public static KeyCode[] getKeys(this VGDLAvatarActions action)
    {
        switch (action)
        {
        case VGDLAvatarActions.ACTION_NIL:
            return(new[] { KeyCode.None, KeyCode.None });

        case VGDLAvatarActions.ACTION_UP:
            return(new[] { KeyCode.UpArrow, KeyCode.W });

        case VGDLAvatarActions.ACTION_LEFT:
            return(new[] { KeyCode.LeftArrow, KeyCode.A });

        case VGDLAvatarActions.ACTION_DOWN:
            return(new[] { KeyCode.DownArrow, KeyCode.S });

        case VGDLAvatarActions.ACTION_RIGHT:
            return(new[] { KeyCode.RightArrow, KeyCode.D });

        case VGDLAvatarActions.ACTION_USE:
            return(new[] { KeyCode.Space, KeyCode.LeftShift });

        case VGDLAvatarActions.ACTION_ESCAPE:
            return(new[] { KeyCode.Escape, KeyCode.Escape });

//            case AvatarActions.ACTION_UP_LEFT:
//            case AvatarActions.ACTION_UP_RIGHT:
//            case AvatarActions.ACTION_DOWN_LEFT:
//            case AvatarActions.ACTION_DOWN_RIGHT:
//                return new[] {KeyCode.None, KeyCode.None};
        default:
            throw new ArgumentOutOfRangeException("action", action, null);
        }
    }
Пример #2
0
 public static Vector2 getDirection(this VGDLAvatarActions action)
 {
     // Probably better to use .equals() instead of == to test for equality,
     // but not necessary for the current call hierarchy of this method
     if (action.Equals(VGDLAvatarActions.ACTION_UP))
     {
         return(VGDLUtils.VGDLDirections.UP.getDirection());
     }
     if (action.Equals(VGDLAvatarActions.ACTION_DOWN))
     {
         return(VGDLUtils.VGDLDirections.DOWN.getDirection());
     }
     if (action.Equals(VGDLAvatarActions.ACTION_LEFT))
     {
         return(VGDLUtils.VGDLDirections.LEFT.getDirection());
     }
     if (action.Equals(VGDLAvatarActions.ACTION_RIGHT))
     {
         return(VGDLUtils.VGDLDirections.RIGHT.getDirection());
     }
     if (action.Equals(VGDLAvatarActions.ACTION_NIL))
     {
         return(VGDLUtils.VGDLDirections.NIL.getDirection());
     }
     return(VGDLUtils.VGDLDirections.NONE.getDirection());
 }
Пример #3
0
    /**
     * Logs a single action
     * @param action the action to log.
     */
    public void logAction(VGDLAvatarActions action)
    {
        lastAction = action;

        if (!string.IsNullOrEmpty(this.actionFile) && SHOULD_LOG)
        {
            allActions.Add(action);
        }
    }
Пример #4
0
 /**
  * Advances the forward model using the action supplied.
  * @param action
  */
 public void advance(VGDLAvatarActions action)
 {
     if (!isEnded)
     {
         //apply player action
         updateAvatars(action, 0);
         //update all the other sprites
         tick();
         //update game state
         advance_aux();
     }
 }
Пример #5
0
    /**
     * Calls update(this) in avatar sprites. It uses the action received as the action of the avatar.
     * Doesn't update disabled avatars.
     * @param action Action to be performed by the avatar for this game tick.
     */
    protected void updateAvatars(VGDLAvatarActions action, int playerID)
    {
        var a = avatars[playerID];

        if (!a.is_disabled())
        {
            //apply action to correct avatar
            a.preMovement();
            a.updateAvatar(this, false, new List <VGDLAvatarActions> {
                action
            });
            avatarLastAction[playerID] = action;
        }
    }
Пример #6
0
 /**
  * Advances the forward model using the actions supplied.
  * @param actions array of actions of all players (index in array corresponds
  *                to playerID).
  */
 public void advance(VGDLAvatarActions[] actions)
 {
     if (!isEnded)
     {
         //apply actions of all players
         for (int i = 0; i < actions.Length; i++)
         {
             VGDLAvatarActions a = actions[i]; // action
             updateAvatars(a, i);              // index in array actions is the playerID
         }
         //update all other sprites in the game
         tick();
         //update game state
         advance_aux();
     }
     //Debug.Log(isMultiGameOver());
 }
Пример #7
0
    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);
    }
Пример #8
0
    public static VGDLAvatarActions ReverseAction(this VGDLAvatarActions value)
    {
        switch (value)
        {
        case VGDLAvatarActions.ACTION_DOWN:
            return(VGDLAvatarActions.ACTION_UP);

        case VGDLAvatarActions.ACTION_UP:
            return(VGDLAvatarActions.ACTION_DOWN);

        case VGDLAvatarActions.ACTION_RIGHT:
            return(VGDLAvatarActions.ACTION_LEFT);

        case VGDLAvatarActions.ACTION_LEFT:
            return(VGDLAvatarActions.ACTION_RIGHT);

        default:
            return(VGDLAvatarActions.ACTION_NIL);
        }
    }
Пример #9
0
 /**
  * Advances the state using the action passed as the move of the agent.
  * It updates all entities in the game. It modifies the object 'this' to
  * represent the next state after the action has been executed and all
  * entities have moved.
  * <p/>
  * Note: stochastic events will not be necessarily the same as in the real game.
  *
  * @param action agent action to execute in the next cycle.
  */
 public void advance(VGDLAvatarActions action)
 {
     model.advance(action);
 }
Пример #10
0
 public static bool isMoving(this VGDLAvatarActions value)
 {
     return(value == VGDLAvatarActions.ACTION_UP || value == VGDLAvatarActions.ACTION_DOWN ||
            value == VGDLAvatarActions.ACTION_LEFT || value == VGDLAvatarActions.ACTION_RIGHT);
 }