Beispiel #1
0
    private void runDiagram(float f)
    {
        if (null == m_DataDiagram)
        {
            return;
        }

        float d = 0f;

        Debug.Log("datad" + lineList.Count);
        for (int i = 0; i < lineList.Count; i++)
        {
            if (i == 0)
            {
                m_DataDiagram.InputPoint(lineList[i], new Vector2(0.1f, hawks.Count / 40f));
            }
            if (i == 1)
            {
                m_DataDiagram.InputPoint(lineList[i], new Vector2(0.1f, foods.Count / 20f));
            }
            if (i == 2)
            {
                m_DataDiagram.InputPoint(lineList[i], new Vector2(0.1f, doves.Count / 40f));
            }
        }
    }
Beispiel #2
0
    private void ContinueInput(float f)
    {
        if (null == dataDiagram)
        {
            return;
        }

        if (false == m_IsContinueInput)
        {
            return;
        }

        DataSource data = DataSource.getSingletonInstance();

        int [] graphsPoints = new int[3]  {
            data.getNumberOfDoves(), data.getNumberOfHawks(), data.getNumberOfFood()
        };
        int   index    = 0;
        float pointVal = 0f;

        foreach (GameObject l in lineList)
        {
            pointVal += (float)((graphsPoints[index] / 10) % 5);
            Debug.Log("Graph Points:" + pointVal);
            dataDiagram.InputPoint(l, new Vector2(0.1f,
                                                  (Mathf.Sin(f + pointVal) + 1f) * 2f));
            index += 1;
        }
    }
Beispiel #3
0
    private void ContinueInput(float f)
    {
        if (null == m_DataDiagram)
        {
            return;
        }



        m_DataDiagram.InputPoint(lineList[0], new Vector2(0.4f,
                                                          Mathf.PerlinNoise(0.5f, f * (ipm.interactionDensity * 0.1f)) * 50f));

        // interactions per min
        m_DataDiagram.InputPoint(lineList[1], new Vector2(0.5f,
                                                          ipm.ipm));

        // interaction density
        m_DataDiagram.InputPoint(lineList[2], new Vector2(0.5f,
                                                          ipm.interactionDensity));
        // m_DataDiagram.InputPoint(lineList[3], new Vector2(0.08f,
        //                 (Mathf.Sin(Mathf.Tan(f)*Mathf.PerlinNoise(1f,f))*0.55f)+0.5f));

        // m_DataDiagram.InputPoint(lineList[0], new Vector2(0.1f,
        //                 Mathf.Pow(Mathf.Sin(freq*f),155)*(Mathf.Sin(freq*f+7.82f)*8)+0.5f));
    }
Beispiel #4
0
    private void ContinueInput(float f)
    {
        if (null == m_DataDiagram)
        {
            return;
        }

        if (false == m_IsContinueInput)
        {
            return;
        }

        DataSource data = DataSource.getSingletonInstance();

        int maxVal = System.Math.Max(data.getNumberOfDoves(), System.Math.Max(data.getNumberOfHawks(), data.getNumberOfFood()));

        float[] graphsPoints = getScaledValues(maxVal, data.getNumberOfDoves(), data.getNumberOfHawks(), data.getNumberOfFood());
        int     index        = 0;
        float   pointVal     = 0f;

//        Debug.Log("asdnfkjdgnkddgf");
//        Debug.Log(graphsPoints[0]);
//        Debug.Log(graphsPoints[1]);
//        Debug.Log(graphsPoints[2]);
        foreach (GameObject l in lineList)
        {
            pointVal += graphsPoints[index];
            //Debug.Log("Graph Points:" + pointVal);
            m_DataDiagram.InputPoint(l, new Vector2(0.1f, (Mathf.Sin(f + pointVal) + 1f) * 2f));
            index++;
        }
    }
Beispiel #5
0
 public static void DiagramPlot(float _channel1, float _channel2, float _channel3, float _channel4, float _channel5)
 {
     DataDiagram.InputPoint(line1, new Vector2(0.1f, _channel1));
     DataDiagram.InputPoint(line2, new Vector2(0.1f, _channel2));
     DataDiagram.InputPoint(line3, new Vector2(0.1f, _channel3));
     DataDiagram.InputPoint(line4, new Vector2(0.1f, _channel4));
     DataDiagram.InputPoint(line5, new Vector2(0.1f, _channel5));
 }
