示例#1
0
 public void Update(DestinyHistoricalStatsValue?other)
 {
     if (other is null)
     {
         return;
     }
     if (StatId != other.StatId)
     {
         StatId = other.StatId;
         OnPropertyChanged(nameof(StatId));
     }
     if (!Basic.DeepEquals(other.Basic))
     {
         Basic.Update(other.Basic);
         OnPropertyChanged(nameof(Basic));
     }
     if (!Pga.DeepEquals(other.Pga))
     {
         Pga.Update(other.Pga);
         OnPropertyChanged(nameof(Pga));
     }
     if (!Weighted.DeepEquals(other.Weighted))
     {
         Weighted.Update(other.Weighted);
         OnPropertyChanged(nameof(Weighted));
     }
     if (ActivityId != other.ActivityId)
     {
         ActivityId = other.ActivityId;
         OnPropertyChanged(nameof(ActivityId));
     }
 }
示例#2
0
        public override void OnRecv(Weighted <Int64> record, T time)
        {
            Int64[][] accum;

            if (recentTimeValid && recentTime.Equals(time))
            {
                accum = recentAccum;
            }
            else
            {
                if (!accumulations.TryGetValue(time, out accum))
                {
                    accum = new Int64[65536][];

                    accumulations.Add(time, accum);

                    this.ScheduleAt(time);
                }

                recentAccum     = accum;
                recentTime      = time;
                recentTimeValid = true;
            }

            var index = record.record / parts;

            if (accum[index / 65536] == null)
            {
                accum[index / 65536] = new Int64[65536];
            }

            accum[index / 65536][index % 65536] += record.weight;
        }
示例#3
0
        private static void TestRandomReverse(string display, List <double> pop, int iterations)
        {
            // Random Reverse test

            int[] collectorINT = new int[pop.Count];
            Console.WriteLine("\n- - -");
            Console.WriteLine($">> {display} {String.Join(", ", pop)}");
            for (int i = 0; i < iterations; i++)
            {
                int result = Weighted.RandomReverse(pop);
                collectorINT[result]++;
            }

            // Eyeball test
            int lowest = int.MaxValue;

            foreach (var item in collectorINT)
            {
                lowest = Math.Min(lowest, item);
            }

            List <double> redacted = new List <double>();
            int           counter  = 0;

            foreach (var item in collectorINT)
            {
                redacted.Add(item / lowest + pop[counter]);
                counter++;
            }

            Console.WriteLine(String.Join(", ", collectorINT));
            Console.WriteLine(String.Join(", ", redacted));
        }
示例#4
0
        public virtual void OnInput2(Weighted <S2> entry, T time)
        {
            var k = key2(entry.record);

            BinaryKeyIndices state;

            if (!keyIndices.TryGetValue(k, out state))
            {
                state = new BinaryKeyIndices();
            }

            if (state.unprocessed1 == 0 && state.unprocessed2 == 0)
            {
                if (!this.KeysToProcessAtTimes.ContainsKey(time))
                {
                    this.KeysToProcessAtTimes.Add(time, new HashSet <K>());
                }

                this.KeysToProcessAtTimes[time].Add(k);
            }

            inputTrace2.Introduce(ref state.unprocessed2, value2(entry.record), entry.weight, internTable.Intern(time));

            keyIndices[k] = state;
        }
    private SpawnPattern getRandomPattern()
    {
        Dictionary <int, float> weights = new Dictionary <int, float>();

        weights.Add(0, 25f);
        weights.Add(1, 5.0f);
        weights.Add(2, 40f);
        weights.Add(3, 30f);
        var pick = Weighted.getWeightedPick(weights);

        switch (pick)
        {
        case 0:
            return(getDiagonalPattern());

        case 1:
            return(getLanePattern());

        case 2:
            return(getDumbPattern());

        case 3:
            return(getThickyLinePattern());

        default:
            return(null);
        }
    }
        public bool Equals(DestinyHistoricalStatsValue input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     StatId == input.StatId ||
                     (StatId != null && StatId.Equals(input.StatId))
                     ) &&
                 (
                     Basic == input.Basic ||
                     (Basic != null && Basic.Equals(input.Basic))
                 ) &&
                 (
                     Pga == input.Pga ||
                     (Pga != null && Pga.Equals(input.Pga))
                 ) &&
                 (
                     Weighted == input.Weighted ||
                     (Weighted != null && Weighted.Equals(input.Weighted))
                 ) &&
                 (
                     ActivityId == input.ActivityId ||
                     (ActivityId.Equals(input.ActivityId))
                 ));
        }
