/// <summary> /// /// </summary> private void Awake() { _weights = GetTileWeights().ToArray(); ValidateWeights(); _selector = new ProbabilitySelector(_weights, new System.Random(_seed)); }
/// <summary> /// /// </summary> private void Awake() { if (_weights.Length != _tileSet.Count) { throw new ArgumentException("The number of weights provided must match the size of the tile set."); } _selector = new ProbabilitySelector(_weights, new System.Random(_seed)); }
/// <summary> /// /// </summary> /// <param name="model"></param> public MLTileSelector(TileSet tileSet, MLSelectorAgent agent, int seed) { if (agent == null) { throw new ArgumentNullException(); } _agent = agent; _selector = new ProbabilitySelector(GetDefaultWeights(tileSet.Count), new Random(seed)); }
/// <summary> /// /// </summary> /// <param name="model"></param> public MLTileSelector(TileModel model, MLSelectorAgent agent, int seed) : base(model) { if (agent == null) { throw new ArgumentNullException(); } _agent = agent; _selector = new ProbabilitySelector(DefaultWeights, new Random(seed)); }
/// <summary> /// /// </summary> /// <param name="model"></param> public ProbabilisticTileSelector(TileModel model, IEnumerable <double> weights, int seed = 1) : base(model) { _weights = weights.ToArray(); if (_weights.Length != model.TileCount) { throw new ArgumentException("The number of weights provided must match the number of tiles in the model."); } _selector = new ProbabilitySelector(_weights, new Random(seed)); }
private Tile.TileType ChooseNextTileType(int dimX, int dimY) { if (dimY >= NumSkyTiles) { int depth = dimY - NumSkyTiles; List <TileProbability> tileProbabilities = new List <TileProbability>(); List <TileGenerationInfo> tileGenInfoList = levelDefinition.tileGenerationInfoList; for (int i = 0; i < tileGenInfoList.Count; i++) { TileProbability tp = new TileProbability( tileGenInfoList[i].tileType, tileGenInfoList[i].baseProbability, tileGenInfoList[i].increaseProbabilityPerRow, tileGenInfoList[i].depthRangeStart, tileGenInfoList[i].depthRangeEnd); tileProbabilities.Add(tp); } ProbabilitySelector probabilitySelector = new ProbabilitySelector(tileProbabilities); return(probabilitySelector.GetTileType(depth)); } return(Tile.TileType.EMPTY); }
public static BehaviorTree.Composite ParserComposite(TreeNode tree, BehaviorTree.Composite parent) { Composite current = null; //Debug.Log(string.Format("NODE:{0} TYPE:{1}",tree.Name,tree.GetType())); #region decoratorNode if (tree is DecoratorNode) { var child = ParserComposite(tree.Children[0], null); current = new Decorator(child); } if (tree is DecoratorNegationNode) { var child = ParserComposite(tree.Children[0], null); current = new DecoratorNegation(child); } if (tree is DecoratorRunUnitlFailureNode) { var child = ParserComposite(tree.Children[0], null); current = new DecoratorRunUnitlFailure(child); } if (tree is DecoratorRunUntilSuccessNode) { var child = ParserComposite(tree.Children[0], null); current = new DecoratorRunUntilSuccess(child); } if (tree is DecoratorTickNode) { var child = ParserComposite(tree.Children[0], null); current = new DecoratorTick(child) { TickTime = (tree as DecoratorTickNode).TickTime }; } if (tree is DecoratorTickUntilSuccessNode) { var child = ParserComposite(tree.Children[0], null); current = new DecoratorTickUntilSuccess(child) { TickTime = (tree as DecoratorTickUntilSuccessNode).TickTime / 1000f }; } if (tree is WaitForSecondsNode) { current = new BWaitForSeconds() { Seconds = (tree as WaitForSecondsNode).Milseconds / 1000f }; } #endregion #region Liner if (tree is LinerNode) { List <Composite> childs = new List <Composite>(); foreach (var i in tree.Children) { childs.Add(ParserComposite(i, null)); } if (tree is ParallelPrioritySelectorNode) { current = new ParallelPrioritySelector(childs.ToArray()); } else if (tree is ParallelSequenceNode) { current = new ParallelSequence(childs.ToArray()); } else if (tree is SequenceNode) { current = new Sequence(childs.ToArray()); } else if (tree is PrioritySelectorNode) { current = new PrioritySelector(childs.ToArray()); } } #endregion #region ProbabilitySelectorNode if (tree is ProbabilitySelectorNode) { List <ProbabilitySelection> randomChilds = new List <ProbabilitySelection>(); foreach (var i in tree.Children) { var item = i as ProbabilitySelectorItemNode; if (item == null) { throw new Exception("ProbabilitySelectorNode's child is not ProbabilitySelectorItemNode"); } var pChild = ParserComposite(item.Children[0], null); randomChilds.Add(new ProbabilitySelection(pChild, (int)item.Probability)); } current = new ProbabilitySelector(randomChilds.ToArray()); } if (tree is ProbabilitySelectorItemNode) { throw new Exception("ProbabilitySelectorItemNode can't be parsed with out parent!"); } #endregion #region Action Type type; if (tree is ActionNode) { if (_ALL_PARSER.TryGetValue(tree.GetType(), out type)) { var item = System.Activator.CreateInstance(type); current = (Composite)item; if (current != null) { (current as INodeParser).Parser(tree); } else { Debug.LogError(string.Format("ITEM:{0} current:{1} TYPE:{2}", item, tree, type)); } } else { Debug.Log(string.Format("Action {0} No Paser!!!", tree.GetType())); } } #endregion if (current != null) { current.Name = tree.Name; //Debug.Log(tree.Name); } else { Debug.Log(string.Format("Action {0} No Paser!!!", tree.GetType())); } //下面解析动作,条件 if (parent == null) { parent = current; } return(parent); }