Beispiel #6
0
    private void plotGraph(List <int> allHawksList, List <int> allDovesList)
    {
        // all hawks
        foreach (int hawkCount in allHawksList)
        {
            dataDiagram.InputPoint(lineHawk, new Vector2(1, hawkCount / 10f));
        }

        // all doves
        foreach (int doveCount in allDovesList)
        {
            dataDiagram.InputPoint(lineDove, new Vector2(1, doveCount / 10f));
        }
    }
Beispiel #7
0
    // Update is called once per frame
    void Update()
    {
        float force = SerialHandler_.getForce();


        diagram.InputPoint(line, new Vector2(0.1f, force * 0.1f));
    }
Beispiel #8
0
 void UpdateChart()
 {
     foreach (var line in lines)
     {
         diagram.InputPoint(line, new Vector2(1, Random.Range(RangeMin, RangeMax)));
     }
 }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        GameObject dd = GameObject.Find("DataDiagram");

        if (null == dd)
        {
            Debug.LogWarning("can not find a gameobject of DataDiagram");
            return;
        }
        m_DataDiagram = dd.GetComponent <DD_DataDiagram>();

        m_DataDiagram.PreDestroyLineEvent += (s, e) => { lineList.Remove(e.line); };

        AddALine();
        StartCoroutine(Pause());
        double result = GetRandomNumber(-1, 1);

        Console.WriteLine(result);

        sharePrice     += (float)result * 10f;
        StockPrice.text = "The stock price is :" + sharePrice;
        foreach (GameObject l in lineList)
        {
            m_DataDiagram.InputPoint(l, new Vector2(1, sharePrice));
        }
    }
Beispiel #10
0
    private void Update()
    {
        time += Time.deltaTime * 5;
        var y = (Mathf.Sin(time) + 1) * 2 + 3;

        diagram.InputPoint(line, new Vector2(0.1f, y));
    }
Beispiel #11
0
    IEnumerator Pause()
    {
        while (true)
        {
            yield return(new WaitForSeconds(5f));

            double result = GetRandomNumber(-1, 1);
            Console.WriteLine(result);

            sharePrice     += (float)result * 10f;
            StockPrice.text = "The stock price is :" + sharePrice;
            foreach (GameObject l in lineList)
            {
                m_DataDiagram.InputPoint(l, new Vector2(1, sharePrice));
            }
        }
    }
Beispiel #12
0
 private void UpdateGraph()
 {
     foreach (KeyValuePair <Company, GameObject> entry in companyGraphs)
     {
         Company    company = entry.Key;
         GameObject graph   = entry.Value;
         diagram.InputPoint(graph, new Vector2(1.0f, Random.Range(company.MinPrice, company.MaxPrice)));
     }
 }
Beispiel #13
0
    private void ContinueInput(float f)
    {
        if (null == m_DataDiagram)
        {
            return;
        }

        if (false == m_IsContinueInput)
        {
            return;
        }

        float d = 0f;

        foreach (GameObject l in lineList)
        {
            m_DataDiagram.InputPoint(l, new Vector2(0.1f,
                                                    (Mathf.Sin(f + d) + 1f) * 2f));
            d += 1f;
        }
    }
 public IEnumerator updateCountGraph()
 {
     while (true)
     {
         float currentTime = Time.time + timeDiff;
         if (totalCount > 0)
         {
             float rate = (totalCount - firstCount) / (currentTime - firstTime);
             countRateGraph.InputPoint(countRateGraphLine, new Vector2(0.1f, rate));
         }
         firstCount = totalCount;
         firstTime  = currentTime;
         yield return(new WaitForSeconds(graphUpdateSpeed));
     }
 }
