コード例 #1
0
 /// <summary>
 /// Get new precepts after the last action taken.
 /// </summary>
 /// <param name="newRewardState">Last reward state (e.g. Player Won)</param>
 /// <param name="reward">Double value of the immediate reward</param>
 private void GetNewPercepts(out Game.RewardState newRewardState, out double reward)
 {
     if (GameEndedAfterLastAction())
     {
         newRewardState = Game.Instance.EndGameRewardState;
         reward         = Game.Instance.GetRewardPercept(Game.Instance.EndGameRewardState);
         Game.Instance.AddToPlayerLog("Got percepts. Reward is " + reward.ToString() + ". New state is " + Game.Instance.EndGameRewardState.ToString());
         DisplayAllQValues(Game.Instance.EndGameCarryingGold);
         lastCarryingGold = Game.Instance.EndGameCarryingGold;
     }
     else
     {
         newRewardState = Game.Instance.CurrentRewardState;
         reward         = Game.Instance.GetRewardPercept(Game.Instance.CurrentRewardState);
         Game.Instance.AddToPlayerLog("Got percepts. Reward is " + reward.ToString() + ". New state is " + Game.Instance.CurrentRewardState.ToString());
         DisplayAllQValues(Game.Instance.PlayerCarryingGold);
         lastCarryingGold = Game.Instance.PlayerCarryingGold;
     }
 }
コード例 #2
0
ファイル: QLearningAgent.cs プロジェクト: ksucase/wumpus
        /// <summary>
        /// Get next action from the QLearning Agent given the current location tile.
        /// </summary>
        /// <param name="currentTile">Player's current tile</param>
        /// <returns>Action</returns>
        public override Action GetAction(Tile currentTile)
        {
            if (currentTile == null) return null;

            Action newAction = null;
            Game.RewardState rewardState;
            double reward;

            GetNewPercepts(out rewardState, out reward);

            if (Game.Instance.IsSmartTrial)
            {
                newAction = GetSmartAction(currentTile);
            }
            else  // learning
            {
                UpdateLearningBasedOnLastAction(currentTile, reward);
                newAction = GetLearningAction(currentTile);
            }
            lastTile = currentTile;
            lastAction = newAction;
            lastRewardState = rewardState;
            return newAction;
        }