public float GetStateValue(TyState playerState, TyState enemyState, Controller player, Controller opponent, PlayerTask task) { TyDebug.Assert(IsMyPlayer(player)); TyDebug.Assert(!IsMyPlayer(opponent)); if (EstimateSecretsAndSpells) { TySecretUtil.CalculateValues(playerState, enemyState, player, opponent); TySecretUtil.EstimateValues(enemyState, opponent); var spell = task.TryGetSpell(); if (spell != null && !spell.IsSecret) { TySpellUtil.CalculateValues(playerState, enemyState, player, opponent, task, spell); } } if (HasLost(enemyState)) { return(Single.PositiveInfinity); } else if (HasLost(playerState)) { return(Single.NegativeInfinity); } return(GetStateValueFor(playerState, enemyState) - GetStateValueFor(enemyState, playerState)); }
public TyStateWeights(params float[] defaultValues) : this() { TyDebug.Assert(defaultValues.Length == (int)WeightType.Count); for (int i = 0; i < _weights.Length; i++) { _weights[i] = defaultValues[i]; } }
/// <summary> Estimates how good the given child state is. </summary> public static float GetStateValue(POGame.POGame parent, POGame.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.CurrentPlayer; opponent = parent.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.CurrentPlayer; opponent = child.CurrentOpponent; //happens sometimes even with/without TURN_END, idk if (!analyzer.IsMyPlayer(player)) { player = child.CurrentOpponent; opponent = child.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); }
public bool IsMyPlayer(Controller c) { TyDebug.Assert(OwnPlayerId != -1); return(c.PlayerId == OwnPlayerId); }