Beispiel #15
0
 private void Update()
 {
     sc = GetScore.sc;
     diagram.InputPoint(line, new Vector2(0.1f, sc));
 }
    void viewGoodResource()
    {
        plus.interactable   = false;
        minus.interactable  = false;
        offer.isOn          = false;
        bid.isOn            = false;
        High.interactable   = false;
        Medium.interactable = false;
        Low.interactable    = false;
        Debug.Log("Was clicked");
        App    app         = UnityEngine.Object.FindObjectOfType <App>();
        int    playerIndex = app.GetHumanIndex();
        Nation player      = State.getNations()[playerIndex];
        Market market      = State.market;

        MarketHelper.currentItem = SelectionButton.transform.parent.parent.name;
        Debug.Log("Grandparent name: " + currentItem);
        if (ress.Contains(currentItem))
        {
            itemImage.sprite = Resources.Load("Resource/" + currentItem, typeof(Sprite)) as Sprite;
            MyEnum.Resources _item = (MyEnum.Resources)Enum.Parse(typeof(MyEnum.Resources), currentItem);
            numOffBid.text = MarketHelper.ResourceOfferBidAmount[_item].ToString();

            if (State.turn > 1)
            {
                offeredLastTurn.text = "Offered Last Turn: " + market.getNumberOfResourcesOffered(_item).ToString();
                soldLastTurn.text    = "Sold Last Turn: " + market.getNumberResourcesSold(_item).ToString();
            }
            else
            {
                offeredLastTurn.text = "Offered Last Turn: 0";
                soldLastTurn.text    = "Sold Last Turn: 0";
            }
            priceHistory = market.getResourcePriceHistory(_item);
        }
        else
        {
            itemImage.sprite = Resources.Load("FinishedGoods/" + currentItem, typeof(Sprite)) as Sprite;
            MyEnum.Goods _item = (MyEnum.Goods)Enum.Parse(typeof(MyEnum.Goods), currentItem);
            numOffBid.text = MarketHelper.GoodsOfferBidAmount[_item].ToString();
            if (State.turn > 1)
            {
                offeredLastTurn.text = "Offered Last Turn: " + market.getNumberGoodsOffered(_item).ToString();
                soldLastTurn.text    = "Sold Last Turn: " + market.getNumberOfGoodsSoldLastTurn(_item).ToString();
                priceHistory         = market.getGoodPriceHistory(_item);
            }
            else
            {
                offeredLastTurn.text = "Offered Last Turn: 0";
                soldLastTurn.text    = "Sold Last Turn: 0";
            }
            priceHistory = market.getGoodPriceHistory(_item);
        }

        GameObject history = dataDiagram.AddLine(player.getName(), player.getColor());

        for (int i = 0; i < priceHistory.Count; i++)
        {
            dataDiagram.InputPoint(history, new Vector2(i, priceHistory[i]));
        }
    }
    public void NextButtonClick()
    {
        List <GameObject> foods  = new List <GameObject>();
        List <GameObject> hawks  = new List <GameObject>();
        List <GameObject> doves  = new List <GameObject>();
        List <GameObject> agents = new List <GameObject>();

        for (int i = 0; i < System.Convert.ToInt32(foodNumber.text); i++)
        {
            spawnPrefab(foodPrefab);
        }
        foreach (GameObject fhd in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (fhd.name == "Food(Clone)")
            {
                foods.Add(fhd);
            }
            if (fhd.name == "Hawk(Clone)")
            {
                agents.Add(fhd);
                hawks.Add(fhd);
            }
            if (fhd.name == "Dove(Clone)")
            {
                agents.Add(fhd);
                doves.Add(fhd);
            }
        }
        while (agents != null)
        {
            if (foods.Count > 0)
            {
                if (agents.Count == 1)
                {
                    if (doves.Contains(agents[0]))
                    {
                        Dove dove = agents[0].transform.GetComponent <Dove>();
                        dove.energy = foodValueInt - baseReqInt + dove.energy;
                    }
                    if (hawks.Contains(agents[0]))
                    {
                        Hawk hawk = agents[0].transform.GetComponent <Hawk>();
                        hawk.energy = foodValueInt - baseReqInt + hawk.energy;
                    }

                    agents.RemoveAt(0);
                }
                else
                {
                    int        r1          = Random.Range(1, agents.Count) - 1;
                    int        r2          = Random.Range(1, agents.Count) - 1;
                    GameObject competitor1 = agents[r1];
                    GameObject competitor2 = agents[r2];
                    agents.RemoveAt(r1);
                    agents.RemoveAt(r2);
                    if (hawks.Contains(competitor1) && hawks.Contains(competitor2))
                    {
                        Hawk hawk1 = competitor1.transform.GetComponent <Hawk>();
                        Hawk hawk2 = competitor2.transform.GetComponent <Hawk>();
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                        hawk2.energy = hawk1.energy - injuryInt - baseReqInt;
                    }
                    if (doves.Contains(competitor1) && doves.Contains(competitor2))
                    {
                        Dove dove1 = competitor1.transform.GetComponent <Dove>();
                        Dove dove2 = competitor2.transform.GetComponent <Dove>();
                        dove1.energy = dove1.energy + foodValueInt - bluffingInt - baseReqInt;
                        dove2.energy = dove1.energy - bluffingInt - baseReqInt;
                    }
                    if (hawks.Contains(competitor1) && doves.Contains(competitor2))
                    {
                        Hawk hawk1 = competitor1.transform.GetComponent <Hawk>();
                        Dove dove1 = competitor2.transform.GetComponent <Dove>();
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                        dove1.energy = dove1.energy - baseReqInt;
                    }
                    if (doves.Contains(competitor1) && hawks.Contains(competitor2))
                    {
                        Dove dove1 = competitor1.transform.GetComponent <Dove>();
                        Hawk hawk1 = competitor2.transform.GetComponent <Hawk>();
                        dove1.energy = dove1.energy - baseReqInt;
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                    }
                }
                int r = Random.Range(1, foods.Count) - 1;
                GameObject.DestroyImmediate(foods[r]);
                foods.RemoveAt(r);
            }
            else
            {
                foreach (GameObject hd in agents)
                {
                    if (hawks.Contains(hd))
                    {
                        Hawk hawk = hd.transform.GetComponent <Hawk>();
                        hawk.energy = hawk.energy - baseReqInt;
                    }
                    else
                    {
                        Dove dove = hd.transform.GetComponent <Dove>();
                        dove.energy = dove.energy - baseReqInt;
                    }
                }
                break;
            }
        }

        int hnumber = 0;
        int dnumber = 0;
        int fnumber = 0;
        int item    = 0;

        foreach (GameObject hd in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (hd.name == "Hawk(Clone)")
            {
                hnumber++;
            }
            if (hd.name == "Dove(Clone)")
            {
                dnumber++;
            }
            if (hd.name == "Food(Clone)" || hd.name == "Food")
            {
                fnumber++;
            }
        }


        if (null == m_DataDiagram)
        {
            return;
        }

        foreach (GameObject line in lineList)
        {
            if (item == 0)
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(hnumber / 10.0)));
            }
            else if (item == 1)
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(dnumber / 10.0)));
            }
            else
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(fnumber / 10.0)));
            }
            item++;
        }
    }