示例#7
0
        public void Base_ConditionalProbability3()
        {
            var ex = from rain in new Bernoulli(0.2)
                     from sprinkler in new Bernoulli(0.2)
                     from w in new Bernoulli(0.05)
                     let wet = rain | sprinkler ? true : w
                               where wet
                               select Tuple.Create(rain, sprinkler);

            var tmp1   = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted <Tuple <bool, bool> >[] {
                new Weighted <Tuple <bool, bool> >()
                {
                    Value = Tuple.Create(false, false), Probability = 0.08163265306122447
                },
                new Weighted <Tuple <bool, bool> >()
                {
                    Value = Tuple.Create(false, true), Probability = 0.4081632653061224
                },
                new Weighted <Tuple <bool, bool> >()
                {
                    Value = Tuple.Create(true, false), Probability = 0.4081632653061224
                },
                new Weighted <Tuple <bool, bool> >()
                {
                    Value = Tuple.Create(true, true), Probability = 0.1020408163265306
                },
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
            {
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
            }
        }
示例#8
0
        public void Base_ConditionalProbability()
        {
            var ex = from a in new Bernoulli(0.1)
                     from b in new Bernoulli(0.1)
                     from c in new Bernoulli(0.1)
                     let d = Convert.ToInt32(a) + Convert.ToInt32(b) + Convert.ToInt32(c)
                             where d >= 2
                             select a;

            var tmp1 = ex.Inference().Support().OrderBy(k => k.Value);
            var tmp2 = ex.SampledInference(10000).Support().OrderBy(k => k.Value);

            var result = new Weighted <bool>[] {
                new Weighted <bool>()
                {
                    Value = false, Probability = 0.3214285714285714
                },
                new Weighted <bool>()
                {
                    Value = true, Probability = 0.6785714285714285
                },
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
            {
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
            }

            foreach (var item in tmp2.Zip(result, Tuple.Create))
            {
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
            }
        }
示例#9
0
        public static void TestBalance()
        {
            int listCount = 10;
            int listSize  = 2;
            List <List <int> > collectionsList      = new List <List <int> >();
            List <int>         controlCollectionOne = new List <int> {
                3, 1
            };
            List <int> controlCollectionTwo = new List <int> {
                2, 1
            };

            collectionsList.Add(controlCollectionOne);
            collectionsList.Add(controlCollectionTwo);

            Random rnd = new Random();

            for (int countC = 0; countC < listCount - 3; countC++)
            {
                List <int> newCollection = new List <int>();
                for (int countS = 0; countS < listSize; countS++)
                {
                    newCollection.Add(rnd.Next(0, 11));
                }
                Console.WriteLine();
                collectionsList.Add(newCollection);
            }

            foreach (List <int> collection in collectionsList)
            {
                Console.WriteLine($"{String.Join(", ", collection)} : balance {Weighted.Balance(collection, false)}");
                Console.WriteLine($"{String.Join(", ", collection)} : balance {Weighted.Balance(collection, true)}");
                Console.WriteLine("- - -");
            }
        }
示例#10
0
文件: Join.cs 项目: xyuan/Naiad
        public override void OnInput1(Weighted <S1> entry, T time)
        {
            //Console.WriteLine("Join Recv1");

            var k = key1(entry.record);
            var v = value1(entry.record);

            var state = new JoinKeyIndices();

            if (!JoinKeys.TryGetValue(k, out state))
            {
                state = new JoinKeyIndices();
            }

            if (!inputShutdown2)//!this.inputImmutable2)
            {
                inputTrace1.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed1);
                inputTrace1.Introduce(ref state.processed1, v, entry.weight, internTable.Intern(time));
            }

            if (inputShutdown1)
            {
                Console.Error.WriteLine("Error in Join input shutdown1");
            }

            if (state.processed2 != 0)
            {
                inputTrace2.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed2);

                times.Clear();
                inputTrace2.EnumerateTimes(state.processed2, times);

                for (int i = 0; i < times.Count; i++)
                {
                    differences2.Clear();
                    inputTrace2.EnumerateDifferenceAt(state.processed2, times.Array[i], differences2);
                    var newTime = time.Join(internTable.times[times.Array[i]]);

                    var output = this.Output.GetBufferForTime(newTime);

                    for (int j = 0; j < differences2.Count; j++)
                    {
                        if (differences2.Array[j].weight != 0)
                        {
                            output.Send(resultSelector(k, v, differences2.Array[j].record).ToWeighted(entry.weight * differences2.Array[j].weight));
                        }
                    }
                }
            }

            if (state.IsEmpty)
            {
                JoinKeys.Remove(k);
            }
            else
            {
                JoinKeys[k] = state;
            }
        }
