void Awake() { that = this; entitiesHolder = new GameObject("EntitiesHolder"); entities = new List<GameObject>(); entityPrefab = Resources.Load<GameObject>("Entity"); AntibodyPrefab = Resources.Load<GameObject>("Antibody"); sprites = Resources.LoadAll<Sprite>("BloodCellWhite"); for(int i=0; i < 10; ++i){ GameObject entity = createEntity(new Vector3(2.5f + Random.Range(0.0f, 1.0f), 2, 0)); } }
public EcoSystem() { int boundary = 640; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); FormBorderStyle = FormBorderStyle.FixedToolWindow; StartPosition = FormStartPosition.CenterScreen; ClientSize = new Size(boundary, boundary); iconRegular = CreateIcon(Brushes.Blue); iconZombie = CreateIcon(Brushes.Red); swarm = new Swarm(boundary); timer = new Timer(); timer.Tick += new EventHandler(this.timer_Tick); timer.Interval = 75; timer.Start(); }
private async Task EnsureExchange(Swarm a, Swarm b) { await a.WaitForRunningAsync(); await b.WaitForRunningAsync(); Log.Debug($"Waiting for a[{a.AsPeer}] to distribute... "); await a.DeltaDistributed.WaitAsync(); Log.Debug($"Waiting for b[{b.AsPeer}] to receive a[{a.AsPeer}]..."); await EnsureRecvAsync(b, a.AsPeer); Log.Debug($"Waiting for b[{b.AsPeer}] to distribute..."); await b.DeltaDistributed.WaitAsync(); Log.Debug($"Waiting for a[{a.AsPeer}] to receive b[{b.AsPeer}]..."); await EnsureRecvAsync(a, b.AsPeer); }
private async Task <Task> StartAsync <T>( Swarm swarm, BlockChain <T> blockChain, CancellationToken cancellationToken = default ) where T : IAction, new() { Task task = Task.Run( async() => await swarm.StartAsync( blockChain, 200, cancellationToken ) ); await swarm.WaitForRunningAsync(); return(task); }
public override Vector3 Target(float time) { while (true) { float dbest = Swarm.DistanceToNearest(current); if (dbest <= 0.5f) { currentValid = false; } if (currentValid) { break; } NewTarget(); currentValid = true; } return(current); }
private async Task EnsureRecvAsync(Swarm swarm, Peer peer = null, DateTimeOffset?lastReceived = null) { while (true) { Log.Debug($"Waiting for receive event... [{swarm.AsPeer}]"); await swarm.DeltaReceived.WaitAsync(); Log.Debug($"Event received. [{swarm.AsPeer}]"); if (lastReceived == null) { break; } DateTimeOffset?lastSeen = null; if (peer == null) { lastSeen = swarm.LastReceived; } else { if (swarm.LastSeenTimestamps.ContainsKey(peer)) { lastSeen = swarm.LastSeenTimestamps[peer]; } else { foreach (KeyValuePair <Peer, DateTimeOffset> kv in swarm.LastSeenTimestamps) { if (peer.PublicKey == kv.Key.PublicKey) { lastSeen = kv.Value; break; } } } } if ((lastSeen != null) && (lastSeen >= lastReceived)) { break; } } }
IEnumerator PSO() { // Spawn particles randomly for (int i = 0; i < particleCount; i++) { Vector3 randomPosition = new Vector3(Random.Range(-terrainSize, terrainSize), 0, Random.Range(-terrainSize, terrainSize)); GameObject newSwarm = Instantiate(swarmPrefab, randomPosition, Quaternion.identity); swarms.Add(newSwarm.GetComponent <Swarm>()); } for (int i = 0; i < maxIteration; i++) { // Update All Swarms Fitness foreach (Swarm s in swarms) { s.UpdateFitness(); } // Get Best Swarms and Best Fitness if (bestSwarm != null) { bestSwarm.GetComponent <Renderer>().material = normalMaterial; } bestSwarm = GetBestSwarm(); bestSwarm.GetComponent <Renderer>().material = bestMaterial; bestFitness = bestSwarm.best_fitness; // Move all Swarms foreach (Swarm s in swarms) { if (s != bestSwarm) { s.UpdateVelocity(bestSwarm, cognitionRate, socialRate, terrainSize, durationIteration, false); } else { s.UpdateVelocity(bestSwarm, cognitionRate, socialRate, terrainSize, durationIteration, true); } } infoText.text = "Iteration:" + i + "\nBest Fitness:" + bestFitness; yield return(new WaitForSeconds(durationIteration)); } this.startButton.SetActive(true); }
/// <inheritdoc /> public async Task <IEnumerable <Peer> > FindProvidersAsync( Cid id, int limit = 20, Action <Peer> action = null, CancellationToken cancel = default(CancellationToken)) { var dquery = new DistributedQuery <Peer> { QueryType = MessageType.GetProviders, QueryKey = id.Hash, Dht = this, AnswersNeeded = limit, }; if (action != null) { dquery.AnswerObtained += (s, e) => action.Invoke(e); } // Add any providers that we already know about. var providers = ContentRouter .Get(id) .Select(pid => { return((pid == Swarm.LocalPeer.Id) ? Swarm.LocalPeer : Swarm.RegisterPeer(new Peer { Id = pid })); }); foreach (var provider in providers) { dquery.AddAnswer(provider); } // Ask our peers for more providers. if (limit > dquery.Answers.Count()) { await dquery.RunAsync(cancel).ConfigureAwait(false); } return(dquery.Answers.Take(limit)); }
private async Task EnsureRecvAsync(Swarm swarm, Peer peer = null, DateTimeOffset?lastReceived = null) { Log.Debug($"Waiting to ensure recv... [{swarm.AsPeer}]"); while (true) { await swarm.DeltaReceived.WaitAsync(); DateTimeOffset?lastSeen = null; if (peer == null) { lastSeen = swarm.LastReceived; } else { if (swarm.LastSeenTimestamps.ContainsKey(peer)) { lastSeen = swarm.LastSeenTimestamps[peer]; } else { IEnumerable <KeyValuePair <Peer, DateTimeOffset> > pairs = swarm.LastSeenTimestamps.ToArray(); foreach (KeyValuePair <Peer, DateTimeOffset> kv in pairs) { if (peer.PublicKey == kv.Key.PublicKey) { lastSeen = kv.Value; break; } } } } bool seenLater = (lastReceived is null) || (lastSeen >= lastReceived); if (!(lastSeen is null) && seenLater) { break; } } Log.Debug($"Received. [{swarm.AsPeer}]"); }
public async Task GetTx() { Swarm <DumbAction> swarmA = _swarms[0]; Swarm <DumbAction> swarmB = _swarms[1]; BlockChain <DumbAction> chainB = _blockchains[1]; Transaction <DumbAction> tx = Transaction <DumbAction> .Create( 0, new PrivateKey(), new DumbAction[0] ); chainB.StageTransactions( new Dictionary <Transaction <DumbAction>, bool> { { tx, true } }); chainB.MineBlock(_fx1.Address1); try { await StartAsync(swarmA); await StartAsync(swarmB); Assert.Throws <PeerNotFoundException>( () => swarmB.GetTxsAsync( swarmA.AsPeer, new[] { tx.Id })); await swarmA.AddPeersAsync(new[] { swarmB.AsPeer }); List <Transaction <DumbAction> > txs = await swarmA.GetTxsAsync( swarmB.AsPeer, new[] { tx.Id } ).ToListAsync(); Assert.Equal(new[] { tx }, txs); } finally { await Task.WhenAll( swarmA.StopAsync(), swarmB.StopAsync()); } }
public async Task InitialBlockDownloadStates() { Swarm <DumbAction> minerSwarm = CreateSwarm(); Swarm <DumbAction> receiverSwarm = CreateSwarm(); BlockChain <DumbAction> minerChain = minerSwarm.BlockChain; BlockChain <DumbAction> receiverChain = receiverSwarm.BlockChain; var key = new PrivateKey(); var address1 = key.ToAddress(); var address2 = new PrivateKey().ToAddress(); var action = new DumbAction( address1, "foo", transfer: Tuple.Create <Address, Address, BigInteger>(address1, address2, 10)); minerChain.MakeTransaction(key, new[] { action }); await minerChain.MineBlock(minerSwarm.Address); minerChain.MakeTransaction(key, new[] { new DumbAction(address1, "bar") }); await minerChain.MineBlock(minerSwarm.Address); minerChain.MakeTransaction(key, new[] { new DumbAction(address1, "baz") }); await minerChain.MineBlock(minerSwarm.Address); try { await StartAsync(minerSwarm); await receiverSwarm.AddPeersAsync(new[] { minerSwarm.AsPeer }, null); await receiverSwarm.PreloadAsync(); var state = receiverChain.GetState(address1); Assert.Equal((Text)"foo,bar,baz", state); Assert.Equal(minerChain.BlockHashes, receiverChain.BlockHashes); } finally { await StopAsync(minerSwarm); } }
/// <summary> /// Advertise that we can provide the CID to the X closest peers /// of the CID. /// </summary> /// <param name="cid"> /// The CID to advertise. /// </param> /// <remarks> /// This starts a background process to send the AddProvider message /// to the 4 closest peers to the <paramref name="cid"/>. /// </remarks> public void Advertise(Cid cid) { _ = Task.Run(async() => { int advertsNeeded = 4; var message = new DhtMessage { Type = MessageType.AddProvider, Key = cid.Hash.ToArray(), ProviderPeers = new DhtPeerMessage[] { new DhtPeerMessage { Id = Swarm.LocalPeer.Id.ToArray(), Addresses = Swarm.LocalPeer.Addresses .Select(a => a.WithoutPeerId().ToArray()) .ToArray() } } }; var peers = RoutingTable .NearestPeers(cid.Hash) .Where(p => p != Swarm.LocalPeer); foreach (var peer in peers) { try { using (var stream = await Swarm.DialAsync(peer, this.ToString())) { ProtoBuf.Serializer.SerializeWithLengthPrefix(stream, message, PrefixStyle.Base128); await stream.FlushAsync(); } if (--advertsNeeded == 0) { break; } } catch (Exception) { // eat it. This is fire and forget. } } }); }
public async Task QueryIsCancelled_WhenDhtStops() { var unknownPeer = new MultiHash("QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCxxx"); var swarm = new Swarm { LocalPeer = self }; swarm.RegisterPeerAddress("/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"); swarm.RegisterPeerAddress("/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64"); var dht = new Dht1 { Swarm = swarm }; await dht.StartAsync(); var task = dht.FindPeerAsync(unknownPeer); await Task.Delay(400); await dht.StopAsync(); }
public async Task MultiAddress() { var swarmB = new Swarm { LocalPeer = other }; await swarmB.StartAsync(); var pingB = new Ping1 { Swarm = swarmB }; await pingB.StartAsync(); var peerBAddress = await swarmB.StartListeningAsync("/ip4/127.0.0.1/tcp/0"); var swarm = new Swarm { LocalPeer = self }; await swarm.StartAsync(); var pingA = new Ping1 { Swarm = swarm }; await pingA.StartAsync(); try { await swarm.ConnectAsync(peerBAddress); var result = await pingA.PingAsync(other.Id, 4); Assert.IsTrue(result.All(r => r.Success)); } finally { await swarm.StopAsync(); await swarmB.StopAsync(); await pingB.StopAsync(); await pingA.StopAsync(); } }
public async Task StopAsync() { Swarm <DumbAction> swarm = _swarms[0]; BlockChain <DumbAction> chain = _blockchains[0]; await swarm.StopAsync(); var task = await StartAsync(swarm); Assert.True(swarm.Running); await swarm.StopAsync(); Assert.False(swarm.Running); Assert.False( task.IsFaulted, $"A task was faulted due to an exception: {task.Exception}" ); }
private async Task <Task> StartAsync <T>( Swarm swarm, BlockChain <T> blockChain, int millisecondsDistributeInterval = 1500, CancellationToken cancellationToken = default ) where T : IAction { Task task = Task.Run( async() => await swarm.StartAsync( blockChain, millisecondsDistributeInterval, cancellationToken ) ); await swarm.WaitForRunningAsync(); return(task); }
private Swarm <T> CreateSwarm <T>( BlockChain <T> blockChain, PrivateKey privateKey = null, AppProtocolVersion?appProtocolVersion = null, int tableSize = Kademlia.TableSize, int bucketSize = Kademlia.BucketSize, string host = null, int?listenPort = null, DateTimeOffset?createdAt = null, IEnumerable <IceServer> iceServers = null, DifferentAppProtocolVersionEncountered differentAppProtocolVersionEncountered = null, IEnumerable <PublicKey> trustedAppProtocolVersionSigners = null, SwarmOptions options = null ) where T : IAction, new() { if (host is null && !(iceServers?.Any() ?? false)) { host = IPAddress.Loopback.ToString(); } var swarm = new Swarm <T>( blockChain, privateKey ?? new PrivateKey(), appProtocolVersion ?? DefaultAppProtocolVersion, tableSize, bucketSize, 5, host, listenPort, createdAt, iceServers, differentAppProtocolVersionEncountered, trustedAppProtocolVersionSigners, options); _finalizers.Add(async() => { await StopAsync(swarm); swarm.Dispose(); }); return(swarm); }
public async Task CanGetTx() { Swarm swarmA = _swarms[0]; Swarm swarmB = _swarms[1]; BlockChain <BaseAction> chainA = _blockchains[0]; BlockChain <BaseAction> chainB = _blockchains[1]; Transaction <BaseAction> tx = Transaction <BaseAction> .Make( new PrivateKey(), new PrivateKey().PublicKey.ToAddress(), new BaseAction[] { }, DateTimeOffset.UtcNow ); chainB.StageTransactions(new[] { tx }.ToHashSet()); chainB.MineBlock(_fx1.Address1); try { await StartAsync(swarmA, chainA); await StartAsync(swarmB, chainB); Assert.Throws <PeerNotFoundException>( () => swarmB.GetTxsAsync <BaseAction>( swarmA.AsPeer, new[] { tx.Id })); await swarmA.AddPeersAsync(new[] { swarmB.AsPeer }); List <Transaction <BaseAction> > txs = await swarmA.GetTxsAsync <BaseAction>( swarmB.AsPeer, new[] { tx.Id } ).ToListAsync(); Assert.Equal(new[] { tx }, txs); } finally { await Task.WhenAll( swarmA.StopAsync(), swarmB.StopAsync()); } }
private void button3_Click(object sender, EventArgs e) { int scoutsCount = int.Parse(textBox1.Text); int employees = int.Parse(textBox2.Text); int onlookers = int.Parse(textBox3.Text); int bestPatches = int.Parse(textBox4.Text); int elitePatches = int.Parse(textBox5.Text); int dim = (int)dimensionComboBox.SelectedItem; double patchSize = double.Parse(textBox6.Text); int iterations = 100000; FitnessFunction func = FitnessFunctions.RosenbrocsSaddle; switch (comboBox1.SelectedItem.ToString()) { case "RosenbrocsSaddle": func = FitnessFunctions.RosenbrocsSaddle; break; case "DeJongs": func = FitnessFunctions.DeJongs; break; } comboBox1.Enabled = false; dimensionComboBox.Enabled = false; button1.Enabled = true; button2.Enabled = true; initializeButton.Enabled = false; textBox1.Enabled = false; textBox2.Enabled = false; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = false; textBox6.Enabled = false; Swarm.GetInstance().Initialize(func, dim, iterations, scoutsCount, employees, onlookers, bestPatches, elitePatches, patchSize); sizeLabel.Text = "Swarm size: " + Swarm.GetInstance().Size; }
public async Task InitialBlockDownloadStates() { Swarm <DumbAction> minerSwarm = _swarms[0]; Swarm <DumbAction> receiverSwarm = _swarms[1]; BlockChain <DumbAction> minerChain = _blockchains[0]; BlockChain <DumbAction> receiverChain = _blockchains[1]; var key = new PrivateKey(); var address = key.ToAddress(); minerChain.MakeTransaction(key, new[] { new DumbAction(address, "foo") }); await minerChain.MineBlock(_fx1.Address1); minerChain.MakeTransaction(key, new[] { new DumbAction(address, "bar") }); await minerChain.MineBlock(_fx1.Address1); minerChain.MakeTransaction(key, new[] { new DumbAction(address, "baz") }); await minerChain.MineBlock(_fx1.Address1); try { await StartAsync(minerSwarm); await receiverSwarm.AddPeersAsync(new[] { minerSwarm.AsPeer }, null); var trustedStateValidators = new[] { minerSwarm.Address }.ToImmutableHashSet(); await receiverSwarm.PreloadAsync(trustedStateValidators : trustedStateValidators); await receiverSwarm.PreloadAsync(); var state = receiverChain.GetState(address); Assert.Equal((Text)"foo,bar,baz", state); Assert.Equal(minerChain.BlockHashes, receiverChain.BlockHashes); } finally { await StopAsync(minerSwarm); } }
public async Task BroadcastIgnoreFromDifferentGenesisHash() { var receiverKey = new PrivateKey(); Swarm <DumbAction> receiverSwarm = CreateSwarm(receiverKey); BlockChain <DumbAction> receiverChain = receiverSwarm.BlockChain; var seedStateStore = new TrieStateStore(new MemoryKeyValueStore()); IBlockPolicy <DumbAction> policy = receiverChain.Policy; Block <DumbAction> mismatchedGenesis = new BlockContent <DumbAction> { PublicKey = receiverKey.PublicKey, Timestamp = DateTimeOffset.MinValue, } .Mine(policy.GetHashAlgorithm(0)) .Evaluate(receiverKey, policy.BlockAction, seedStateStore); BlockChain <DumbAction> seedChain = MakeBlockChain( policy, new MemoryStore(), seedStateStore, genesisBlock: mismatchedGenesis); var seedMiner = new PrivateKey(); Swarm <DumbAction> seedSwarm = CreateSwarm(seedChain, seedMiner); try { await StartAsync(receiverSwarm); await StartAsync(seedSwarm); await receiverSwarm.AddPeersAsync(new[] { seedSwarm.AsPeer }, null); Block <DumbAction> block = await seedChain.MineBlock(seedMiner); seedSwarm.BroadcastBlock(block); Assert.NotEqual(seedChain.Tip, receiverChain.Tip); } finally { await StopAsync(seedSwarm); await StopAsync(receiverSwarm); seedSwarm.Dispose(); } }
public void Test() { Swarm g = new Swarm(); IOptiTestFunc f = new Weierstrass(); g.dimension = 10; g.searchSpace = f.SearchSpace; double[] res = g.Opti(f.Func); double val = f.Func(res); Assert.AreEqual(f.MinimumValue, val, 5); g = new Swarm(); f = new SumSquares(); g.dimension = 10; g.searchSpace = f.SearchSpace; res = g.Opti(f.Func); val = f.Func(res); Assert.AreEqual(f.MinimumValue, val, 5); }
public override Vector3 CalculateMove(Agent agent, List <Transform> context, Swarm flock) { if (context.Count == 0) { return(Vector3.zero); } Vector3 cohesionMove = Vector3.zero; foreach (Transform item in context) { cohesionMove += item.position; } cohesionMove /= context.Count; //create offset from agent position cohesionMove -= agent.transform.position; cohesionMove = Vector3.SmoothDamp(agent.transform.forward, cohesionMove, ref currentVelocity, agentSmoothTime); return(cohesionMove); }
private void timer_Tick(object sender, EventArgs e) { label1.Text = "Iterations: " + Swarm.GetInstance().CurrentIteration; label2.Text = "Fittnes: " + Swarm.GetInstance().Fitness; //label3.Text = "Position: " + Swarm.Instance.Position.X + "," + Swarm.Instance.Position.Y; foreach (var curve in zedGraph.GraphPane.CurveList) { curve.Clear(); } Swarm.GetInstance().Run(); AddDataToGraph(zedGraph, Swarm.GetInstance().Agents.Where(a => a.Role == Agent.RoleTypes.Scout).Select(p => p.Position).ToList(), "Scout"); AddDataToGraph(zedGraph, Swarm.GetInstance().Agents.Where(a => a.Role == Agent.RoleTypes.Employed).Select(p => p.Position).ToList(), "Employed"); AddDataToGraph(zedGraph, Swarm.GetInstance().Agents.Where(a => a.Role == Agent.RoleTypes.Onlooker).Select(p => p.Position).ToList(), "Onlooker"); zedGraph.AxisChange(); zedGraph.Invalidate(); }
public async Task AddDiscoveredPeerToRoutingTable() { var swarm = new Swarm { LocalPeer = self }; var dht = new Dht1 { Swarm = swarm }; await dht.StartAsync(); try { var peer = swarm.RegisterPeerAddress("/ip4/127.0.0.1/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h"); Assert.IsTrue(dht.RoutingTable.Contains(peer)); } finally { await dht.StopAsync(); } }
public async Task WorksAsCollection() { Swarm a = _swarms[0]; Swarm b = _swarms[1]; Swarm c = _swarms[2]; // Obtaining swarm's endpoint... await Task.WhenAll( StartAsync(a, _blockchains[0]), StartAsync(b, _blockchains[1]), StartAsync(c, _blockchains[2])); Assert.Empty(a); Assert.Empty(b); Assert.Empty(c); a.Add(b.AsPeer); a.Add(c.AsPeer); Assert.Contains(b.AsPeer, a); Assert.Contains(c.AsPeer, a); Peer[] peers = null; Assert.Throws <ArgumentNullException>(() => { a.CopyTo(peers, 0); }); peers = new Peer[3]; Assert.Throws <ArgumentOutOfRangeException>(() => { a.CopyTo(peers, -1); }); Assert.Throws <ArgumentException>(() => { a.CopyTo(peers, 2); }); a.CopyTo(peers, 1); Assert.Equal(new Peer[] { null, b.AsPeer, c.AsPeer }, peers); }
public async Task ExchangeWithIceServer() { Uri turnUrl = FactOnlyTurnAvailable.TurnUri; string username = FactOnlyTurnAvailable.Username; string password = FactOnlyTurnAvailable.Password; IEnumerable <IceServer> iceServers = new[] { new IceServer( urls: new[] { turnUrl }, username: username, credential: password), }; var seed = new Swarm(new PrivateKey(), 1, host: "localhost"); var swarmA = new Swarm(new PrivateKey(), 1, iceServers: iceServers); var swarmB = new Swarm(new PrivateKey(), 1, iceServers: iceServers); try { await StartAsync(seed, _blockchains[0]); await StartAsync(swarmA, _blockchains[1]); await StartAsync(swarmB, _blockchains[2]); await swarmA.AddPeersAsync(new[] { seed.AsPeer }); await swarmB.AddPeersAsync(new[] { seed.AsPeer }); await EnsureExchange(swarmA, swarmB); Assert.Contains(swarmA.AsPeer, swarmB); Assert.Contains(swarmB.AsPeer, swarmA); } finally { await Task.WhenAll( seed.StopAsync(), swarmA.StopAsync(), swarmB.StopAsync()); } }
private static async Task StartSwarmAsync( Swarm <AppAgnosticAction> swarm, IEnumerable <Peer> seeds, CancellationToken cancellationToken) { if (swarm is null) { Startup.PreloadedSingleton = true; return; } try { Console.Error.WriteLine("Bootstrapping."); await swarm.BootstrapAsync( seeds, 5000, 5000, cancellationToken : cancellationToken ); } catch (TimeoutException) { Console.Error.WriteLine("No any neighbors."); } // Since explorer does not require states, turn off trustedPeer option. var trustedPeers = ImmutableHashSet <Address> .Empty; Console.Error.WriteLine("Starts preloading."); await swarm.PreloadAsync( dialTimeout : TimeSpan.FromSeconds(15), trustedStateValidators : trustedPeers, cancellationToken : cancellationToken ); Console.Error.WriteLine("Finished preloading."); Startup.PreloadedSingleton = true; await swarm.StartAsync(cancellationToken : cancellationToken); }
private void Start() { buttons = FindObjectOfType <ButtonUpdater>(); target = FindObjectOfType <Swarm>(); //player = new PlayerStats("Player", 100, 2, 0, 1); dataManager = FindObjectOfType <DataManager>(); combat = FindObjectOfType <CombatTurn>(); player = dataManager.GetData <PlayerStats>("player"); inv = dataManager.GetData <Inventory>("inventory"); gameObject.name = player.name; //transform.position = new Vector3() //player.pos.x = transform.position.x; //player.pos.y = transform.position.y; //player.pos.z = transform.position.z; //dataManager.SetData(Application.dataPath + "/gameData/player/", "player.json", player); }
public async Task CanBeCancelled() { Swarm swarm = _swarms[0]; Blockchain <BaseAction> chain = _blockchains[0]; var cts = new CancellationTokenSource(); try { await swarm.InitContextAsync(); var at = Task.Run( async() => await swarm.RunAsync(chain, 250, cts.Token)); cts.Cancel(); await Assert.ThrowsAsync <TaskCanceledException>(async() => await at); } finally { await swarm.DisposeAsync(); } }
private void Start() { switch (targetSelector) { case targetType.PLAYER: Player player = FindObjectOfType <Player>(); txtName.text = player.GetName(); setHpTxt(player.GetHp()); player.hpChanged += setHpTxt; player.GetLvl(); break; case targetType.SWARM: Swarm swarm = FindObjectOfType <Swarm>(); txtName.text = swarm.GetName(); setHpTxt(swarm.GetHp()); swarm.hpChanged += setHpTxt; swarm.GetLvl(); break; } }
private void SetState(BeeState state) { _state = state; switch (_state) { case BeeState.Idle: BeeNPC.EnableGatherText(true); _targetSwarm = null; SetIdleAnimation(); break; case BeeState.Follow: BeeNPC.EnableGatherText(false); SetFlyingAnimation(); break; case BeeState.Dead: BeeNPC.EnableGatherText(false); break; } }
public Swarm SW; // Final swarm #endregion Fields #region Constructors public Result() { SW=new Swarm(Constants.SMax); error=new Fitness(Constants.fMax); }
public Result(int maxSwarmSize) { SW=new Swarm(maxSwarmSize); }
// Use this for initialization void Awake() { // Set the singleton S = this; // Get components rigid = GetComponent<Rigidbody>(); rigid.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ; sc = GetComponent<SphereCollider>(); soundTrigger = transform.Find("Noise Trigger").GetComponent<SphereCollider>(); }
void Awake() { _instance = this; swarm = new Swarm(); }