Beispiel #18
0
    public void Btn_Next_Click()
    {
        BroadcastMessage("Expiring");
        for (int i = 0; i < System.Convert.ToInt32(foodNum.text); i++)
        {
            spawnPrefab(foodPrefab);
        }

        List <GameObject> foods  = new List <GameObject>();
        List <GameObject> hawks  = new List <GameObject>();
        List <GameObject> doves  = new List <GameObject>();
        List <GameObject> agents = new List <GameObject>();

        foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (go.name == "Food(Clone)")
            {
                foods.Add(go);
            }
            else if (go.name == "Hawk(Clone)")
            {
                hawks.Add(go);
                agents.Add(go);
            }
            else if (go.name == "Dove(Clone)")
            {
                doves.Add(go);
                agents.Add(go);
            }
        }

        Debug.Log(foods.Count());
        while (agents.Count > 0)
        {
            if (foods.Count > 0)
            {
                if (agents.Count > 1)
                {
                    int        random1 = Random.Range(0, agents.Count - 1);
                    GameObject agent1  = agents[random1];
                    agents.RemoveAt(random1);
                    int        random2 = Random.Range(0, agents.Count - 1);
                    GameObject agent2  = agents[random2];
                    agents.RemoveAt(random2);
                    if (hawks.Contains(agent1) && hawks.Contains(agent2))
                    {
                        HawkManager hm = agent1.transform.GetComponent <HawkManager>();
                        hm.energy += (foodValueInt - baseReqInt);
                        HawkManager hm2 = agent2.transform.GetComponent <HawkManager>();
                        hm2.energy -= (injuryInt + baseReqInt);
                    }
                    else if (doves.Contains(agent1) && doves.Contains(agent2))
                    {
                        DoveManager dm = agent1.transform.GetComponent <DoveManager>();
                        dm.energy += (foodValueInt - bluffingInt - baseReqInt);
                        DoveManager dm2 = agent2.transform.GetComponent <DoveManager>();
                        dm2.energy -= (bluffingInt + baseReqInt);
                    }
                    else if (hawks.Contains(agent1) && doves.Contains(agent2))
                    {
                        HawkManager hm = agent1.transform.GetComponent <HawkManager>();
                        hm.energy += (foodValueInt - baseReqInt);
                        DoveManager dm = agent2.transform.GetComponent <DoveManager>();
                        dm.energy -= baseReqInt;
                    }
                    else
                    {
                        HawkManager hm = agent2.transform.GetComponent <HawkManager>();
                        hm.energy += (foodValueInt - baseReqInt);
                        DoveManager dm = agent1.transform.GetComponent <DoveManager>();
                        dm.energy -= baseReqInt;
                    }
                }
                else
                {
                    if (hawks.Contains(agents[0]))
                    {
                        HawkManager hm = agents[0].transform.GetComponent <HawkManager>();
                        hm.energy += (foodValueInt - baseReqInt);
                    }
                    else
                    {
                        DoveManager dm = agents[0].transform.GetComponent <DoveManager>();
                        dm.energy += (foodValueInt - baseReqInt);
                    }
                    agents.RemoveAt(0);
                }
                int random3 = Random.Range(0, foods.Count() - 1);
                GameObject.DestroyImmediate(foods[random3]);
                foods.RemoveAt(random3);
            }
            else
            {
                foreach (GameObject go in agents)
                {
                    if (hawks.Contains(go))
                    {
                        HawkManager hm = go.transform.GetComponent <HawkManager>();
                        hm.energy -= baseReqInt;
                    }
                    else
                    {
                        DoveManager dm = go.transform.GetComponent <DoveManager>();
                        dm.energy -= baseReqInt;
                    }
                }
                break;
            }
        }

        Debug.Log(foods.Count());

        int howkCount = 0;
        int doveCount = 0;

        foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (go.name == "Hawk(Clone)")
            {
                howkCount++;
            }
            else if (go.name == "Dove(Clone)")
            {
                doveCount++;
            }
        }

        Debug.Log(howkCount + "; " + doveCount);

        if (null == m_DataDiagram)
        {
            return;
        }

        int j = 0;

        foreach (GameObject l in lineList)
        {
            if (j == 0)
            {
                m_DataDiagram.InputPoint(l, new Vector2(1, (float)(howkCount / 10.0)));
            }
            else if (j == 1)
            {
                m_DataDiagram.InputPoint(l, new Vector2(1, (float)(doveCount / 10.0)));
            }
            else
            {
                m_DataDiagram.InputPoint(l, new Vector2(1, (float)((howkCount + doveCount) / 10.0)));
            }
            j++;
        }

        sb.Append(howkCount.ToString()).Append(",");
        sb.Append(doveCount.ToString()).Append(",");
        sb.Append((howkCount + doveCount).ToString()).Append(",");
    }
 public IEnumerator AsynchronousReadFromArduino()
 {
     while (readSerial)
     {
         if (stream != null)
         {
             if (stream.IsOpen)
             {
                 try
                 {
                     string data = stream.ReadLine();
                     print(data);
                     addText(data);
                     string[] dataSplit = data.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                     //string[] dataSplit = data.Split(',');
                     //Must have 6 parts to be counted as a row of data
                     if (dataSplit.Length == 6)
                     {
                         try
                         {
                             totalCount  = long.Parse(dataSplit[0]);
                             timeStamp   = long.Parse(dataSplit[1]);
                             measuredADC = int.Parse(dataSplit[2]);
                             sipmVolts   = float.Parse(dataSplit[3]);
                             deadTime    = long.Parse(dataSplit[4]);
                             temperature = float.Parse(dataSplit[5]);
                             print("Count: " + totalCount + ", Time Stamp: " + timeStamp + ", Measured ADC: " + measuredADC + ", SiPM Volts: " + sipmVolts + ", Dead time: " + deadTime + ", Temperature: " + temperature);
                             displayCount.text    = dataSplit[0];
                             temperatureText.text = string.Format("Temperture: {0:#0.0}°C", temperature);
                             sipmText.text        = string.Format("SiPM voltage estimate: {0:#0.00}mV", sipmVolts);
                             //If the arduino has been reset, restart the timer
                             if (totalCount == 1)
                             {
                                 isFirstTime = true;
                             }
                             //Calculate the difference in time between the application's timestamp and the arduino's time stamp.
                             //Because we trust thecomputer's clock more than the arduino's, we only calculate the difference once and use this to work out what the actual time should be.
                             if (isFirstTime)
                             {
                                 timeDiff           = ((float)timeStamp / 1000f) - Time.time;
                                 isFirstTime        = false;
                                 portsErrorMsg.text = "The connection has experienced success";
                             }
                             //float runningTime = Time.realtimeSinceStartup + timeDiff;
                             sipmGraph.InputPoint(sipmGraphLine, new Vector2(0.1f, sipmVolts));
                             deadTimeText.text = string.Format("Dead time: {0}%", 100 * deadTime / timeStamp);
                         }
                         catch (FormatException)
                         {
                             print("Could not format as a number");
                         }
                     }
                 }
                 catch (TimeoutException)
                 {
                 }
             }
         }
         yield return(new WaitForSeconds(0.25f));
     }
 }