示例#11
0
 public bool DeepEquals(DestinyHistoricalStatsValue?other)
 {
     return(other is not null &&
            StatId == other.StatId &&
            (Basic is not null ? Basic.DeepEquals(other.Basic) : other.Basic is null) &&
            (Pga is not null ? Pga.DeepEquals(other.Pga) : other.Pga is null) &&
            (Weighted is not null ? Weighted.DeepEquals(other.Weighted) : other.Weighted is null) &&
            ActivityId == other.ActivityId);
 }
示例#12
0
文件: Join.cs 项目: xyuan/Naiad
        public override void OnInput2(Weighted <S2> entry, T time)
        {
            var k = key2(entry.record);
            var v = value2(entry.record);

            var index = k / parts;

            if (JoinKeys[index / 65536] == null)
            {
                JoinKeys[index / 65536] = new JoinIntKeyIndices[65536];
            }

            var state = JoinKeys[index / 65536][index % 65536];

            if (!inputShutdown1)
            {
                inputTrace2.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed2);
                inputTrace2.Introduce(ref state.processed2, v, entry.weight, internTable.Intern(time));
            }

            if (inputShutdown2)
            {
                Console.Error.WriteLine("Error in Join; input2 shutdown but recv'd input1");
            }

            if (state.processed1 != 0)
            {
                inputTrace1.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed1);

                times.Clear();
                inputTrace1.EnumerateTimes(state.processed1, times);

                for (int i = 0; i < times.Count; i++)
                {
                    differences1.Clear();
                    inputTrace1.EnumerateDifferenceAt(state.processed1, times.Array[i], differences1);
                    var newTime = time.Join(internTable.times[times.Array[i]]);

                    var output = this.Output.GetBufferForTime(newTime);

                    for (int j = 0; j < differences1.Count; j++)
                    {
                        if (differences1.Array[j].weight != 0)
                        {
                            output.Send(resultSelector(k, differences1.Array[j].record, v).ToWeighted(entry.weight * differences1.Array[j].weight));
                        }
                    }
                }
            }

            JoinKeys[index / 65536][index % 65536] = state;
        }
    public void GenerateItems()
    {
        if (store.items.Length != 0)
        {
            //go through all the item spawn points in the transforms children, to instantiate the prefab and the set its properties using InitItem
            for (int i = 0; i < itemSpawnPositions.childCount; i++)
            {
                ItemController item = Instantiate(itemPrefab, itemSpawnPositions.GetChild(i).position, transform.rotation);

                item.InitItem((Item)Weighted.WeightedPick(store.items), discount); //set the item's data to a randomly (weighted) pick from the items available to spawn in the store
            }
        }
    }
示例#14
0
        private static void TestRandom(string display, List <double> dist, int iterations)
        {
            // Random test

            double[] collectorINT = new double[dist.Count];
            Console.WriteLine("\n- - -");
            Console.WriteLine($">> {display} {String.Join(", ", dist)}");
            for (int i = 0; i < iterations; i++)
            {
                double result = Weighted.Random(dist);
                collectorINT[(int)result]++;
            }
            Console.WriteLine(String.Join(", ", collectorINT));
        }
示例#15
0
        public virtual void OnInput2(Weighted <S2> entry, T time)
        {
            var k = key2(entry.record);

            var index = (int)(k / this.Stage.Placement.Count);

            if (keyIndices[index / 65536] == null)
            {
                keyIndices[index / 65536] = new BinaryKeyIndices[65536];
            }

            keysToProcess.Add(index);

            inputTrace2.Introduce(ref keyIndices[index / 65536][index % 65536].unprocessed2, value2(entry.record), entry.weight, internTable.Intern(time));
        }
