private void DrawGlobalHeatmap()
        {
            var state = _gameInstance.State;

            var mouseMob = state.AtCoord(_camera.MouseHex, true);
            var heatmap  = Heatmap.BuildHeatmap(_gameInstance, mouseMob);

            DrawHeatmap(heatmap);
        }
Exemple #2
0
    /// <summary>
    /// initialization.
    /// </summary>
    void Start()
    {
        //Get Server Instance
        if (serverInstance == null)
        {
            serverInstance = TCPServer.getInstance(Ip, Port);
        }

        //register to IncomingMessage event
        serverInstance.incomingMessage += new EventIncomingMessage(HandleIncomingMessage);

        //Get Animator
        if (MainArm == null)
        {
            MainArm = GameObject.FindGameObjectWithTag("MainLimbAnimatorObject");
        }

        animArm = MainArm.GetComponent <Animator>();
        if (TACArm == null)
        {
            TACArm = GameObject.FindGameObjectWithTag("TACLimbAnimatorObject");
        }
        if (TACArm != null)
        {
            animTACArm = TACArm.GetComponent <Animator>();
        }
        TACArm.GetComponentInChildren <SkinnedMeshRenderer>().enabled = !HideTACArm;
        TACArmSkinR = false;

        //Create Mam
        Mam = new Heatmap(colormap, alpha, cubeheight, map3D, MainArm);

        //Set DOF LIST for main Arm
        DOF_ArmList.Add(new DOF("f_Open", "f_Close", 0x09, -1.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_Supination", "f_Pronation", 0x08, -1.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_Extend", "f_Flex", 0x07, -1.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_Ulnar", "f_Radial", 0x0F, 0.0F, 1.0F, Range)); //minValue is 0 because a fully extended arm is the initial position. The currentValue cannot go <0 and cause some delay when flexing again.
        DOF_ArmList.Add(new DOF("f_Pincer", "f_Rest", 0x0C, 0.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_IndexFinger", "f_Rest", 0x0A, 0.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_Key", "f_Rest", 0x0D, 0.0F, 1.0F, Range));
        DOF_ArmList.Add(new DOF("f_Rest", "f_Rest", 0x00, 0.0F, 0.0F, Range));

        //Set DOF LIST for the TAC Arm
        DOF_TAC_ArmList.Add(new DOF("f_Open", "f_Close", 0x09, -1.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Supination", "f_Pronation", 0x08, -1.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Extend", "f_Flex", 0x07, -1.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Ulnar", "f_Radial", 0x0F, 0.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Pincer", "f_Rest", 0x0C, 0.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_IndexFinger", "f_Rest", 0x0A, 0.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Key", "f_Rest", 0x0D, 0.0F, 1.0F, Range));
        DOF_TAC_ArmList.Add(new DOF("f_Rest", "f_Rest", 0x00, 0.0F, 0.0F, Range));

        //Set ID-list of secondary-close movments
        CloseMovement.Add(0x0C);
        CloseMovement.Add(0x0D);
        CloseMovement.Add(0x0A);
    }
Exemple #3
0
    private void GenerateHeatmap(string filename)
    {
        if (cyclists == null)
        {
            cyclists    = new AssetType[1];
            cyclists[0] = AssetType.Cyclist;
        }

        if (area == null)
        {
            Debug.LogError("Can't generate heatmap with unassigned area");
            return;
        }

        Bounds aabb = new Bounds(area.position, area.localScale);

        if (filename.EndsWith(TrafficIO.VISSIM_VEHICLES_EXTENSION))
        {
            TrafficData data = TrafficIO.Load(filename, columnSeparator, vectorSeparator, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Vehicles_Heatmap", cyclists, false);
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Cyclists_Heatmap", cyclists, true);
        }
        else if (filename.EndsWith(TrafficIO.VISSIM_PEDESTRIANS_EXTENSION))
        {
            TrafficData data = TrafficIO.Load(filename, columnSeparator, vectorSeparator, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Pedestrians_Heatmap");
        }
        else if (filename.EndsWith(TrafficIO.BINARY_VEHICLES_EXTENSION))
        {
            TrafficData data = TrafficIO.LoadBinary(filename, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Vehicles_Heatmap", cyclists, false);
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Cyclists_Heatmap", cyclists, true);
        }
        else if (filename.EndsWith(TrafficIO.BINARY_PEDESTRIANS_EXTENSION))
        {
            TrafficData data = TrafficIO.LoadBinary(filename, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Pedestrians_Heatmap");
        }
        AssetDatabase.Refresh();
    }
Exemple #4
0
        public async Task <IActionResult> Post(Heatmap heatmap)
        {
            Heatmap _heatmap = await _heatmapService.AddAsync(heatmap);

            if (_heatmap == null)
            {
                return(NotFound());
            }
            return(CreatedAtAction(nameof(Get), _heatmap));
        }
Exemple #5
0
        public async Task <ActionResult <Heatmap> > Get(int heatmapId)
        {
            Heatmap heatmap = await _heatmapService.GetByIdAsync(heatmapId);

            if (heatmap == null)
            {
                return(NotFound());
            }
            return(heatmap);
        }
Exemple #6
0
        /// <summary>
        /// Add a colorbar initialized with settings from a heatmap
        /// </summary>
        public Colorbar AddColorbar(Heatmap heatmap, int space = 100)
        {
            var cb = new Colorbar(heatmap.Colormap);

            cb.AddTick(0, heatmap.ColorbarMin);
            cb.AddTick(1, heatmap.ColorbarMax);
            Add(cb);
            YAxis2.SetSizeLimit(min: space);
            return(cb);
        }
Exemple #7
0
        public async Task <IActionResult> Put(int heatmapId, Heatmap heatmap)
        {
            if (heatmapId != heatmap.HeatmapID)
            {
                return(BadRequest());
            }
            await _heatmapService.UpdateAsync(heatmap);

            return(NoContent());
        }
        public virtual void OnHeatMapWayPoint(int id, Heatmap heatMap)
        {
            var handler = OnHeatMapWayPointEvent;

            if (handler != null)
            {
                handler(this, new HeatMapArgs {
                    RobotId = id, HeatMap = heatMap
                });
            }
        }
Exemple #9
0
 private void Awake()
 {
     start_panel_active   = true;
     buildingDeleteModeOn = false;
     barDeleteModeOn      = false;
     landmarkModeOn       = false;
     buildingPlacement    = GameObject.Find("Terrain").GetComponent <BuildingPlacement>();
     barPlacement         = GameObject.Find("Terrain").GetComponent <BarPlacement>();
     skyExposure          = GameObject.Find("Main Camera").GetComponent <SkyExposure>();
     heatmap = GameObject.Find("Heatmap").GetComponent <Heatmap>();
     create_building_panel.SetActive(false);
 }
        static async Task Main()
        {
            // Call asynchronous network methods in a try/catch block to handle exceptions.
            try
            {
                client.DefaultRequestHeaders.Add("ApiKey", "829320-adajdasd-12vasdas-baslk3");
                HttpResponseMessage response = await client.GetAsync("https://fruitflywebapi.azurewebsites.net/api/Referencepoint");

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                // Above three lines can be replaced with new helper method below


                //Splits the responsebody into each datatype and it's value. Items * 1000 to make sure that a thousand heatmapID's can be loaded.
                line = responseBody.Split(',', items * 1000);

                //Checks for 3 specific strings that contain: 'x', 'y' and ('h', 'e', 'a' and 't').
                CheckEachString();


                for (int i = 0; i < lineHeat.Count; i++)
                {
                    //Here a new object of heatmap is created for each heatmap ID in the database. The values are collected from the sepereate list of x, y and heatmapID.
                    var obj = new Heatmap
                    {
                        x         = ExtractInteger(lineX[i]),
                        y         = ExtractInteger(lineY[i]),
                        HeatmapID = ExtractInteger(lineHeat[i]),
                        Value     = 1
                    };

                    //adds all the added headmaps into a list of heatmaps.
                    heatmaps.Add(obj);
                }

                //compares if there are more than 1 element with the same x and y coordinates. If so, the value of the item will increase with 1 pr matching elements.
                CompareElements(heatmaps);

                foreach (var i in heatmaps)
                {
                    Console.WriteLine("X: " + i.x + "\t" + "Y: " + i.y + "\t" + "Value: " + i.Value + "\t" + "ID: " + i.HeatmapID + "\n");
                }

                //serializes the list of heatmaps and
                JsonSerialize(heatmaps);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }
        }
Exemple #11
0
        public async Task <IActionResult> Delete(int heatmapId)
        {
            Heatmap heatmap = await _heatmapService.GetByIdAsync(heatmapId);

            if (heatmap == null)
            {
                return(NotFound());
            }
            await _heatmapService.RemoveAsync(heatmap);

            return(NoContent());
        }
        public async Task <IEnumerable <Heatmap> > GetAllHeatmapAsync()
        {
            // Call asynchronous network methods in a try/catch block to handle exceptions.
            try
            {
                HeatClient.DefaultRequestHeaders.Add("ApiKey", "829320-adajdasd-12vasdas-baslk3"); //Server side API Token

                var handler = _httpHandler.Get("https://fruitflywebapi.azurewebsites.net/api/Heatmap", HeatClient).EnsureSuccessStatusCode();

                if (handler.IsSuccessStatusCode)
                {
                    var responseBody = await handler.Content.ReadAsStringAsync();

                    Console.WriteLine("Connection established");

                    //Splits the responsebody into each datatype and it's value. Items * 1000 to make sure that a thousand heatmapID's can be loaded.
                    var _line = responseBody.Split(',', items * 1000);

                    //Checks for 3 specific strings that contain: 'x', 'y' and ('h', 'e', 'a' and 't').
                    CheckEachString.CheckStringHeatmap(_line, LineX, LineY, LineHeat);

                    for (int i = 0; i < LineHeat.Count; i++)
                    {
                        //Here a new object of heatmap is created for each heatmap ID in the database. The values are collected from the sepereate list of x, y and heatmapID.
                        var obj = new Heatmap
                        {
                            x         = Extractor.ExtractFromString(LineX[i]),
                            y         = Extractor.ExtractFromString(LineY[i]),
                            HeatmapID = Extractor.ExtractFromString(LineHeat[i]),
                            Value     = 1
                        };

                        //adds all the added heatmaps into a list of heatmaps.
                        Heatmaps.Add(obj);
                    }

                    //compares if there are more than 1 element with the same x and y coordinates. If so, the value of the item will increase with 1 pr matching elements.
                    CompareElements.CompareHeatmapValues(Heatmaps);
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }

            //DeleteAllHeatmapAsync();

            //returns all data stored in the list of heatmaps to the GET method
            Console.WriteLine("All heatmap data stored");
            return(Heatmaps);
        }
Exemple #13
0
    private void Save(string filename, Heatmap heatmap)
    {
        // Serializes the heatmap data and saves the data to the given path (and overwrites if necessary)
        StreamWriter streamWriter = new StreamWriter("Assets/Resources/Heatmap/" + filename + ".txt", false);

        streamWriter.Write(Json.Serialize(heatmap.Data));
        streamWriter.Close();

        // Reimports the file because Unity doesn't realize changes made to it
        AssetDatabase.ImportAsset("Assets/Resources/Heatmap/" + filename + ".txt");

        HeatmapFilename = filename;
    }
    public IEnumerator TakeScreenshot()
    {
        int i = 0;

        while (File.Exists("Assets/Screenshot" + i + ".png"))
        {
            i++;
            yield return(0);
        }
        string path = "Assets/Screenshot" + i + ".png";

        Heatmap.Screenshot(path, camera);
    }
Exemple #15
0
        public void Recived_calls_JsonSerializer()
        {
            List <Heatmap> heatmaps = new List <Heatmap>();
            Heatmap        h        = new Heatmap();

            heatmaps.Add(h);

            var mockedObject = new Mock <IController>();
            var obj          = mockedObject.Object;

            obj.OpenConnection();

            Mock.Get(obj).Verify(x => x.JsonSerialize(heatmaps), Times.AtLeastOnce);
        }
Exemple #16
0
        /// <summary>
        /// Add a heatmap to the plot
        /// </summary>
        public Heatmap AddHeatmap(double[,] intensities, Drawing.Colormap colormap = null, bool lockScales = true)
        {
            if (lockScales)
            {
                AxisScaleLock(true);
            }

            var plottable = new Heatmap();

            plottable.Update(intensities, colormap);
            Add(plottable);

            return(plottable);
        }
Exemple #17
0
    public void RiderStart()
    {
        m_heatmap  = GetComponent <Heatmap>();
        m_steering = GetComponent <Steering>();

        m_game         = FindObjectOfType <BikeGangs>();
        m_started      = true;
        m_moveSpeed    = Random.Range(MinMoveSpeed, MaxMoveSpeed);
        m_offset       = Random.Range(-m_game.RoadGenerator.RoadWidth, m_game.RoadGenerator.RoadWidth);
        m_targetOffset = m_game.RoadGenerator.RoadWidth / 12.0f * 3.0f;
        m_heatmap.Begin();
        m_accumulatorMultiplier  = Random.Range(0.0f, 10.0f);
        m_accumulatorMultiplier += Random.Range(0.0f, 0.5f);
    }
Exemple #18
0
        private XPlot.Plotly.PlotlyChart PlotMatrix(double[,] matrix)
        {
            var m  = matrix.Reverse(false);
            var s1 = new Heatmap()
            {
                name       = "Heat-map of Matrix",
                colorscale = @"YIGnBu",
                z          = m
            };

            var chart = XPlot.Plotly.Chart.Plot <Trace>(new Trace[] { s1 });

            return(chart);
        }
        private void ChartLoaded(object sender, RoutedEventArgs e)
        {
            if (chart.Series.Count > 0)
            {
                return;
            }

            chart.BeginUpdate();

            var scale = new DiscreteColorScale()
            {
                Intervals = new List <DiscreteColorScale.Interval>()
            };

            scale.Intervals.Add(new DiscreteColorScale.Interval(0, 10, Color.FromRgb(0x05, 0x71, 0xB0), "Very Low"));
            scale.Intervals.Add(new DiscreteColorScale.Interval(10, 25, Color.FromRgb(0x92, 0xC5, 0xDE), "Low"));
            scale.Intervals.Add(new DiscreteColorScale.Interval(25, 75, Color.FromRgb(0xD7, 0xD7, 0xD7), "Normal"));
            scale.Intervals.Add(new DiscreteColorScale.Interval(75, 90, Color.FromRgb(0xF4, 0xA5, 0x82), "High"));
            scale.Intervals.Add(new DiscreteColorScale.Interval(90, 100, Color.FromRgb(0xCA, 0x00, 0x20), "Critical"));

            var rnd  = new Random();
            var data = new double[24, 7];

            for (var j = 0; j < 7; j++)
            {
                for (var i = 0; i < 24; i++)
                {
                    data[i, j] = 10 * Math.Exp(-(i - 12) * (i - 12) / (2 * 4.0 * 4.0)) / Math.Sqrt(2 * Math.PI * 4.0 * 4.0) * ((j == 5 || j == 6) ? 50 : 100) * rnd.NextDouble();
                }
            }

            var hmap = new Heatmap();

            hmap.ItemsSource = data;
            hmap.ColorScale  = scale;
            chart.Series.Add(hmap);

            var times = new string[24];

            for (var i = 0; i < 24; i++)
            {
                times[i] = new DateTime(2000, 1, 1, i, 0, 0).ToShortTimeString();
            }
            chart.AxisX.ItemsSource = times;

            chart.AxisY.ItemsSource = new string[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };

            chart.EndUpdate();
        }
        private void DrawHoverHeatmap(int currentMob)
        {
            if (_gameInstance.Pathfinder.IsValidCoord(_camera.MouseHex))
            {
                var state    = _gameInstance.State;
                var mouseMob = state.AtCoord(_camera.MouseHex, true);

                if (mouseMob.HasValue)
                {
                    var heatmap = Heatmap.BuildHeatmap(_gameInstance, mouseMob);

                    DrawHeatmap(heatmap);
                }
            }
        }
        private void DrawHeatmap(Heatmap heatmap)
        {
            _spriteBatch.Begin(transformMatrix: _camera.Transform, samplerState: Camera2D.SamplerState);
            foreach (var coord in heatmap.Map.AllCoords)
            {
                if (heatmap.Map[coord] == 0)
                {
                    continue;
                }

                float percent = heatmap.Map[coord] / (float)heatmap.MaxValue / 2 + 0.5f;
                DrawAt(_assetManager[AssetManager.HexHoverSprite], coord, Color.Red * percent * percent);
            }
            _spriteBatch.End();
        }
Exemple #22
0
        private void ColorAxis_Load(object sender, EventArgs e)
        {
            var chart = new FlexChart();

            chart.Legend.Position      = Position.None;
            chart.Dock                 = DockStyle.Fill;
            chart.AxisY.Title          = "y";
            chart.AxisY.MajorGrid      = false;
            chart.AxisY.AxisLine       = true;
            chart.AxisY.MajorTickMarks = TickMark.Outside;
            chart.AxisX.Title          = "x";
            chart.ToolTip.Content      = "{item:0.00}";
            chart.Header.Content       = "2D deformation distribution";
            chart.Header.Style.Font    = new Font("Seqoe UI", 16);

            var scale = new GradientColorScale()
            {
                Min  = 0,
                Max  = 4,
                Axis = new C1.Win.Chart.Extended.ColorAxis()
                {
                    Position = Position.Right, Title = "deformation, mm"
                },
                Colors = new List <Color> {
                    Color.Yellow, Color.Red
                }
            };

            var data = new double[150, 150];

            for (var i = 0; i < 150; i++)
            {
                for (var j = 0; j < 150; j++)
                {
                    data[i, j] = 2 + (Math.Sin(0.01 * i) + Math.Cos(0.1 * j));
                }
            }

            var hmap = new Heatmap();

            hmap.DataSource = data;
            hmap.ColorScale = scale;
            hmap.StartX     = 0;
            hmap.StartY     = 0;
            chart.Series.Add(hmap);

            Controls.Add(chart);
        }
Exemple #23
0
    void GenerateHeatMap()
    {
        Bounds aabb = new Bounds(area.position, area.localScale);

        if (heatmapPasses == null || heatmapPasses.Length == 0)
        {
            Heatmap.GenerateHeatmap(data, transform.position, heatmapResolution, pointRadius, aabb, logarithmic, name + "-Heatmap");
        }
        else
        {
            for (int i = 0; i < heatmapPasses.Length; i++)
            {
                Heatmap.GenerateHeatmap(data, transform.position, heatmapResolution, pointRadius, aabb, logarithmic, name + "-Heatmap" + (i + 1), heatmapPasses[i].assetTypes, heatmapPasses[i].include);
            }
        }
    }
    void Awake()
    {
        gvc           = GetComponentInChildren <GraphicValuesController> ();
        heatmap       = FindObjectOfType <Heatmap> ();
        HeatmapActive = false;

        //Persistencia de IP y Puerto
        //ipText.text = PlayerPrefs.GetString("IP");
        //portText.text = PlayerPrefs.GetString("Port");

        try{
            dataObjectUI = FindObjectOfType <DataObject>().gameObject;
        }catch {
            throw new System.IndexOutOfRangeException("No hay ningún DataObject en la escena!");
        }
    }
        public async Task <IEnumerable <Heatmap> > GetAllReferenceid()
        {
            try
            {
                RefClient.DefaultRequestHeaders.Add("ApiKey", "829320-adajdasd-12vasdas-baslk3"); //Server side API Token

                var handler = _httpHandler.Get("https://fruitflywebapi.azurewebsites.net/api/Referencepoint", RefClient).EnsureSuccessStatusCode();

                if (handler.IsSuccessStatusCode)
                {
                    Console.WriteLine("Connection established");


                    var responseBody = await handler.Content.ReadAsStringAsync();

                    //Splits the responsebody into each datatype and it's value. Items * 1000 to make sure that a thousand heatmapID's can be loaded.
                    var _line = responseBody.Split(',', items * 1000);

                    //Checks for 3 specific strings that contain: 'x', 'y' and ('r', 'e', and 'f').
                    CheckEachString.CheckStringReference(_line, RefLineX, RefLineY, LineRef);

                    for (int i = 0; i < LineRef.Count; i++)
                    {
                        //Here a new object of heatmap is created for each heatmap ID in the database. The values are collected from the sepereate list of x, y and heatmapID.
                        var obj = new Heatmap
                        {
                            x         = Extractor.ExtractFromString(RefLineX[i]),
                            y         = Extractor.ExtractFromString(RefLineY[i]),
                            HeatmapID = Extractor.ExtractFromString(LineRef[i]),
                            Value     = 0
                        };

                        //adds all the added heatmaps into a list of heatmaps.
                        HeatmapsRef.Add(obj);
                    }
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }

            //returns all data stored in the list of heatmaps to the GET method
            Console.WriteLine("All Reference data stored");
            return(HeatmapsRef);
        }
Exemple #26
0
        public void Setup()
        {
            uut = new CompareElements();

            items = new List <Heatmap>();
            Heatmap h1 = new Heatmap
            {
                x         = 3,
                y         = 4,
                Value     = 1,
                HeatmapID = 1
            };
            Heatmap h2 = new Heatmap
            {
                x         = 42,
                y         = 62,
                Value     = 1,
                HeatmapID = 2
            };
            Heatmap h3 = new Heatmap
            {
                x         = 32,
                y         = 3,
                Value     = 1,
                HeatmapID = 3
            };
            Heatmap h4 = new Heatmap
            {
                x         = 17,
                y         = 55,
                Value     = 1,
                HeatmapID = 4
            };
            Heatmap h5 = new Heatmap
            {
                x         = 3,
                y         = 4,
                Value     = 1,
                HeatmapID = 5
            };

            items.Add(h1);
            items.Add(h2);
            items.Add(h3);
            items.Add(h4);
            items.Add(h5);
        }
Exemple #27
0
    public static bool CanSeeGridRay(Vec2I from, Vec2I to)
    {
        foreach (Vec2I step in AxMath.CartesianLine(from, to))
        {
            HeatmapNode node = Heatmap.GetNode(step);
            if (node == null)
            {
                return(false);
            }
            if (node.HasWall)
            {
                return(false);
            }
        }

        return(true);
    }
Exemple #28
0
        /// <summary>
        /// Generates a number of defensive move actions based on a heatmap.
        /// </summary>
        public static void GenerateDefensiveMoveActions(GameInstance state, CachedMob mob, List <UctAction> result)
        {
            var heatmap = Heatmap.BuildHeatmap(state, null, false);
            var coords  = new List <AxialCoord>();

            var mobInstance = mob.MobInstance;
            var mobId       = mob.MobId;

            foreach (var coord in heatmap.Map.AllCoords)
            {
                if (heatmap.Map[coord] != heatmap.MinValue)
                {
                    continue;
                }
                if (state.Map[coord] == HexType.Wall)
                {
                    continue;
                }
                if (state.State.AtCoord(coord, true).HasValue)
                {
                    continue;
                }

                bool canMoveTo = state.Pathfinder.Distance(mobInstance.Coord, coord) <= mobInstance.Ap;

                if (!canMoveTo)
                {
                    continue;
                }

                coords.Add(coord);
            }

            coords.Shuffle();

            int maximumMoveActions = Math.Max(0, 3 - result.Count);

            for (int i = 0; i < Math.Min(coords.Count, maximumMoveActions); i++)
            {
                var action = UctAction.DefensiveMoveAction(mobId, coords[i]);
                GameInvariants.AssertValidAction(state, action);

                result.Add(action);
            }
        }
    public void OnGUI()
    {
        if (GUI.Button(resetRect, "Reset"))
        {
            Heatmap.DestroyHeatmapObjects();
            ClearPoints();
#if !UNITY_WEBPLAYER
            //usePresetCoordinates = false;
#endif
        }

#if !UNITY_WEBPLAYER
        if (GUI.Button(screenshotRect, "Screenshot"))
        {
            StartCoroutine(TakeScreenshot());
        }
#endif
    }
Exemple #30
0
    public static int MINIMUM_THRESHOLD = -333; //!< Minimum threshold.
                                                ///	Minimum alpha a point must have to be rendered at all.
                                                ///
    //Inputs:   speedAndPos | the dictionary that stores all the points and their different color values
    //          cam         | the main camera
    //          plane       | the heatplane that the texture is going to be put on
    //Outputs:  Texture2D   | the texture that the heatmap is put on
    //Functionality: creates a texture for the heatmap to be stored on using all the points and their color values
    public static Texture2D CreateHeatmap(Dictionary <Vector2, float> speedAndPos, Camera cam, GameObject plane)
    {
        //find camera
        if (cam == null)
        {
            if (Camera.main == null)
            {
                Debug.LogWarning("No camera found.  Returning an empty texture.");
                return(new Texture2D(0, 0));
            }
            else
            {
                cam = Camera.main;
            }
        }

        // Create new texture
        Texture2D map = new Texture2D((int)(plane.transform.localScale.x * 30 * 10), (int)(plane.transform.localScale.z * 30 * 10), TextureFormat.ARGB32, false);

        // Set texture to alpha-fied state
        map.SetPixels(Heatmap.ColorArray(new Color(1f, 1f, 1f, 0f), map.width * map.height), 0);

        //Going through each point, set the alpha value to the color value in speedAndPos
        foreach (KeyValuePair <Vector2, float> keyval in speedAndPos)
        {
            //this checks if the color value is 0, in which case the color should be different. This represents the starting position of the agent
            //this is currently turned off in Tracker
            if (keyval.Value == 0)
            {
                map.SetPixel((int)keyval.Key.x, (int)keyval.Key.y, Color.cyan);
            }
            else
            {
                map.SetPixel((int)keyval.Key.x, (int)keyval.Key.y, new Color(1f, 1f, 1f, keyval.Value));
            }
        }

        //finish the map by applying all changes and setting the rest of the pixels
        map.Apply();
        map.SetPixels(Colorize(map.GetPixels(0)), 0);
        map.Apply();

        return(map);
    }
Exemple #31
0
    private bool SaveAs(string filename, Heatmap heatmap, ref bool shouldRebuild)
    {
        TextAsset textAsset = Resources.Load<TextAsset>("Heatmap/" + filename);

        // Does the same thing as above, but asks if you want to overwrite the file in case it already exists
        if ((textAsset == null) || EditorUtility.DisplayDialog("Warning", "That file already exists, do you want to overwrite it?", "Yes", "No"))
        {
            if (shouldRebuild)
            {
                heatmap.RefreshData();
                shouldRebuild = false;
            }

            Save(filename, heatmap);

            // Also, assigns the file to the heatmap
            heatmap.File = Resources.Load<TextAsset>("Heatmap/" + filename);

            Task = HeatmapEditorTask.ViewOrUpdate;

            return true;
        }

        return false;
    }
Exemple #32
0
    private void Save(string filename, Heatmap heatmap)
    {
        // Serializes the heatmap data and saves the data to the given path (and overwrites if necessary)
        StreamWriter streamWriter = new StreamWriter("Assets/Resources/Heatmap/" + filename + ".txt", false);
        streamWriter.Write(Json.Serialize(heatmap.Data));
        streamWriter.Close();

        // Reimports the file because Unity doesn't realize changes made to it
        AssetDatabase.ImportAsset("Assets/Resources/Heatmap/" + filename + ".txt");

        HeatmapFilename = filename;
    }