public void Clear() { var emptyTargets = new Target[] { new Multiple(new Member[0]) }; _selector = new IndexSelector <Target>(emptyTargets); OnTargetChanged.Publish(); }
private void UpdateUi() { if (_isConfirmingTurn) { _shouldHighlight = false; } var activeCards = cards.ShownCards; _indexSelector = new IndexSelector <CardPresenter>(activeCards, Math.Min(activeCards.Length - 1, _lastIndex)); if (activeCards.Any(c => c.HasCard)) { while (!_indexSelector.Current.HasCard) { _indexSelector.MovePrevious(); } } _lastIndex = _indexSelector.Index; if (_shouldHighlight) { EnableHighlight(); } else { DisableHighlight(); } }
public BattlePlayerTargetingState WithPossibleTargets(Target[] targets) { _selector = new IndexSelector <Target>(targets); OnTargetChanged.Publish(); Message.Publish(new TargetChanged(Current)); return(this); }
private TypeDefinition CheckArrayIndexSelector( IndexSelector indexSelector, TypeDefinition type) { if (!(type is ArrayTypeDefinition arrayType)) { _parser.NotifyErrorListeners(indexSelector.Token, "Array reference expected", null); return(SimpleTypeDefinition.VoidType); } indexSelector.IndexDefinition = ConstantSolver.Solve(indexSelector.IndexDefinition, _parser.currentBlock); if (indexSelector.IndexDefinition.TargetType.Type != BaseTypes.Int) { _parser.NotifyErrorListeners(indexSelector.Token, "Array reference must be INTEGER", null); return(SimpleTypeDefinition.VoidType); } if (indexSelector.IndexDefinition.IsConst) { var ce = (ConstantExpression)indexSelector.IndexDefinition; int index = ce.ToInt32(); if (index < 1 || index > arrayType.Size) { _parser.NotifyErrorListeners(indexSelector.Token, "Array index out of bounds", null); return(SimpleTypeDefinition.VoidType); } } return(arrayType.ArrayType); // types match }
private void Awake() { for (var i = 0; i < buttonParent.transform.childCount; i++) { buttonParent.transform.GetChild(i).gameObject.SetActive(false); } _cursor = new IndexSelector <TextCommandButton>(InstantiateButtons()); }
void Awake() { _pages = new IndexSelector <Page>(pages); foreach (var p in pages) { p.Init(MovePrevious, MoveNext, PerformAction); p.gameObject.SetActive(false); } _pages.Current.gameObject.SetActive(true); }
public FollowPath(Entity entity, Entity target, float followDistance, ECSInstance ecsInstance) { //perform all needed setup f_ThisEntity = entity; f_FollowDistance = followDistance; f_Target = target; s_EcsInstance = ecsInstance; tooClose = new Conditional(isTooClose); targetMoved = new Conditional(hasTargetMoved); pathFound = new Conditional(hasPathBeenFound); reachedCell = new Conditional(hasReachedCell); reachedTarget = new Conditional(hasReachedTarget); isNewPath = new Conditional(hasNewPath); moveToCell = new BehaviorAction(moveTowardsCell); calcPath = new BehaviorAction(calculatePath); initPathfinder = new BehaviorAction(initializePathfinder); getNextCell = new BehaviorAction(getNextPathCell); setPath = new BehaviorAction(setNewPath); getPath = new BehaviorAction(getCurrentPath); updatePosition = new BehaviorAction(updateTargetPosision); reset = new BehaviorAction(resetPathfinder); animate = new BehaviorAction(updateAnimation); Sequence pSeqA = new Sequence(initPathfinder, calcPath); Selector pSelA = new Selector(new Inverter(targetMoved), new Inverter(reachedTarget), new Inverter(reset), calcPath); //Selector pSelA = new Selector(new Inverter(targetMoved));//, new Inverter(reset), calcPath); Selector pSelB = new Selector(new Inverter(pathFound), getPath); Selector pSelC = new Selector(new Inverter(isNewPath), setPath); Selector pSelD = new Selector(new Inverter(reachedCell), getNextCell); Selector pSelE = new Selector(reachedTarget, moveToCell); //Sequence pSeqC = new Sequence(pSelE, reset, calcPath); Sequence pSeqB = new Sequence(new Inverter(tooClose), updatePosition, pSelA, pSelB, pSelC, pSelD, pSelE, animate); //setup root node, choose initialization phase or pathing/movement phase root = new IndexSelector(switchBehaviors, pSeqA, pSeqB); f_Behavior = new Behavior(root); f_PositionMapper = new ComponentMapper(new Position(), ecsInstance); f_VelocityMapper = new ComponentMapper(new Velocity(), ecsInstance); f_HeadingMapper = new ComponentMapper(new Heading(), ecsInstance); f_GameMapMapper = new ComponentMapper(new GameMap(), ecsInstance); f_ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance); f_MapDebugMapper = new ComponentMapper(new MapDebug(), ecsInstance); f_SpatialMapper = new ComponentMapper(new SpatialPartition(), ecsInstance); f_SpriteMapper = new ComponentMapper(new Sprite(), ecsInstance); f_PathMapper = new ComponentMapper(new APath(), ecsInstance); }
private void safeSetSelector(IndexSelector selector, int current) { if (selector.count <= current) { selector.current = selector.count - 1; } else { selector.current = current; } }
private Sequence AggressiveAI() { BehaviorAction stop = new BehaviorAction(aiToTarget.Stop); Sequence sequenceShootWhileMove = new Sequence(Shoot(), DoTransitionBehavior()); RepeatUntilFail followPathLoop = new RepeatUntilFail(sequenceShootWhileMove); RepeatUntilFail stopLoop = new RepeatUntilFail(stop); IndexSelector minDistance = new IndexSelector(MinDistanceReached, stopLoop, followPathLoop); return(new Sequence(Shoot(), new StatefulSequence(CalculatePath(aiToTarget.CalculatePath), minDistance))); }
private void InitilizeIndexSelector() { IndexSelector.Items.Clear(); IIndexResolver resolver = ResolverFactory.GetIndexResolver(IndexType); List <string> indexNames = resolver.GetIndexNames(); indexNames.Insert(0, String.Empty); IndexSelector.DataSource = indexNames; IndexSelector.DataBind(); IndexSelector.Enabled = true; }
private void Update() { if (!_isDirty) { return; } _isDirty = false; if (cards.ShownCards.Length < 1) { return; } _indexSelector = new IndexSelector <GameObject>(cards.ShownCards); if (_shouldHighlight) { EnableHighlight(); } }
private StatefulSequence DoTransitionBehavior() { BehaviorAction move = new BehaviorAction(aiToTarget.Move); Conditional stopped = new Conditional(aiToTarget.StoppedCheck); BehaviorAction fail = new BehaviorAction(ReturnFail); BehaviorAction respawn = new BehaviorAction(aiToTarget.Respawn); BehaviorAction die = new BehaviorAction(Die); BehaviorAction nextTransition = new BehaviorAction(aiToTarget.NextTransition); BehaviorAction waitForGrounded = new BehaviorAction(ReturnRunning); Sequence stopOrMove = new Sequence(new Inverter(stopped), move); StatefulSelector fallingBehavior = new StatefulSelector(respawn, die); IndexSelector fallingOrStanding = new IndexSelector(FallOrStandSelect, fail, fallingBehavior, waitForGrounded); StatefulSelector moveSelect = new StatefulSelector(stopOrMove, fallingOrStanding); return(new StatefulSequence(nextTransition, moveSelect)); }
/// <summary> /// /// </summary> /// <param name="root"></param> public Behavior(IndexSelector root) { _Root = root; }
public IndexSelectorTests() { _sut = new IndexSelector(); }
private void Awake() => _narratorSounds = new IndexSelector <AudioClip>(narratorSounds);
public WanderingEnemyBehavior(Entity entity, ECSInstance ecsInstance) { w_ECSInstance = ecsInstance; w_ThisEntity = entity; w_CurrentState = STATE_INITIALIZE; //setup all conditionals tooClose = new Conditional(tooCloseToTarget); tooFar = new Conditional(tooFarFromTarget); detectedHostile = new Conditional(hasDetectedHostile); collided = new Conditional(hasCollided); healthy = new Conditional(isHealthy); targetDead = new Conditional(isTargetDead); //setup all behavior actions init = new BehaviorAction(initialize); setStateWander = new BehaviorAction(stateChangeWander); setStatePursue = new BehaviorAction(stateChangePursue); setStateFlee = new BehaviorAction(stateChangeFlee); choseDirection = new BehaviorAction(chooseRandomDirection); collideCorrection = new BehaviorAction(correctHeadingForCollision); move = new BehaviorAction(moveViaHeading); towardsHeading = new BehaviorAction(headingTowardsTarget); awayHeading = new BehaviorAction(headingAwayTarget); fireShot = new BehaviorAction(fireAtTarget); animate = new BehaviorAction(updateAnimation); playDetected = new BehaviorAction(playDetectedSound); playFlee = new BehaviorAction(playFleeSound); Sequence setPursue = new Sequence(playDetected, setStatePursue); Sequence setFlee = new Sequence(playFlee, setStateFlee); //initialize sequence Sequence initSeq = new Sequence(init, setStateWander); //if not healthy, flee Selector healthSel = new Selector(healthy, new Inverter(setFlee)); //if target is dead, wander Selector deadTargetSel = new Selector(new Inverter(targetDead), setStateWander); //if not collided, then chose a new direction every second Sequence randWalk = new Sequence(new Inverter(collided), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, choseDirection)); //if not randomly walking, correct for a collision Selector walkOrCorrect = new Selector(randWalk, collideCorrection); //wander sequence, while no hostiles detected, walk around randomly Sequence wanderSeq = new Sequence(new Inverter(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, detectedHostile)), walkOrCorrect, move, animate); //Sequence wanderSeq = new Sequence(new Inverter(detectedHostile), walkOrCorrect, move, animate); //wander or change to pursue state88 Selector wanderSel2 = new Selector(wanderSeq, new Inverter(setPursue)); //move towards your target Sequence moveTowards = new Sequence(towardsHeading, move, animate); //move away from your target Sequence moveAway = new Sequence(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate); //if too far from your target, move towards it Selector moveTooFar = new Selector(new Inverter(tooFar), moveTowards); //if too close to your target, move away from it Selector moveTooClose = new Selector(new Inverter(tooClose), moveAway); //if target isnt dead and you're not too far and not too close, shoot at it Sequence attackSeq = new Sequence(deadTargetSel, new Inverter(tooFar), new Inverter(tooClose), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, fireShot), animate); //move towards or away from your target, then attemp to attack it Sequence pursAttackSeq1 = new Sequence(moveTooFar, moveTooClose, attackSeq); //as long as your healthy, pursue and attack your target Sequence pursAttackSeq2 = new Sequence(healthSel, pursAttackSeq1); //flee sequence, while unhealthy, flee Sequence fleeSeq = new Sequence(new Inverter(healthy), deadTargetSel, new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate); Selector fleeSel = new Selector(fleeSeq, setStateWander); //setup root selector w_Root = new IndexSelector(switchBehaviors, initSeq, wanderSel2, pursAttackSeq2, fleeSel); //set tree reference w_Behavior = new Behavior(w_Root); //initialize mappers w_PositionMapper = new ComponentMapper(new Position(), ecsInstance); w_VelocityMapper = new ComponentMapper(new Velocity(), ecsInstance); w_HeadingMapper = new ComponentMapper(new Heading(), ecsInstance); w_ColidableMapper = new ComponentMapper(new MapCollidable(), ecsInstance); w_ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance); w_SpatialMapper = new ComponentMapper(new SpatialPartition(), ecsInstance); //w_SpriteMapper = new ComponentMapper(new Sprite(), ecsInstance); w_FactionMapper = new ComponentMapper(new Factions(), ecsInstance); w_HealthMapper = new ComponentMapper(new Health(), ecsInstance); w_EquipmentMapper = new ComponentMapper(new Equipment(), ecsInstance); w_ItemMapper = new ComponentMapper(new Item(), ecsInstance); w_AggroMapper = new ComponentMapper(new Aggrivation(), ecsInstance); }
private MWNumericArray GetIndexTimeSeries(IndexType type, int yieldspan) { IndexSelector ids = new IndexSelector(); IndexGroup idgSWI = null;; switch (type) { case IndexType.SWIndustry: idgSWI = ids.GetSWIndustryIndex(); break; case IndexType.ZXIndustry: idgSWI = ids.GetZXIndustryIndex(); break; case IndexType.JCIndustry: idgSWI = ids.GetJCIndustryIndex(); break; case IndexType.ZZSize: idgSWI = ids.GetZZSizeIndex(); break; case IndexType.JCSize: idgSWI = ids.GetJCSizeIndex(); break; case IndexType.SWProfit: idgSWI = ids.GetSWProfitIndex(); break; case IndexType.JCStyle: idgSWI = ids.GetJCStyleIndex(); break; default: throw new Exception("未知的指数类型"); } idgSWI.SetDatePeriod(this.StartDate, this.EndDate); idgSWI.LoadData(DataInfoType.SecurityInfo); idgSWI.LoadData(DataInfoType.TradingPrice); int rows = idgSWI.SecurityHoldings[0].TradingPrice.AdjustedTimeSeries.Count; int cols = idgSWI.SecurityHoldings.Count; double[,] aryi = new double[rows, cols]; for (int irow = 0; irow < rows; irow++) { for (int icol = 0; icol < cols; icol++) { //从降序排列转换为升序排列 Nullable <double> d = null; switch (yieldspan) { case 1: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay1; break; case 2: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay2; break; case 3: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay3; break; case 4: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay4; break; case 5: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay5; break; default: d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay1; break; } if (d == null) { aryi[rows - irow - 1, icol] = 0; } else { aryi[rows - irow - 1, icol] = d.Value; } } } MWNumericArray x = aryi; return(x); }
/// <summary> /// </summary> /// <param name="root"></param> public Behavior(IndexSelector root) { _root = root; }
public void CreateAndStartDefensiveAI() { IndexSelector root = new IndexSelector(AIAlive, DefensiveAI(), DiiSeq(), new BehaviorAction(ReturnRunning)); behavior = new Behavior(root); }