示例#16
0
        public void BaseNestedInference()
        {
            var ex = from x in new Flip(0.5)
                     from y in Inner(x)
                     where !y
                     select x;

            var tmp1 = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted<bool>[] {
                new Weighted<bool>() { Value = false, Probability = 0.1666666666666666 },
                new Weighted<bool>() { Value = true, Probability = 0.8333333333333334},
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
        }
示例#17
0
        private void OnInput(Weighted <R> entry, T time)
        {
            this.Output.Send(entry, time);

            if (action != null)
            {
                list.Add(entry.ToNaiadRecord(time));
            }

            if (count == 0 || leastTime.CompareTo(time) > 0)
            {
                leastTime = time;
            }

            count++;
        }
示例#18
0
        public void BaseNestedInference2()
        {
            var ex = from x in new Flip(0.5)
                     let inner                     = from y in new Flip(0.5)
                                           let tmp = x ? 1.0 : y ? 0.9 : 0.1
                                                     from z in new Bernoulli(tmp)
                                                     where z
                                                     select y

                                                     let groups = from q in inner.Support()
                                                                  group q by q.Value into summary
                                                                  let prob = summary.Select(k => k.Probability).Aggregate((a, b) => a + b)
                                                                             select Tuple.Create(summary.Key, prob)

                                                                             let norm = (from item in groups select item.Item2).Sum()

                                                                                        let normalized = from g in groups
                                                                                                         select new Weighted <bool>()
            {
                Value       = g.Item1,
                Probability = g.Item2 / norm
            }

            let inferred = new Multinomial <bool>(normalized.ToList())

                           from y in inferred
                           where !y
                           select x;

            var tmp1   = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted <bool>[] {
                new Weighted <bool>()
                {
                    Value = false, Probability = 0.1666666666666666
                },
                new Weighted <bool>()
                {
                    Value = true, Probability = 0.8333333333333334
                },
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
            {
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
            }
        }
        public override void OnInput2(Weighted <T> input2)
        {
            IntersectState state;

            var key = input2.record;

            var present = states.TryGetValue(input2.record, out state);

            if (!present)
            {
                state = new IntersectState();
            }

            var oldmin = Math.Min(state.val1, state.val2);

            state.val2 += input2.weight;

            var newmin = Math.Min(state.val1, state.val2);

            if (oldmin != newmin)
            {
                Send(new Weighted <T>(key, newmin - oldmin));
            }

            if (state.val1 == 0.0 && state.val2 == 0.0)
            {
                if (present)
                {
                    states.Remove(key);
                }
            }
            else
            {
                if (!present)
                {
                    states.Add(key, state);
                }
                else
                {
                    states[key] = state;
                }
            }
        }
示例#20
0
    void Start()
    {
        if (SoundSwitch)
        {
            SoundSwitch.Status = Prefs.SoundStatus;
        }

        string board = Progress.Data.Board;

        for (int i = 0; i < Columns; i++)
        {
            for (int j = 0; j < Rows; j++)
            {
                ItemCube cube = CreateCube(i, j);
                int      idx  = i * Columns + j;
                if (!string.IsNullOrEmpty(board) && board.Length > idx)
                {
                    int cl = 0;
                    if (int.TryParse(board[idx].ToString(), out cl))
                    {
                        cube.SetColor(cl);
                    }

                    //Debug.Log(board[idx].ToString());
                }

                Board.Add(BoardIndex(i, j), cube);
            }
        }
        score = Progress.Data.Score;
        if (ScoreText)
        {
            ScoreText.text = score.ToString();
        }

        //Create weighted list
        WeightColors.Add(Weighted.Create(0.5f, 1));
        WeightColors.Add(Weighted.Create(2, 2));
        WeightColors.Add(Weighted.Create(2, 3));
        WeightColors.Add(Weighted.Create(0.5f, 4));

        NewMove();
    }
示例#21
0
        public virtual void OnInput1(Weighted <S1> entry, T time)
        {
            var k = key1(entry.record);

            BinaryKeyIndices state;

            if (!keyIndices.TryGetValue(k, out state))
            {
                state = new BinaryKeyIndices();
            }

            if (state.unprocessed1 == 0 && state.unprocessed2 == 0)
            {
                keysToProcess.Add(k);
            }

            inputTrace1.Introduce(ref state.unprocessed1, value1(entry.record), entry.weight, internTable.Intern(time));

            keyIndices[k] = state;
        }
示例#22
0
    private void SpawnStores(Transform[] locations, GameObject[] prefabs, ExitStore[] interiors)
    {
        for (int i = 0; i < locations.Length; i++)
        {
            GameObject newStore = Instantiate(prefabs[Random.Range(0, prefabs.Length)], locations[i].position, transform.rotation);

            //set up door connection between exteriors and interiors
            DoorController storeDoor = newStore.GetComponentInChildren <DoorController>();
            interiors[StoreId - 1].door = storeDoor.transform;

            //Select the store type and store discount
            //cast the weighted to be storeType as it derives from Weigted and we dont need the weighted attribute after selecting the store type
            StoreType selectedStore    = (StoreType)Weighted.WeightedPick(storeArray.stores);
            Discount  selectedDiscount = (Discount)Weighted.WeightedPick(discounts);

            //set up store exterior by setting the sign sprites to the one stored in the StoreType asset
            SignEditor[] signs = newStore.GetComponentsInChildren <SignEditor>();
            foreach (SignEditor sign in signs)
            {
                //set the type of store sign
                if (sign.signType == SignTypes.store)
                {
                    sign.SetSprite(selectedStore.logo);
                }
                else if (sign.signType == SignTypes.sale)
                {
                    sign.SetSprite(selectedDiscount.sign);
                }
            }

            //set up the store interior by setting the type for the generation
            InteriorGenerator storeInterior = interiors[StoreId - 1].GetComponent <InteriorGenerator>();
            storeInterior.store    = selectedStore;
            storeInterior.discount = selectedDiscount;
            storeInterior.GenerateItems();

            storeDoor.storeId = StoreId++; //after setting the storeId post-increment the static variable for the next store
        }
    }
示例#23
0
        public static void TestRandom()
        {
            int        counter = 10;
            List <int> weights = new List <int>();

            for (int count = 0; count < counter; count++)
            {
                weights.Add(count % 3);
            }
            Console.WriteLine(String.Join(", ", weights));

            int[] result = new int[counter];
            for (int count = 0; count < counter; count++)
            {
                result[count] = 0;
            }

            for (int count = 0; count < counter * 100; count++)
            {
                result[Weighted.Random(weights)]++;
            }
            Console.WriteLine(String.Join(", ", result));
        }
示例#24
0
        public void BaseNestedInference()
        {
            var ex = from x in new Flip(0.5)
                     from y in Inner(x)
                     where !y
                     select x;

            var tmp1   = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted <bool>[] {
                new Weighted <bool>()
                {
                    Value = false, Probability = 0.1666666666666666
                },
                new Weighted <bool>()
                {
                    Value = true, Probability = 0.8333333333333334
                },
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
            {
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
            }
        }
示例#25
0
        private void OnRecv(Weighted <S> record, T time)
        {
            Dictionary <S, Int64> accum;

            if (recentTimeValid && recentTime.Equals(time))
            {
                accum = recentAccum;
            }
            else
            {
                if (!accumulations.TryGetValue(time, out accum))
                {
                    accum = new Dictionary <S, Int64>();
                    accumulations.Add(time, accum);

                    this.NotifyAt(time);
                }

                recentAccum     = accum;
                recentTime      = time;
                recentTimeValid = true;
            }

            // update dictionary, adding/removing if needed
            Int64 count;

            accum.TryGetValue(record.record, out count);
            if (count + record.weight == 0)
            {
                accum.Remove(record.record);
            }
            else
            {
                accum[record.record] = count + record.weight;
            }
        }
示例#26
0
    public static Map <Vertex, Weighted <Vertex> > Dijkstra <Vertex>(Vertex start, Func <Vertex, IEnumerable <Weighted <Vertex> > > edges, int maxSteps = 10000)
    {
        Map <Vertex, Weighted <Vertex> > result = new Map <Vertex, Weighted <Vertex> >(() => new Weighted <Vertex>(default(Vertex), float.PositiveInfinity));
        HashSet <Vertex> relaxated = new HashSet <Vertex>();

        result[start] = new Weighted <Vertex>(default(Vertex), 0);
        for (int i = 0; i < maxSteps; i++)
        {
            var vertex = result.Keys.Except(relaxated).MinBy(v => result[v].weight);
            if (vertex == null)
            {
                break;
            }
            relaxated.Add(vertex);
            edges(vertex).ForEach(e => {
                var newPath = result[vertex].weight + e.weight;
                if (newPath < result[e.to].weight)
                {
                    result[e.to] = new Weighted <Vertex>(vertex, newPath);
                }
            });
        }
        return(result);
    }
 public void On_Empty_Returns_4() => Weighted.Compute(new Activity[0]).Should().Be(0);
 public void Add(Weighted <T> more)
 {
     pending.Add(more);
 }
示例#29
0
    /*
     * TODO: buffZBRadiating on ghost disactivated due to Mesh warning
     * test on chickenV2 ?
     */
    public static void _Define()
    {
        Printer.Print("BiomeInfo._Define()");
        ZBiomeInfo desert = new ZBiomeInfo("desert", 0f);

        desert.blockSoil             = "terrDesertGround,terrSand,terrSandStone";
        desert.blockTrap             = ZBiomeInfo.Blocks.cactus;
        desert.buffGhost             = "buffZBShoking";
        desert.decoProj              = "rockFragment,ZBProj_treePlainsTree,Boulder,ZBProj_treeCactus03";
        desert.blockRock             = "terrStone,terrGravel,terrSandStoneUnstable";
        desert.blockBuild            = "brickBlock";
        desert.zombies               = "zombieYo";
        desert.animals               = "animalZombieVulture,animalSnake";
        desert.fillBag               = "resourceBrokenGlass,resourceCrushedSand,terrDirt,terrSand";
        desert.envProj               = "ZBProj_sand,ZBProj_electric,ZBProj_eject,ZBProj_ragdoll,ZBProj_poison";
        desert.groundSmokeProjectile = "p_impact_stone_on_plant,p_impact_stone_on_earth";
        desert.groundColor           = new Color(218f / 255, 165f / 255, 32f / 255);
        desert.particleStorm         = GhostData.ssandEffect;
        desert.waterBlock            = "waterBoil,waterBoil";
        desert.Ghost = Weighted <GhostData> .Of(
            GhostData.fbolt, 0.2f, GhostData.fghost, 0.2f, GhostData.fbomb, 0.2f,
            GhostData.ebolt, 2f, GhostData.eghost, 2f, GhostData.ebomb, 2f,
            GhostData.ybolt, 0.5f, GhostData.yghost, 0.5f, GhostData.ybomb, 0.5f,
            GhostData.lbolt, 0.5f, GhostData.lbomb, 0.5f,
            GhostData.bbolt, 1f
            );

        ZBiomeInfo burnt_forest = new ZBiomeInfo("burnt_forest", 0.5f);

        burnt_forest.blockSoil             = "terrBurntForestGround,terrDirt";
        burnt_forest.blockTrap             = "woodLogSpike1";
        burnt_forest.buffGhost             = "buffZBFiring";
        burnt_forest.decoProj              = "rockFragment,ZBProj_treePlainsTree,Boulder,ZBProj_treeShrub,ZBProj_treeDeadTree01";
        burnt_forest.blockRock             = "terrStone,terrDirt";
        burnt_forest.blockBuild            = "burntWoodBlock1,burntWoodBlock2,burntWoodBlock3,burntWoodBlock4";
        burnt_forest.zombies               = "zombieMoe";
        burnt_forest.animals               = "animalZombieBear";
        burnt_forest.fillBag               = "terrDirt,terrSand";
        burnt_forest.envProj               = "ZBProj_fire,ZBProj_fireHuman,ZBProj_fireHuman,ZBProj_eject,ZBProj_ragdoll";
        burnt_forest.groundSmokeProjectile = "p_blockdestroy_stone,p_impact_stone_on_earth";
        burnt_forest.particleStorm         = GhostData.ssmokeEffect;
        burnt_forest.groundColor           = new Color(139f / 255, 69f / 255, 19f / 255);
        burnt_forest.waterBlock            = "waterBoil,waterBoil";
        burnt_forest.Ghost = Weighted <GhostData> .Of(
            GhostData.fbolt, 2f, GhostData.fghost, 2f, GhostData.fbomb, 2f,
            GhostData.ebolt, 0.1f,
            GhostData.ybolt, 0.5f, GhostData.yghost, 0.5f, GhostData.ybomb, 0.5f,
            GhostData.lbolt, 0.3f, GhostData.lbomb, 0.3f,
            GhostData.bbolt, 1f
            );

        ZBiomeInfo pine_forest = new ZBiomeInfo("pine_forest");

        pine_forest.blockSoil             = "terrForestGround";
        pine_forest.blockTrap             = ZBiomeInfo.Blocks.woodtrap;
        pine_forest.buffGhost             = "buffZBRadiating,buffZBShoking,buffZBFiring";
        pine_forest.decoProj              = "rockFragment,ZBProj_treePlainsTree,Boulder,ZBProj_treeShrub,ZBProj_treeOakSml01,ZBProj_treeOakLrg01,ZBProj_treePlantedOak41m,ZBProj_treeMountainPine12m";
        pine_forest.blockRock             = "terrStone";
        pine_forest.blockBuild            = "woodFrameMaster";
        pine_forest.zombies               = "zombieFarmer";
        pine_forest.animals               = "animalWolf,animalMountainLion";
        pine_forest.fillBag               = "resourceWood,resourceClayLump";
        pine_forest.envProj               = "ZBProj_fire,ZBProj_eject,ZBProj_sand,ZBProj_ragdoll,ZBProj_poison";
        pine_forest.groundSmokeProjectile = "p_treeGib_birch_small,p_impact_stone_on_plant,p_impact_stone_on_plant";  // p_treeGib_birch_6m is too big ?
        pine_forest.particleStorm         = GhostData.ssmokeEffect;
        pine_forest.groundColor           = new Color(34f / 255, 139f / 255, 34f / 255);
        pine_forest.waterBlock            = "terrWaterPOI,terrWaterPOI,terrWaterPOI,terrWaterPOI,waterBoil";
        pine_forest.Ghost = Weighted <GhostData> .Of(
            GhostData.fbolt, 1f, GhostData.fghost, 1f, GhostData.fbomb, 1f,
            GhostData.ybolt, 1f, GhostData.yghost, 1f, GhostData.ybomb, 1f,
            GhostData.lbolt, 1f, GhostData.lbomb, 1f,
            GhostData.bbolt, 1f
            );

        ZBiomeInfo snow = new ZBiomeInfo("snow", 2f);

        snow.blockSoil             = "terrSnow";
        snow.blockTrap             = "snowStalagmite";
        snow.buffGhost             = "buffZBRadiating,buffZBShoking";
        snow.decoProj              = "rockFragment,ZBProj_treePlainsTree,Boulder,ZBProj_treeShrub,ZBProj_treeWinterPine13m,ZBProj_treeWinterPine28m";
        snow.blockRock             = "terrStone,terrAsphalt";
        snow.blockBuild            = "flagstoneBlock";
        snow.zombies               = "zombieSnow";
        snow.animals               = "animalBear";
        snow.fillBag               = "resourceSnowBall";
        snow.envProj               = "ZBProj_freeze,ZBProj_electric,ZBProj_eject,ZBProj_ragdoll,ZBProj_freeze";
        snow.groundSmokeProjectile = "p_treeGib_winter01,p_paint_splash2,p_impact_bullet_on_snow,p_blockdestroy_snow";
        snow.particleStorm         = GhostData.ssnowEffect;
        snow.groundColor           = new Color(176f / 255, 224f / 255, 230f / 255);
        snow.waterBlock            = "waterFreeze,waterFreeze,waterFreeze,waterBoil,terrWaterPOI";
        snow.Ghost = Weighted <GhostData> .Of(
            GhostData.ebolt, 1f, GhostData.eghost, 1f, GhostData.ebomb, 1f,
            GhostData.ybolt, 1f, GhostData.yghost, 1f, GhostData.ybomb, 1f,
            GhostData.lbolt, 1f, GhostData.lbomb, 1f
            );


        ZBiomeInfo wasteland = new ZBiomeInfo("wasteland");

        wasteland.blockSoil             = "terrDestroyedStone";
        wasteland.blockTrap             = string.Join(",", ZBiomeInfo.Blocks.irontrap, "barbedWireSheet");
        wasteland.buffGhost             = "buffZBRadiating";
        wasteland.decoProj              = "rockFragment,ZBProj_treePlainsTree,Boulder,ZBProj_treeShrub,ZBProj_treeOakSml01,ZBProj_treeMountainPine12m,ZBProj_treeDeadTree01";
        wasteland.blockRock             = "terrStone,terrDestroyedStone,terrConcrete";
        wasteland.blockBuild            = "concreteBlock,scrapMetalPile";
        wasteland.zombies               = "zombieLab";
        wasteland.animals               = "animalZombieDog";
        wasteland.fillBag               = "resourceScrapPolymers";
        wasteland.envProj               = "ZBProj_spark,ZBProj_poison,ZBProj_spark,ZBProj_eject,ZBProj_sand";
        wasteland.groundSmokeProjectile = "p_impact_wood_on_earth,p_blockdestroy_metal";
        wasteland.particleStorm         = GhostData.ssandEffect;
        wasteland.groundColor           = new Color(188f / 255, 143f / 255, 143f / 255);
        wasteland.waterBlock            = "terrWaterPOI,terrWaterPOI,waterSlime";
        wasteland.Ghost = Weighted <GhostData> .Of(
            GhostData.fbolt, 0.2f, GhostData.fghost, 0.2f, GhostData.fbomb, 0.2f,
            GhostData.ebolt, 1f, GhostData.eghost, 1f, GhostData.ebomb, 1f,
            GhostData.ybolt, 1f, GhostData.yghost, 1f, GhostData.ybomb, 1f,
            GhostData.lbolt, 1f, GhostData.lbomb, 1f,
            GhostData.bbolt, 1f
            );

        Defined = true;
        Printer.Print("ZBiomeInfo keys:", string.Join(",", List.Keys));
    }
示例#30
0
文件: Join.cs 项目: sherryshare/Naiad
        public override void OnInput2(Weighted <S2> entry, T time)
        {
            var k = key2(entry.record);
            var v = value2(entry.record);

            var state = new JoinKeyIndices();

            if (!JoinKeys.TryGetValue(k, out state))
            {
                state = new JoinKeyIndices();
            }

            if (!inputShutdown1)//!this.inputImmutable1)
            {
                inputTrace2.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed2);
                inputTrace2.Introduce(ref state.processed2, v, entry.weight, internTable.Intern(time));
            }

            if (inputShutdown2)
            {
                Console.Error.WriteLine("Error in Join input shutdown2");
            }

            if (state.processed1 != 0)
            {
                inputTrace1.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed1);

                times.Clear();
                inputTrace1.EnumerateTimes(state.processed1, times);

                for (int i = 0; i < times.Count; i++)
                {
                    differences1.Clear();
                    inputTrace1.EnumerateDifferenceAt(state.processed1, times.Array[i], differences1);
                    var newTime = time.Join(internTable.times[times.Array[i]]);

                    for (int j = 0; j < differences1.Count; j++)
                    {
                        if (differences1.Array[j].weight != 0)
                        {
                            //Send(resultSelector(k, differences1.Array[j].record, v).ToNaiadRecord(entry.weight * differences1.Array[j].weight, newTime));
                            var result = resultSelector(k, differences1.Array[j].record, v);
                            var weight = entry.weight * differences1.Array[j].weight;
                            this.Output.Buffer.payload[this.Output.Buffer.length++] = new Pair <Weighted <R>, T>(new Weighted <R>(result, weight), newTime);

                            if (this.Output.Buffer.length == this.Output.Buffer.payload.Length)
                            {
                                this.Output.Send(this.Output.Buffer);
                                this.Output.Buffer.length = 0;
                            }
                        }
                    }
                }
            }

            if (state.IsEmpty)
            {
                JoinKeys.Remove(k);
            }
            else
            {
                JoinKeys[k] = state;
            }
        }
示例#31
0
        public void Base_ConditionalProbability()
        {
            var ex = from a in new Bernoulli(0.1)
                     from b in new Bernoulli(0.1)
                     from c in new Bernoulli(0.1)
                     let d = Convert.ToInt32(a) + Convert.ToInt32(b) + Convert.ToInt32(c)
                     where d >= 2
                     select a;

            var tmp1 = ex.Inference().Support().OrderBy(k => k.Value);
            var tmp2 = ex.SampledInference(10000).Support().OrderBy(k => k.Value);

            var result = new Weighted<bool>[] {
                new Weighted<bool>() { Value = false, Probability = 0.3214285714285714},
                new Weighted<bool>() { Value = true, Probability = 0.6785714285714285},
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));

            foreach (var item in tmp2.Zip(result, Tuple.Create))
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
        }
