public void InitTree(TyStateAnalyzer analyzer, POGame root, List <PlayerTask> options) { _sortedNodes.Clear(); _explorableNodes.Clear(); _nodesToEstimate.Clear(); _analyzer = analyzer; _rootGame = root; //var initialResults = TyStateUtility.GetSimulatedGames(root, options, _analyzer); for (int i = 0; i < options.Count; i++) { PlayerTask task = options[i]; var node = new TyTaskNode(this, _analyzer, task, 0.0f); //end turn is pretty straight forward, should not really be looked at later in the simulations, just simulate once and keep the value: if (task.PlayerTaskType == PlayerTaskType.END_TURN) { TySimResult sim = TyStateUtility.GetSimulatedGame(root, task, _analyzer); node.AddValue(sim.value); } else { _explorableNodes.Add(node); _sortedNodes.Add(node); } _nodesToEstimate.Add(task, node); } }
public TyTaskNode(TySimTree tree, TyStateAnalyzer analyzer, PlayerTask task, float totalValue) { _tree = tree; _analyzer = analyzer; _task = task; _totalValue = totalValue; _visits = 0; }
public static TySimResult GetSimulatedGame(POGame parent, PlayerTask task, TyStateAnalyzer analyzer) { POGame simulatedState = parent.Simulate(new List <PlayerTask>() { task })[task]; float stateValue = GetStateValue(parent, simulatedState, task, analyzer); return(new TySimResult(simulatedState, task, stateValue)); }
private TycheAgentCompetition(TyStateWeights weights, bool heroBasedWeights, int episodeMultiplier, bool adjustEpisodeMultiplier) { _defaultEpisodeMultiplier = episodeMultiplier; _curEpisodeMultiplier = episodeMultiplier; _heroBasedWeights = heroBasedWeights; _analyzer = new TyStateAnalyzer(weights); _simTree = new TySimTree(); _random = new Random(); AdjustEpisodeMultiplier = adjustEpisodeMultiplier; }
/// <summary> Estimates how good the given child state is. </summary> public static float GetStateValue(POGame parent, POGame child, PlayerTask task, TyStateAnalyzer analyzer) { float valueFactor = 1.0f; TyState myState = null; TyState enemyState = null; Controller player = null; Controller opponent = null; //it's a buggy state, mostly related to equipping/using weapons on heroes etc. //in this case use the old state and estimate the new state manually: if (child == null) { player = parent._game.CurrentPlayer; opponent = parent._game.CurrentOpponent; myState = TyState.FromSimulatedGame(parent, player, task); enemyState = TyState.FromSimulatedGame(parent, opponent, null); //if the correction failes, assume the task is x% better/worse: if (!TyState.CorrectBuggySimulation(myState, enemyState, parent, task)) { valueFactor = 1.25f; } } else { player = child._game.CurrentPlayer; opponent = child._game.CurrentOpponent; //happens sometimes even with/without TURN_END, idk if (!analyzer.IsMyPlayer(player)) { player = child._game.CurrentOpponent; opponent = child._game.CurrentPlayer; } myState = TyState.FromSimulatedGame(child, player, task); enemyState = TyState.FromSimulatedGame(child, opponent, null); } TyDebug.Assert(analyzer.IsMyPlayer(player)); TyDebug.Assert(!analyzer.IsMyPlayer(opponent)); return(analyzer.GetStateValue(myState, enemyState, player, opponent, task) * valueFactor); }
/// <summary> Returns a list of simulated games with the given parameters. </summary> public static List <TySimResult> GetSimulatedGames(POGame parent, List <PlayerTask> options, TyStateAnalyzer analyzer) { List <TySimResult> stateTaskStructs = new List <TySimResult>(); for (int i = 0; i < options.Count; i++) { stateTaskStructs.Add(GetSimulatedGame(parent, options[i], analyzer)); } return(stateTaskStructs); }
/// <summary> Returns N sorted simulated TySimResults for the given start state. </summary> public static List <TySimResult> GetSimulatedBestTasks(int numTasks, POGame game, List <PlayerTask> options, TyStateAnalyzer analyzer) { return(GetSortedBestTasks(numTasks, GetSimulatedGames(game, options, analyzer))); }
/// <summary> Returns N sorted simulated TySimResults for the given start state. </summary> public static List <TySimResult> GetSimulatedBestTasks(int numTasks, POGame game, TyStateAnalyzer analyzer) { return(GetSimulatedBestTasks(numTasks, game, game._game.CurrentPlayer.Options(), analyzer)); }