//If b == true then you are shooting along X // if false, you are shooting along Y private void checkWumpus(int i, bool b) { if (b == true) { if (entityMap[i, _player.PosY] != null && entityMap[i, _player.PosY].ENTITY_ASSETNAME == "Wumpus") { entityMap[i, _player.PosY] = null; _player.Score += boardX * boardY * 4; _player.playerLog.Add("Player slayed the Wumpus! +" + boardX * boardY * 4 + " Points"); _player.listUpdated = true; if (QLearning) { currentRewardState = RewardState.KilledWumpus; // reward - DMC } } } else { if (QLearning) { currentRewardState = RewardState.MissedWumpus; // reward - DMC } if (entityMap[_player.PosX, i] != null && entityMap[_player.PosX, i].ENTITY_ASSETNAME == "Wumpus") { entityMap[_player.PosX, i] = null; _player.Score += boardX * boardY * 4; _player.playerLog.Add("Player slayed the Wumpus! +" + boardX * boardY * 4 + " Points"); _player.listUpdated = true; if (QLearning) { currentRewardState = RewardState.KilledWumpus; // reward - DMC } } } }
/// <summary> /// Get action result reward percept. /// See Russell & Norvig page 237 /// </summary> /// <returns></returns> public double GetRewardPercept(RewardState rewardState) { double reward; switch (rewardState) { case RewardState.PlayerWon: reward = 3000.0; break; case RewardState.PlayerDied: reward = -1000.0; break; case RewardState.KilledWumpus: reward = 100.0; break; case RewardState.MissedWumpus: reward = -10.0; break; case RewardState.PickedUpGold: reward = 1000.0; break; case RewardState.Playing: reward = 0.0; break; case RewardState.TriedImpossibleAction: reward = -5.0; break; case RewardState.FoundGold: reward = 400.0; break; case RewardState.FoundBaseWithGold: reward = 2000.0; break; default: reward = 0.0; break; } return(reward); }
private void changeState(RewardState newState) { switch (newState) { case RewardState.INVISIBLE: setRenders(isVisible: false); break; case RewardState.READY_TO_ACTIVATE: setRenders(isVisible: true); internalState = newState; if (hasValidParameter) { animController.SetBool(hashParamIsCollected, value: false); } if (InteractionObj != null) { InteractionObj.SetActive(value: true); } break; case RewardState.COLLECTED_TODAY: setRenders(isVisible: true); internalState = newState; if (hasValidParameter) { animController.SetBool(hashParamIsCollected, value: true); } if (InteractionObj != null) { InteractionObj.SetActive(value: false); } break; case RewardState.NONE: break; } }
public RegisterRewardVm(RewardState state, int dayIndex, List <long> rewardConfig) { State = state; DayIndex = dayIndex; RewardConfig = rewardConfig; }
public void UpdateGame(GameTime gametime) { //Updates the player _player.Update(gametime, mBoard[(int)_player.PosX, _player.PosY]); this.gameInfo.SetStatus(_player.playerLoc); //Checks if a Transition was just made, if so prepares for the next transition if (boardTransition == false && _player.transition == false) { boardTransition = true; } screenTransition(); //Checks if a player is between tiles, currently also manages if a player is moving into a tile that they would die in if (_player.isBetweenTiles()) { try { mBoard[(int)_player.DestinationX, _player.DestinationY]._explored = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY] != null && _player.goingToDie == false) { entityMap[(int)_player.DestinationX, _player.DestinationY].visible = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY].Kill == true) { _player.goingToDie = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY].ENTITY_ASSETNAME == "Wumpus") { _player.playerLog.Add("Player Killed by Wumpus!"); } else _player.playerLog.Add("Player killed by Pit!"); _player.listUpdated = true; _player.Score = 0; // Record reward for Q learning & play again - DMC if (QLearning) { EndGameCarryingGold = PlayerCarryingGold; EndGameRewardState = RewardState.PlayerDied; EndGameAction = LastAction; EndGameX = _player.PosX; EndGameY = _player.PosY; currentRewardState = RewardState.PlayerDied; PlayAgain(); } } } } catch (Exception ex) { _player.playerLog.Add("Error: " + ex.Message); } } //If the player fired an arrow, check which direction it was fired, then check if a wumpus was // within 5ish blocks in that direction (might make an infinite arrow range option later, on larger maps it could make searching // for many wumpus' more reasonable) if (_player.firedArrow == true) { if (_player.lastAction.CurrentCommand == Action.Command.ShootLeft) { int check; if (_player.PosX - 5 >= 0) check = _player.PosX - 5; else check = 0; for (int x = _player.PosX; x >= check; x--) { checkWumpus(x, true); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootRight) { int check; if (_player.PosX + 5 <= boardX) check = _player.PosX + 5; else check = boardX; for (int x = _player.PosX; x < check; x++) { checkWumpus(x, true); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootUp) { int check; if (_player.PosY - 5 >= 0) check = _player.PosY - 5; else check = 0; for (int y = _player.PosY; y >= check; y--) { checkWumpus(y, false); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootDown) { int check; if (_player.PosY + 5 <= boardY) check = _player.PosY + 5; else check = boardY; for (int y = _player.PosY; y < boardY; y++) { checkWumpus(y, false); } } _player.ArrowReset(); } //If picking_up and there is treasure, pick it up if (_player.picking_up == true && entityMap[_player.PosX, _player.PosY] != null && entityMap[_player.PosX, _player.PosY].ENTITY_ASSETNAME == "Treasure") { entityMap[_player.PosX, _player.PosY] = null; _player.Score += boardX * boardY * 2; _player.playerLog.Add("Player picked up the Gold! +" + boardX * boardY * 2 + " Points"); _player.listUpdated = true; // Record reward for Q learning - DMC if (QLearning) { LastCarryingGold = false; currentRewardState = RewardState.PickedUpGold; } } // Record reward for Q learning - DMC else if (QLearning && _player.PosX == 0 && _player.PosY == (boardY - 1) && Game.Instance.PlayerCarryingGold) { _player.playerLog.Add("Player reached Base with GOLD! "); // _player.listUpdated = true; currentRewardState = RewardState.FoundBaseWithGold; LastCarryingGold = true; } else { _player.picking_up = false; // Record reward for Q learning - DMC if (QLearning) { if (Game.Instance.GetTile(_player.PosX, _player.PosY)._gold && entityMap[_player.PosX, _player.PosY] != null && !PlayerCarryingGold && currentRewardState == RewardState.Playing) { LastCarryingGold = false; currentRewardState = RewardState.FoundGold; } _player.playerLog.Add(currentRewardState.ToString()); } } //If player is going to die, and they are at destination (wumpus or pit), Kill them if (_player.goingToDie == true && _player.DestinationX == _player.PosX && _player.DestinationY == _player.PosY) { _player.dead(); // Record reward for Q learning - DMC if (QLearning) { EndGameCarryingGold = PlayerCarryingGold; EndGameRewardState = RewardState.PlayerDied; EndGameAction = LastAction; EndGameX = _player.PosX; EndGameY = _player.PosY; currentRewardState = RewardState.PlayerDied; _player.playerLog.Add(currentRewardState.ToString()); } } //If player's score < 0 kill them if (_player.Score < 0) { _player.dead(); _player.goingToDie = true; _player.playerLog.Add("Player Starved to Death!"); _player.listUpdated = true; // Record reward for Q learning - DMC if (QLearning) { // If you starve, don't apply the penalty to this action... just terminate the trial - DMC currentRewardState = RewardState.Playing; _player.playerLog.Add(currentRewardState.ToString()); PlayAgain(); } } //Updates the List and score! if (_player.listUpdated == true) { gameInfo.UpdateList(); gameInfo.UpdateScore(_player.Score); _player.listUpdated = false; } //Calculates the lighting calcLight(); }
/// <summary> /// Get action result reward percept. /// See Russell & Norvig page 237 /// </summary> /// <returns></returns> public double GetRewardPercept(RewardState rewardState) { double reward; switch (rewardState) { case RewardState.PlayerWon: reward = 3000.0; break; case RewardState.PlayerDied: reward = -1000.0; break; case RewardState.KilledWumpus: reward = 100.0; break; case RewardState.MissedWumpus: reward = -10.0; break; case RewardState.PickedUpGold: reward = 1000.0; break; case RewardState.Playing: reward = 0.0; break; case RewardState.TriedImpossibleAction: reward = -5.0; break; case RewardState.FoundGold: reward = 400.0; break; case RewardState.FoundBaseWithGold: reward = 2000.0; break; default: reward = 0.0; break; } return reward; }
//If b == true then you are shooting along X // if false, you are shooting along Y private void checkWumpus(int i, bool b) { if (b == true) { if (entityMap[i, _player.PosY] != null && entityMap[i, _player.PosY].ENTITY_ASSETNAME == "Wumpus") { entityMap[i, _player.PosY] = null; _player.Score += boardX * boardY * 4; _player.playerLog.Add("Player slayed the Wumpus! +" + boardX * boardY * 4 + " Points"); _player.listUpdated = true; if (QLearning) currentRewardState = RewardState.KilledWumpus; // reward - DMC } } else { if (QLearning) currentRewardState = RewardState.MissedWumpus; // reward - DMC if (entityMap[_player.PosX, i] != null && entityMap[_player.PosX, i].ENTITY_ASSETNAME == "Wumpus") { entityMap[_player.PosX, i] = null; _player.Score += boardX * boardY * 4; _player.playerLog.Add("Player slayed the Wumpus! +" + boardX * boardY * 4 + " Points"); _player.listUpdated = true; if (QLearning) currentRewardState = RewardState.KilledWumpus; // reward - DMC } } }
public void UpdateGame(GameTime gametime) { //Updates the player _player.Update(gametime, mBoard[(int)_player.PosX, _player.PosY]); this.gameInfo.SetStatus(_player.playerLoc); //Checks if a Transition was just made, if so prepares for the next transition if (boardTransition == false && _player.transition == false) { boardTransition = true; } screenTransition(); //Checks if a player is between tiles, currently also manages if a player is moving into a tile that they would die in if (_player.isBetweenTiles()) { try { mBoard[(int)_player.DestinationX, _player.DestinationY]._explored = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY] != null && _player.goingToDie == false) { entityMap[(int)_player.DestinationX, _player.DestinationY].visible = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY].Kill == true) { _player.goingToDie = true; if (entityMap[(int)_player.DestinationX, _player.DestinationY].ENTITY_ASSETNAME == "Wumpus") { _player.playerLog.Add("Player Killed by Wumpus!"); } else { _player.playerLog.Add("Player killed by Pit!"); } _player.listUpdated = true; _player.Score = 0; // Record reward for Q learning & play again - DMC if (QLearning) { EndGameCarryingGold = PlayerCarryingGold; EndGameRewardState = RewardState.PlayerDied; EndGameAction = LastAction; EndGameX = _player.PosX; EndGameY = _player.PosY; currentRewardState = RewardState.PlayerDied; PlayAgain(); } } } } catch (Exception ex) { _player.playerLog.Add("Error: " + ex.Message); } } //If the player fired an arrow, check which direction it was fired, then check if a wumpus was // within 5ish blocks in that direction (might make an infinite arrow range option later, on larger maps it could make searching // for many wumpus' more reasonable) if (_player.firedArrow == true) { if (_player.lastAction.CurrentCommand == Action.Command.ShootLeft) { int check; if (_player.PosX - 5 >= 0) { check = _player.PosX - 5; } else { check = 0; } for (int x = _player.PosX; x >= check; x--) { checkWumpus(x, true); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootRight) { int check; if (_player.PosX + 5 <= boardX) { check = _player.PosX + 5; } else { check = boardX; } for (int x = _player.PosX; x < check; x++) { checkWumpus(x, true); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootUp) { int check; if (_player.PosY - 5 >= 0) { check = _player.PosY - 5; } else { check = 0; } for (int y = _player.PosY; y >= check; y--) { checkWumpus(y, false); } } else if (_player.lastAction.CurrentCommand == Action.Command.ShootDown) { int check; if (_player.PosY + 5 <= boardY) { check = _player.PosY + 5; } else { check = boardY; } for (int y = _player.PosY; y < boardY; y++) { checkWumpus(y, false); } } _player.ArrowReset(); } //If picking_up and there is treasure, pick it up if (_player.picking_up == true && entityMap[_player.PosX, _player.PosY] != null && entityMap[_player.PosX, _player.PosY].ENTITY_ASSETNAME == "Treasure") { entityMap[_player.PosX, _player.PosY] = null; _player.Score += boardX * boardY * 2; _player.playerLog.Add("Player picked up the Gold! +" + boardX * boardY * 2 + " Points"); _player.listUpdated = true; // Record reward for Q learning - DMC if (QLearning) { LastCarryingGold = false; currentRewardState = RewardState.PickedUpGold; } } // Record reward for Q learning - DMC else if (QLearning && _player.PosX == 0 && _player.PosY == (boardY - 1) && Game.Instance.PlayerCarryingGold) { _player.playerLog.Add("Player reached Base with GOLD! "); // _player.listUpdated = true; currentRewardState = RewardState.FoundBaseWithGold; LastCarryingGold = true; } else { _player.picking_up = false; // Record reward for Q learning - DMC if (QLearning) { if (Game.Instance.GetTile(_player.PosX, _player.PosY)._gold&& entityMap[_player.PosX, _player.PosY] != null && !PlayerCarryingGold && currentRewardState == RewardState.Playing) { LastCarryingGold = false; currentRewardState = RewardState.FoundGold; } _player.playerLog.Add(currentRewardState.ToString()); } } //If player is going to die, and they are at destination (wumpus or pit), Kill them if (_player.goingToDie == true && _player.DestinationX == _player.PosX && _player.DestinationY == _player.PosY) { _player.dead(); // Record reward for Q learning - DMC if (QLearning) { EndGameCarryingGold = PlayerCarryingGold; EndGameRewardState = RewardState.PlayerDied; EndGameAction = LastAction; EndGameX = _player.PosX; EndGameY = _player.PosY; currentRewardState = RewardState.PlayerDied; _player.playerLog.Add(currentRewardState.ToString()); } } //If player's score < 0 kill them if (_player.Score < 0) { _player.dead(); _player.goingToDie = true; _player.playerLog.Add("Player Starved to Death!"); _player.listUpdated = true; // Record reward for Q learning - DMC if (QLearning) { // If you starve, don't apply the penalty to this action... just terminate the trial - DMC currentRewardState = RewardState.Playing; _player.playerLog.Add(currentRewardState.ToString()); PlayAgain(); } } //Updates the List and score! if (_player.listUpdated == true) { gameInfo.UpdateList(); gameInfo.UpdateScore(_player.Score); _player.listUpdated = false; } //Calculates the lighting calcLight(); }
private void DisplayExperienceGain(GameTime gameTime) { if (RewardState == RewardState.ExperienceToBeAwarded) { int experienceGained = AwardExperience(); _textPanel.BattleText.FirstLine = "Gained " + experienceGained + " experience!"; RewardState = RewardState.ExperienceAwarded; } _textPanel.TextPromptArrow.WaitingForTextToAppear(gameTime, 2000); if (_textPanel.TextPromptArrow.State == TextArrowState.Clicked) { EndStage = EndStage.DisplayExit; } }
public Battle(Game1 game, Trainer alliedTrainer, Trainer enemyTrainer, bool trainerBattle) : base(game) { Camera = new Camera(game.ScreenRectangle) {Zoom = 4f}; Camera.LockToCenter(game.ScreenRectangle); _trainerBattle = trainerBattle; CurrentPhase = BattlePhase.Starting; AlliedTrainer = alliedTrainer; AlliedTrainer.PrepareForCombat(RenderingPosition.Ally); EnemyTrainer = enemyTrainer; EnemyTrainer.PrepareForCombat(RenderingPosition.Enemy); foreach (var pokemon in EnemyTrainer.PokemonSet.Where(pokemon => pokemon.CurrentHealth > 0)) { ActiveEnemyPokemon = new PokemonWrapper(game, pokemon); break; } foreach (var pokemon in AlliedTrainer.PokemonSet.Where(pokemon => pokemon.CurrentHealth > 0)) { ActiveAlliedPokemon = new PokemonWrapper(game, pokemon); break; } ActiveAlliedPokemon.PokemonInstance.PrepareForCombat(RenderingPosition.Ally); ActiveEnemyPokemon.PokemonInstance.PrepareForCombat(RenderingPosition.Enemy); // Initiate state BattleConclusion = BattleConclusion.Undecided; EndStage = EndStage.DisplayResult; CurrentPlayerTurnPhase = PlayerTurnPhase.ChoosingAction; RewardState = RewardState.ExperienceToBeAwarded; LoadContent(); }
public DiamondRewardState(RewardState state) : this(state.PointsBalance, state.RewardAccount) { }