示例#32
0
        public void Base_ConditionalProbability3()
        {
            var ex = from rain in new Bernoulli(0.2)
                     from sprinkler in new Bernoulli(0.2)
                     from w in new Bernoulli(0.05)
                     let wet = rain | sprinkler ? true : w
                     where wet
                     select Tuple.Create(rain, sprinkler);

            var tmp1 = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted<Tuple<bool, bool>>[] {
                new Weighted<Tuple<bool,bool>>() { Value = Tuple.Create(false,false), Probability = 0.08163265306122447},
                new Weighted<Tuple<bool,bool>>() { Value = Tuple.Create(false,true), Probability = 0.4081632653061224},
                new Weighted<Tuple<bool,bool>>() { Value = Tuple.Create(true,false), Probability = 0.4081632653061224},
                new Weighted<Tuple<bool,bool>>() { Value = Tuple.Create(true,true), Probability = 0.1020408163265306},
            };
            foreach (var item in tmp1.Zip(result, Tuple.Create))
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
        }
示例#33
0
        public void BaseNestedInference2()
        {
            var ex = from x in new Flip(0.5)
                     let inner =  from y in new Flip(0.5)
                                  let tmp = x ? 1.0 : y ? 0.9 : 0.1
                                  from z in new Bernoulli(tmp)
                                  where z
                                  select y

                     let groups =  from q in inner.Support()
                                   group q by q.Value into summary
                                   let prob = summary.Select(k => k.Probability).Aggregate((a, b) => a + b)
                                   select Tuple.Create(summary.Key, prob)

                     let norm =  (from item in groups select item.Item2).Sum()

                     let normalized = from g in groups
                                      select new Weighted<bool>() {
                                          Value = g.Item1,
                                          Probability = g.Item2 / norm
                                      }
                     let inferred = new Multinomial<bool>(normalized.ToList())

                     from y in inferred
                     where !y
                     select x;

            var tmp1 = ex.Inference().Support().OrderBy(k => k.Value);
            var result = new Weighted<bool>[] {
                new Weighted<bool>() { Value = false, Probability = 0.1666666666666666 },
                new Weighted<bool>() { Value = true, Probability = 0.8333333333333334},
            };

            foreach (var item in tmp1.Zip(result, Tuple.Create))
                Assert.IsTrue(ApproxEqual(item.Item1.Probability, item.Item2.Probability));
        }
示例#34
0
文件: Tests.cs 项目: mhjort/aivo
 public void PicksOneRandomly()
 {
     Assert.AreEqual(0, Weighted.RandomIndexByWeight(new[] { 1, 2 }, (start, end) => start));
     Assert.AreEqual(1, Weighted.RandomIndexByWeight(new[] { 1, 2 }, (start, end) => start + 1));
     Assert.AreEqual(1, Weighted.RandomIndexByWeight(new[] { 1, 2 }, (start, end) => start + 2));
 }