Esempio n. 1
0
    //Three or four same, pair
    static void CalculateAmountOfSameDices(SingleLine sl, int threeOrFour)
    {
        int amount = 0; //points to be given if three same dices
        Dictionary <int, int> tempDict = new Dictionary <int, int>();

        foreach (int i in nums)
        {
            if (tempDict.ContainsKey(i))
            {
                tempDict[i] += 1;
            }
            else
            {
                tempDict.Add(i, 1);
            }
            amount += i;
        }

        //if the highest value in tempdict is equal or higher than the checked number, the dice row meets the requirements for giving points
        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value >= threeOrFour)
            {
                sl.SetDicePoints(amount);
                return;
            }
        }
        //HOX if there are enough of the same number code beyond this point(return) will not be executed
        sl.SetDicePoints(0);
    }
Esempio n. 2
0
 static void AddLocations(SingleLine line, List <string> branchNumbers)
 {
     branchNumbers.ForEach((b) =>
     {
         var location          = new Location();
         location.BranchNumber = b;
         line.Locations.Add(b, location);
     });
 }
        /// <summary>
        ///     Adds an entry for each requirement to the line requirments dict.
        /// </summary>
        /// <param name="line">Current line being sourced.</param>
        /// <param name="atgOrderRes">The ATG Order response that will be written to CosmosDB.</param>
        public void SetLineRequirements(SingleLine line, AtgOrderRes atgOrderRes)
        {
            if (LineRequiresOverpackLocation(line.MasterProductNumber, line.Quantity, atgOrderRes))
            {
                line.Requirements.Add("Overpack", true);
            }

            // Set requirements on the AtgOrder for use when setting sourcing messages
            atgOrderRes.items.FirstOrDefault(i => i.lineId == line.LineId).requirements = line.Requirements;
        }
Esempio n. 4
0
    //Random
    static void CalculateRandom(SingleLine sl)
    {
        int amount = 0;

        foreach (int i in nums)
        {
            amount += i;
        }
        sl.SetDicePoints(amount);
    }
 private void Start()
 {
     line = FindObjectOfType<SingleLine>();
     image = GetComponent<Image>();
     anim = transform.GetChild(1).GetComponent<Animator>();
     Border = transform.GetChild(1).gameObject;
     Border.GetComponent<Image>().color = new Color(1, 1, 1, 0);
     BaseText.text = "";
     PatternText.text = "";
     GreenText.GetComponent<TMP_Text>().text = "";
 }
Esempio n. 6
0
    /*
     * Creating lines
     */
    void CreateSheet()
    {
        bool hasUpperBonus = false; //does the sheet contain line for upperbonus. if not, the game has as many rounds as the sheet has lines. if yes rounds = sheet length -1. checked after the for loop

        TextAsset textAsset = Resources.Load <TextAsset>(sheetVersion);

        string[] lineArray = textAsset.text.Split('\n');
        sheetLines  = new SingleLine[lineArray.Length];
        lineObjects = new GameObject[lineArray.Length];
        for (int i = 0; i < lineArray.Length; i++)
        {
            string[]   tempLine = lineArray[i].Split('-');      //splitting line from text asset to id name and score
            GameObject lineGo;

            //creating new line
            if (tempLine[2] == "upBonus")
            {
                lineGo = Instantiate(upperBonusLinePrefab);
            }
            else
            {
                lineGo = Instantiate(linePrefab);
            }
            lineGo.transform.SetParent(lineParent.transform);   //parenting it
            lineGo.name    = tempLine[1];                       //change gameobject name
            lineObjects[i] = lineGo;                            //store the lines as gameobjects
            SingleLine sl = lineGo.GetComponent <SingleLine>(); //temp reference to the SingleLine of the object
            sheetLines[i]    = sl;                              //adding lines script to this scripts array
            sl.id            = System.Int32.Parse(tempLine[0]); //setting line's id, line name and possible score
            sl.lineName      = tempLine[1];
            sl.lineType      = tempLine[2];
            sl.pointsDefault = System.Int32.Parse(tempLine[3]);
            lineGo.GetComponent <Toggle>().group = lineParent.GetComponent <ToggleGroup>();   //set lines toggle group

            if (sl.lineType == "upBonus")
            { //line calculating the bonus for the lines 1-6 is not handled where other lines are calculated (because it does not rely on the dices, but scores from the upper section)
                upperBonusLine = sl;
                hasUpperBonus  = true;
            }
            if (sl.lineType == "yatzy")
            {  //if sheet has yatzy, it will have extra points for extra yatzys
                YatzyExtraPoints = sl.pointsDefault;
            }
        }
        //game has as many rounds as the sheet has lines, minus the upper bonus line
        if (hasUpperBonus)
        {
            GameManager.instance.roundsPerGame = sheetLines.Length - 1;
        }
        else
        {
            GameManager.instance.roundsPerGame = sheetLines.Length;
        }
    }
Esempio n. 7
0
    //small and large straight
    static void CalculateStraight(SingleLine sl, int numsInRow)
    {
        //numsinrow= how many dices needs to be in a row for a straight
        //small = 4 digits in row
        //large = 5 digits in row
        List <int> numsList = new List <int>(); //make nums into list so Sort() can be used

        //not adding duplicate values to numslist, they are not needed for checking straight
        foreach (int i in nums)
        {
            bool exists = numsList.Exists(digit => digit == i);
            if (!exists)
            {
                numsList.Add(i);
            }
        }
        numsList.Sort();



        //there has to be enough different values for a straight to be possible (longer the list more different numbers)
        if (numsList.Count < numsInRow)
        {
            sl.SetOtherPoints(false);
            return;
        }

        //if enough different values, proceed

        int count = 1; //how many values are in row (cant be zero there is always the first dice)

        for (int i = 1; i < numsList.Count; i++)
        {
            //the previuous value plus 1 should be same as current value
            if (numsList[i] == (numsList[i - 1] + 1))
            {
                count++;
            }
            else if (count < numsInRow)
            {//if not, start from one
                count = 1;
            }
        }
        //if enough numbers in row, give points
        if (count >= numsInRow)
        {
            sl.SetOtherPoints(true);
        }
        else
        {
            sl.SetOtherPoints(false);
        }
    }
Esempio n. 8
0
    //two pairs
    static void CalculateTwoPairs(SingleLine sl)
    {
        int amount = 0; //points to be given two pairs
        Dictionary <int, int> tempDict = new Dictionary <int, int>();

        foreach (int i in nums)
        {
            if (tempDict.ContainsKey(i))
            {
                tempDict[i] += 1;
            }
            else
            {
                tempDict.Add(i, 1);
            }
            amount += i;
        }
        //if tempdict has more than 3 kvps, two pairs is impossible, give 0 points
        if (tempDict.Count > 3)
        {
            sl.SetDicePoints(0);
            return;
        }
        //if the highest kvp value is 4 or more, the dice row is for example 11112, which counts as two pairs (2 sets of 1 1)
        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value >= 4)
            {
                sl.SetDicePoints(amount);
                return;
            }
        }
        //finally checking for two pairs, both with different digit (or a full house)
        int amountOfPairs = 0;

        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value == 2 || kvp.Value == 3)
            {
                amountOfPairs++;
            }
        }
        if (amountOfPairs >= 2)
        {
            sl.SetDicePoints(amount);
        }
        //if dice row is for example one pair or three same
        else
        {
            sl.SetDicePoints(0);
        }
    }
Esempio n. 9
0
        public void Test_SetAvailableLocationsOnAllLines()
        {
            SourcingEngine.allLines = new AllLines();

            var dcLine  = new SingleLine(123456, 8, 0);
            var dcLines = new List <SingleLine>()
            {
                dcLine
            };

            SourcingEngine.allLines.lineDict.Add("DC", dcLines);

            var feiLine  = new SingleLine(789654, 10, 1);
            var feiLines = new List <SingleLine>()
            {
                feiLine
            };

            SourcingEngine.allLines.lineDict.Add("FEI", feiLines);

            var locationDict = locationController.locations.LocationDict;

            var dcLocation = new Location();

            dcLocation.DCLocation = true;
            locationDict.Add("423", dcLocation);

            var branchLocation = new Location();

            branchLocation.BranchLocation = true;
            locationDict.Add("27", branchLocation);

            locationController.SetAvailableLocationsOnAllLines();

            Assert.Single(SourcingEngine.allLines.lineDict["DC"]);


            SourcingEngine.allLines.lineDict["DC"].ForEach(l =>
            {
                var branchNumbers = l.Locations.Select(x => x.Key);

                Assert.Single(branchNumbers);
            });

            SourcingEngine.allLines.lineDict["FEI"].ForEach(l =>
            {
                var branchNumbers = l.Locations.Select(x => x.Key);

                Assert.Equal(2, branchNumbers.Count());
            });
        }
Esempio n. 10
0
    //lines 1-6
    static void CalculateUpperPart(SingleLine sl)
    {
        int amount  = 0;
        int lineNum = System.Int32.Parse(sl.lineType.Replace("upper", ""));

        foreach (int i in nums)
        {
            if (i == lineNum)
            {
                amount += i;
            }
        }
        sl.SetDicePoints(amount);
    }
Esempio n. 11
0
 /// <summary>Export this pattern as XML</summary>
 public virtual XElement ToXml(XElement node)
 {
     node.Add
     (
         Expr.ToXml(XmlTag.Expr, false),
         Active.ToXml(XmlTag.Active, false),
         PatnType.ToXml(XmlTag.PatnType, false),
         IgnoreCase.ToXml(XmlTag.IgnoreCase, false),
         Invert.ToXml(XmlTag.Invert, false),
         WholeLine.ToXml(XmlTag.WholeLine, false),
         SingleLine.ToXml(XmlTag.SingleLine, false)
     );
     return(node);
 }
Esempio n. 12
0
    //Yatzy
    static void CalculateYatzy(SingleLine sl)
    {
        int digit = nums[0];

        foreach (int i in nums)
        {
            if (i != digit)
            {
                sl.SetOtherPoints(false);
                return;
            }
        }
        sl.SetOtherPoints(true);
    }
        public void Test_ValidatePickupLocation()
        {
            // Craete pickup lines
            var line1 = new SingleLine(123456, 10, 0);
            var line2 = new SingleLine(789654, 50, 1);

            var branchLines = new List <SingleLine>()
            {
                line1
            };
            var feiLines = new List <SingleLine>()
            {
                line2
            };

            var allLines = new Dictionary <string, List <SingleLine> >()
            {
                { "FEI", feiLines },
                { "Branch", branchLines }
            };

            var pickupLocation = "107";

            // Add inventory
            var item1Inventory = new ItemInventory();

            item1Inventory.Available.Add(pickupLocation, 80);

            var item2Inventory = new ItemInventory();

            item2Inventory.Available.Add(pickupLocation, 3);

            itemController.inventory.InventoryDict.Add(123456, item1Inventory);
            itemController.inventory.InventoryDict.Add(789654, item2Inventory);

            var pickupLocationHasInventory = sourcingController.ValidatePickupInventory(pickupLocation, allLines);

            var noInventoryFEILines = feiLines
                                      .Where(l => sourcingController.GetOrderItemByLineId(l.LineId).sourcingMessage == "This pickup location does not have the required quantity of inventory for the order line.")
                                      .Select(l => l);

            var noInventoryBranchLines = branchLines
                                         .Where(l => sourcingController.GetOrderItemByLineId(l.LineId).sourcingMessage == "This pickup location does not have the required quantity of inventory for the order line.")
                                         .Select(l => l);

            Assert.False(pickupLocationHasInventory);
            Assert.Empty(noInventoryBranchLines);
            Assert.Single(noInventoryFEILines);
        }
Esempio n. 14
0
 /// <summary>
 /// Button2 Clear Function
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     textBox_multi.Clear();
     SingleLine.Clear();
     panel_draw.Invalidate();
     circleObjects.Clear();
     rectangleObjects.Clear();
     variableObjects.Clear();
     polygonObjects.Clear();
     lineObjects.Clear();
     this.drawCircle  = false;
     this.drawRect    = false;
     this.movePointer = false;
     this.drawPolgon  = false;
 }
Esempio n. 15
0
        /// <summary>
        /// Update new profile data
        /// </summary>
        /// <param name="_p"></param>
        public void UpdateProfile(Profile _p)
        {
            // If new profile has stronger vertical base line and out of base line deviation limit, replace all stack
            // If new profile base line is in the base line deviation limit with the old one, update all column in each stack:
            // If the column in new profile has higher score, update the column info in old profile by the new one
            if (Math.Abs(_p.VerticalBaseLine.Value - this.vertical_base_line.Value) > ConfigParameters.PROFILING_MAX_V_BASE_LINE_DEVIATION)
            {
                if (_p.vertical_base_line.Score > this.vertical_base_line.Score)
                {
                    this.vertical_base_line = _p.vertical_base_line;
                    this.stacks             = _p.stacks;
                }
            }
            else
            if (stacks.Count == 0)
            {
                stacks = _p.stacks;
            }
            else
            {
                // update all column in old profile if the column data is stronger
                for (int i = 0; i < stacks.Count; i++)
                {
                    int num_of_col = _p.stacks[i].Columns.Count < stacks[i].Columns.Count
                                                ? _p.stacks[i].Columns.Count
                                                : stacks[i].Columns.Count;

                    for (int j = 0; j < num_of_col; j++)
                    {
                        Column current_col = new Column(stacks[i].Columns[j]);
                        Column new_col     = new Column(_p.stacks[i].Columns[j]);
                        if (new_col.Score > current_col.Score)
                        {
                            stacks[i].Columns[j].Quantity = new_col.Quantity;
                            stacks[i].Columns[j].Score    = new_col.Score;
                            stacks[i].Columns[j].ZPos     = new_col.ZPos;
                        }
                    }
                }
            }

            generateContainers();
        }
    }//MoveDown

    public void Confirm()
    {
        GetComponent<AudioSource>().Play();
        MoveDown();
        BaseNumber(no);
        foreach (Transform child in GameObject.Find("SingleLineParent").transform)
        {
            GameObject.Destroy(child.gameObject);
        }
        line.Reset();
        CurrentJump = no;
        Multiplication.CurrentJump = CurrentJump;
        Multiplication.StoredTotal = CurrentJump * 1;
        ButtonTest.JumpCount = 0;
        Multiplication.BaseChange = true;
        GreenText.GetComponent<TMP_Text>().text = "Tap " + no + " to start";
        if (no == 5)
        {
            SingleLine.A = GameObject.Find("00").transform.GetChild(3).transform;
            line.line.SetPosition(0, SingleLine.A.position);
            line.line.SetPosition(1, SingleLine.A.position);
            SingleLine.B = GameObject.Find("0"+Multiplication.StoredTotal).transform.GetChild(3).transform;
        }
        else
        {
            SingleLine.A = GameObject.Find("00").transform.GetChild(1).transform;
            SingleLine.B = GameObject.Find("0"+Multiplication.StoredTotal).transform.GetChild(1).transform;
        }

        SingleLine.NewCheckDistance(SingleLine.A, SingleLine.B);
        Pattern.PatternIsOver = false;
        Pattern.Count = 0;
        Star.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        SuperStar.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        Pentagon.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        YOYO.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        Multiplication.TempTens = 0;
        Multiplication.Red = false;
        AgainParent.SetActive(false);
        Pattern.PatternCount = 1;
        Pattern4.text = "";
        ButtonTest.start = true;
    }//Confirm
Esempio n. 17
0
    //line has been chosen, play it
    public void PlayRound()
    {
        //get the chosen line and do needed things in it
        Toggle     chosenToggle = lineToggleGroup.ActiveToggles().FirstOrDefault();
        SingleLine sl           = chosenToggle.GetComponent <SingleLine>();

        sl.PlayThis();

        clickBlocker.SetActive(true);

        GameManager.instance.playerInTurn.AddToPoints(sl.points); //send points to the players score

        //check the upper section if needed for the upper bonus
        if (sl.lineType.Contains("upper"))
        {
            upperPoints += sl.points;
            CheckUpperLine();
            upperBonusLine.UpperBonusUpdating(upperPoints);     //show upper points in sheet
        }
        //if line is first yatzy
        if (sl.lineType == "yatzy" && !yatzyPlayed)
        {
            if (currentLineIsYatzy)
            { //if yatzy has been played as zero, later yatzys wont give extra 50 points
                yatzyZeroPoints = false;
            }
            else
            {
                yatzyZeroPoints = true;
            }
            yatzyPlayed = true;
        }
        //if line is not yatzy, but dices are the same number and yatzy has not been played as 0. so give EXTRA POINTS!
        else if (yatzyPlayed && !yatzyZeroPoints && currentLineIsYatzy)
        {
            GameManager.instance.playerInTurn.AddToPoints(YatzyExtraPoints);
            //sl.extraPoints = YatzyExtraPoints;
            sl.ShowExtraPoints(YatzyExtraPoints);
            Debug.Log("EXTRA FIDDY");
        }
        ///////
        GameManager.instance.StartNextTurn();       //new round
    }
Esempio n. 18
0
    public void Convert()
    {
        var reader = new StreamReader(FilePath);

        Lines = new List <SingleLine>();
        //reader.ReadLine();
        while (!reader.EndOfStream)
        {
            string str      = reader.ReadLine();
            string timehead = str.Substring(1, 10);
            str = str.Substring(11);
            string plName = str.Split(']')[0].Substring(1);
            str = str.Split(']')[1];
            var line = new SingleLine {
                Content = str, StartTime = GetTimeStampFromString(timehead), PlayerName = plName
            };
            Lines.Add(line);
        }
        reader.Close();
    }
        /// <summary>
        ///     Determines if the specified location meets the item's sourcing requirements.
        /// </summary>
        /// <returns>true if the location meets the item's sourcing requirments.</returns>
        public bool DoesLocationMeetRequirements(SingleLine line, string guide, Location location)
        {
            var requirementDict = line.Requirements;
            var itemData        = itemController.items.ItemDict[line.MasterProductNumber];

            // Sourcing guide
            if (!MeetsSourcingGuidelineRequirement(location, guide))
            {
                return(false);
            }

            // Overpack
            requirementDict.TryGetValue("Overpack", out bool overPackRequired);

            if (overPackRequired && !MeetsOverPackRequirements(itemData, line.Quantity, location))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 20
0
    //full house
    static void CalculateFullHouse(SingleLine sl)
    {
        Dictionary <int, int> tempDict = new Dictionary <int, int>();

        foreach (int i in nums)
        {
            if (tempDict.ContainsKey(i))
            {
                tempDict[i] += 1;
            }
            else
            {
                tempDict.Add(i, 1);
            }
        }
        //checking if there is a 3x AND a pair, if yes, full house, else 0 points
        bool threeSame = false;
        bool pair      = false;

        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value == 3)
            {
                threeSame = true;
            }
            if (kvp.Value == 2)
            {
                pair = true;
            }
        }
        if (threeSame && pair)
        {
            sl.SetOtherPoints(true);
        }
        else
        {
            sl.SetOtherPoints(false);
        }
    }
    }//Update

    #endregion

    #region User Define Methods

    public void GetJumpNumber()
    {
        no = int.Parse(this.name);
        
        if (!ButtonTest.PatternIsRunning)
        {
            ButtonTest.start = true;
            BaseSelected = true;
            no = int.Parse(this.name);
            BaseNumber(no);
            FirstTimeDone = true;
            CurrentJump = no;
            Multiplication.CurrentJump = CurrentJump;
            Multiplication.StoredTotal = CurrentJump * 1;
            ButtonTest.JumpCount = 0;
            Multiplication.BaseChange = true;
            GreenText.GetComponent<TMP_Text>().text = "You start at 0, go around "+no+" and tap the number";
            if (no == 5)
            {
                SingleLine.A = GameObject.Find("00").transform.GetChild(3).transform;
                line.line.SetPosition(0, SingleLine.A.position);
                line.line.SetPosition(1, SingleLine.A.position);
                SingleLine.B = GameObject.Find("0" + Multiplication.StoredTotal).transform.GetChild(3).transform;
            }
            else
            {
                SingleLine.A = GameObject.Find("00").transform.GetChild(1).transform;
                SingleLine.B = GameObject.Find("0" + Multiplication.StoredTotal).transform.GetChild(1).transform;
            }
            SingleLine.NewCheckDistance(SingleLine.A, SingleLine.B);
        }//if First Check
        else
        {
            Up = true;
            BottomText.GetComponent<TMP_Text>().text = "";
        }
        GetComponent<AudioSource>().Play();
    }//GetJumpNumber
Esempio n. 22
0
        private Stack getMiddleStackProfile(Point3D[] points)
        {
            // Idea:
            // 1) Collect all point inside the middle section of middle container stack
            // 2) Get the strongest vertical line and set it as vertical base line if it meets the criterion
            // 3) Devide middle stack points according to x value of every columns calculated base on
            // the vertical base line and container column width
            // 4) Initial empty columns and add to list column
            // 5) Get the number of container in each column and the score of column
            //    Update in list empty columns

            List <Column>  middle_columns      = new List <Column>();
            List <Point3D> middle_stack_points = new List <Point3D>();
            List <Point3D> vertical_points     = new List <Point3D>();
            List <Point3D> horizontal_points   = new List <Point3D>();

            // filter points in middle z range of middle container stack
            foreach (Point3D point in points)
            {
                if (Math.Abs(point.Z) <= ConfigParameters.MIDDLE_STACK_SECTION_LENGTH_Z - ConfigParameters.Z_OFFSET)
                {
                    middle_stack_points.Add(point);
                }
            }

            // collect vertical and horizontal points
            foreach (Point3D point in middle_stack_points)
            {
                if (!isPointOnContainerLevel(point))
                {
                    vertical_points.Add(point);
                }
                else
                {
                    horizontal_points.Add(point);
                }
            }

            // collect the x array and y array to pass to get lines
            double[] x_arr = new double[vertical_points.Count];
            double[] y_arr = new double[vertical_points.Count];

            for (int i = 0; i < vertical_points.Count; i++)
            {
                x_arr[i] = vertical_points[i].X;
                y_arr[i] = vertical_points[i].Y;
            }

            // get the strongest vertical line
            SingleLine[] v_lines = getLines(x_arr, y_arr, ConfigParameters.PROFILING_VERTICAL_LINE_THICKNESS,
                                            ConfigParameters.PROFILING_VERTICAL_NUM_POINT_LIMIT, ConfigParameters.PROFILING_MERGE_LINE_DISTANCE);
            double container_column_width = ConfigParameters.CONTAINER_WIDTH + ConfigParameters.DEFAULT_SPACE_BETWEEN_COLUMN;

            // get the top line and update the vertical base line
            if (v_lines.Length > 0)
            {
                SingleLine top_line = v_lines[0];
                if (top_line.Score > vertical_base_line.Score)
                {
                    double new_base_line_value = top_line.Value - (int)(top_line.Value / container_column_width) * container_column_width;
                    vertical_base_line = new SingleLine(new_base_line_value, top_line.Score);
                    Logger.Log("New vertical base line: " + new_base_line_value + " with socre: " + top_line.Score);
                }
            }

            double start_column_x = vertical_base_line.Value;

            // get the height of every column in turn
            while (start_column_x + container_column_width < ConfigParameters.MAX_X_RANGE)
            {
                // collect all points within column range
                List <double> col_points_x = new List <double>();
                List <double> col_points_y = new List <double>();

                foreach (Point3D point in horizontal_points)
                {
                    if (point.X >= start_column_x && point.X < start_column_x + container_column_width)
                    {
                        col_points_x.Add(point.X);
                        col_points_y.Add(point.Y);
                    }
                }

                SingleLine[] h_lines = getLines(col_points_y.ToArray(), col_points_x.ToArray(), ConfigParameters.PROFILING_HORIZONTAL_LINE_THICKNESS,
                                                ConfigParameters.PROFILING_HORIZONTAL_NUM_POINT_LIMIT, ConfigParameters.PROFILING_MERGE_LINE_DISTANCE);

                // set deufault column height is 0
                SingleLine col_highest_line = new SingleLine(ConfigParameters.SENSOR_TO_GROUND_DISTANCE, 0);

                // TODO: check the minimum threshold of score for line in profile by change the zero score above
                if (h_lines.Length > 0)
                {
                    col_highest_line = h_lines[0];
                }

                int quantity = (int)Math.Round((ConfigParameters.SENSOR_TO_GROUND_DISTANCE - col_highest_line.Value) / ConfigParameters.CONTAINER_HEIGHT);

                middle_columns.Add(new Column(quantity, ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2, col_highest_line.Score));

                // move to next column
                start_column_x += container_column_width;
            }

            return(new Stack(middle_columns));
        }
Esempio n. 23
0
 private void Start()
 {
     line             = FindObjectOfType <SingleLine>();
     Button           = FindObjectOfType <BottomBarButtonScript>();
     ButtonTest.start = false;
 }
Esempio n. 24
0
 public Profile(SingleLine _v_base_line, List <Stack> _stacks)
 {
     this.vertical_base_line = _v_base_line;
     this.stacks             = _stacks;
     generateContainers();
 }
Esempio n. 25
0
 public Profile(Profile _p)
 {
     this.vertical_base_line = _p.VerticalBaseLine;
     this.stacks             = _p.stacks;
     generateContainers();
 }
Esempio n. 26
0
        private Stack getSideStackProfile(Point3D[] _points, Stack _middle_stack, bool _isRight)
        {
            // Idea:
            // 1) Collect all points in overlap range in middle container stack
            // 2) Divide them to many sections based on vertical based line of middle container stack
            // 3) Collect all the highest lines from those sections
            // 4) Compare to middle stack list column height to detect the overlap container
            // 5) Save overlap container information

            List <Column>  overlap_cols         = new List <Column>();
            List <Column>  side_stack_cols      = new List <Column>();
            List <Point3D> side_stack_points    = new List <Point3D>();
            List <Point3D> overlap_range_points = new List <Point3D>();

            // filter to get all point in the overlap range
            if (_isRight)
            {
                foreach (Point3D point in _points)
                {
                    if (point.Z < -ConfigParameters.MIDDLE_STACK_SECTION_LENGTH_Z && point.Z > -ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2 - ConfigParameters.Z_OFFSET)
                    {
                        overlap_range_points.Add(point);
                    }
                }
            }
            else
            {
                foreach (Point3D point in _points)
                {
                    if (point.Z > ConfigParameters.MIDDLE_STACK_SECTION_LENGTH_Z && point.Z < ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2 - ConfigParameters.Z_OFFSET)
                    {
                        overlap_range_points.Add(point);
                    }
                }
            }

            double container_column_width = ConfigParameters.CONTAINER_WIDTH + ConfigParameters.DEFAULT_SPACE_BETWEEN_COLUMN;

            //(new TIS_3dAntiCollision.UI.DataRepresentChart(overlap_range_points.ToArray())).Show();

            for (int i = 0; i < _middle_stack.Columns.Count; i++)
            {
                // find the highest line from points
                // get the point in range
                List <double> list_x_tmp = new List <double>();
                List <double> list_y_tmp = new List <double>();
                List <double> list_z_tmp = new List <double>();

                // collect all points within column range
                foreach (Point3D point in overlap_range_points)
                {
                    if (point.X >= i * container_column_width && point.X < (i + 1) * container_column_width)
                    {
                        list_x_tmp.Add(point.X);
                        list_y_tmp.Add(point.Y);
                        list_z_tmp.Add(point.Z);
                    }
                }

                // find the highest horizontal line -> exchange x & y
                SingleLine[] lines = getLines(list_y_tmp.ToArray(), list_x_tmp.ToArray(),
                                              ConfigParameters.PROFILING_HORIZONTAL_LINE_THICKNESS, ConfigParameters.PROFILING_HORIZONTAL_NUM_POINT_LIMIT,
                                              ConfigParameters.PROFILING_MERGE_LINE_DISTANCE);

                SingleLine highest_line = new SingleLine(ConfigParameters.SENSOR_TO_GROUND_DISTANCE, 0);

                // find the highest
                // but score of the highest must be higher than haft of score of the boldest line
                foreach (SingleLine l in lines)
                {
                    // TODO: Check the strong of line in here
                    if (l.Value < highest_line.Value && l.Score > lines[0].Score / 2 && l.Score != 0)
                    {
                        highest_line = new SingleLine(l.Value, l.Score);
                    }
                }

                // add empty column to list overlap column
                overlap_cols.Add(new Column());

                // compare to middle stack profile
                if (Math.Abs(highest_line.Value - (ConfigParameters.SENSOR_TO_GROUND_DISTANCE - _middle_stack.Columns[i].Quantity * ConfigParameters.CONTAINER_HEIGHT))
                    > ConfigParameters.CONTAINER_HEIGHT / 3)
                // detect and collect the overlap container
                {
                    double sum_z_tmp = 0;
                    int    z_count   = 0;
                    // collect all point in highest line to calculate the averate of z
                    for (int j = 0; j < list_x_tmp.Count; j++)
                    {
                        if (Math.Abs(list_y_tmp[j] - highest_line.Value) <= ConfigParameters.PROFILING_MERGE_LINE_DISTANCE / 2)
                        {
                            sum_z_tmp += list_z_tmp[j];
                            z_count++;
                        }
                    }
                    if (z_count != 0)
                    {
                        overlap_cols[i] = new Column((int)Math.Round((ConfigParameters.SENSOR_TO_GROUND_DISTANCE - highest_line.Value) / ConfigParameters.CONTAINER_HEIGHT),
                                                     _isRight ? sum_z_tmp / z_count
                                                        : sum_z_tmp / z_count + ConfigParameters.LEFT_STACK_CONTAINER_LENGTH,
                                                     highest_line.Score);
                    }
                }
            }

            //--- SIDE STACK PROFILING

            double start_side_stack_z = ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2 + ConfigParameters.DEFAULT_SPACE_BETWEEN_STACK;

            // collect the point of side container stack based on Z
            if (!_isRight)
            {
                foreach (Point3D point in _points)
                {
                    if (point.Z >= start_side_stack_z && point.Z <= start_side_stack_z + ConfigParameters.RIGHT_STACK_CONTAINER_LENGTH)
                    {
                        side_stack_points.Add(point);
                    }
                }
            }
            else
            {
                foreach (Point3D point in _points)
                {
                    if (point.Z <= -start_side_stack_z && point.Z >= -(start_side_stack_z + ConfigParameters.LEFT_STACK_CONTAINER_LENGTH))
                    {
                        side_stack_points.Add(point);
                    }
                }
            }

            double start_column_x = vertical_base_line.Value;

            while (start_column_x + container_column_width < ConfigParameters.MAX_X_RANGE)
            {
                // get level of every column
                // collect the point on each column
                List <double> list_x_tmp = new List <double>();
                List <double> list_y_tmp = new List <double>();

                foreach (Point3D point in side_stack_points)
                {
                    if (point.X >= start_column_x && point.X <= start_column_x + ConfigParameters.CONTAINER_WIDTH)
                    {
                        list_x_tmp.Add(point.X);
                        list_y_tmp.Add(point.Y);
                    }
                }

                SingleLine[] h_lines = getLines(list_y_tmp.ToArray(), list_x_tmp.ToArray(), ConfigParameters.PROFILING_HORIZONTAL_LINE_THICKNESS,
                                                ConfigParameters.PROFILING_HORIZONTAL_NUM_POINT_LIMIT, ConfigParameters.PROFILING_MERGE_LINE_DISTANCE);

                SingleLine col_highest_line = new SingleLine(ConfigParameters.SENSOR_TO_GROUND_DISTANCE, 0);

                // TODO: Check the strong of vertical line
                if (h_lines.Length > 0)
                {
                    col_highest_line = h_lines[0];
                }

                int quantity = (int)Math.Round((ConfigParameters.SENSOR_TO_GROUND_DISTANCE - col_highest_line.Value) / ConfigParameters.CONTAINER_HEIGHT);

                side_stack_cols.Add(new Column(quantity,
                                               _isRight? -ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2
                                               - ConfigParameters.DEFAULT_SPACE_BETWEEN_STACK
                                                        : ConfigParameters.MIDDLE_STACK_CONTAINER_LENGTH / 2 + ConfigParameters.DEFAULT_SPACE_BETWEEN_STACK
                                               + ConfigParameters.LEFT_STACK_CONTAINER_LENGTH,
                                               col_highest_line.Score));

                // move to next column
                start_column_x += container_column_width;
            }

            // Update overlap containers in side stack containers
            for (int i = 0; i < side_stack_cols.Count; i++)
            {
                // if same container quantity in same slot
                if (overlap_cols[i].Quantity == side_stack_cols[i].Quantity)
                {
                    // update the z position of the top container
                    side_stack_cols[i] = new Column(side_stack_cols[i].Quantity,
                                                    overlap_cols[i].ZPos,
                                                    overlap_cols[i].Score);
                }
            }


            return(new Stack(side_stack_cols));
        }
Esempio n. 27
0
        /// <summary>
        /// Get all the lines which contains points exceed the threshold. It will get the vertical lines by default
        /// </summary>
        /// <param name="points"></param>
        /// <param name="line_thickness"></param>
        /// <param name="num_point_limit"></param>
        /// <returns>Return the strongest line value with its score</returns>
        private SingleLine[] getLines(double[] x_arr, double[] y_arr, double line_thickness, int num_point_limit, double merge_distance)
        {
            SingleLine[] line_freq_arr = new SingleLine[0];

            List <double> list_line      = new List <double>();
            List <int>    list_frequency = new List <int>();

            double[] line_arr;
            int[]    frequency_arr;

            // sort array according to x
            Array.Sort(x_arr, y_arr);

            // round point value based on the thickness and count how many point on the line
            list_line.Add(0);
            list_frequency.Add(0);
            for (int i = 0; i < x_arr.Length; i++)
            {
                double rounded_num = Math.Round(x_arr[i] / line_thickness) * line_thickness;
                if (list_line[list_line.Count - 1] == rounded_num)
                {
                    list_frequency[list_frequency.Count - 1]++;
                }
                else
                {
                    list_line.Add(rounded_num);
                    list_frequency.Add(1);
                }
            }

            // filter the line that not meet the limited threshold
            for (int i = 0; i < list_frequency.Count; i++)
            {
                if (list_frequency[i] < num_point_limit)
                {
                    list_frequency.RemoveAt(i);
                    list_line.RemoveAt(i);
                    i--;
                }
            }

            // collecting all line that meet the threshold
            // clustering line based on width or height params
            // merging every line with its nearby lines
            if (list_line.Count > 0)
            {
                line_arr      = list_line.ToArray();
                frequency_arr = list_frequency.ToArray();

                // MERGE LINE
                Array.Sort(line_arr, frequency_arr);
                list_line.Clear();
                list_frequency.Clear();
                // init first value
                list_line.Add(line_arr[0]);
                list_frequency.Add(frequency_arr[0]);

                for (int i = 1; i < line_arr.Length; i++)
                {
                    if (line_arr[i] - list_line[list_line.Count - 1] <= merge_distance)
                    {
                        list_line[list_line.Count - 1] = (list_line[list_line.Count - 1] * list_frequency[list_frequency.Count - 1] + line_arr[i] * frequency_arr[i]) /
                                                         (list_frequency[list_frequency.Count - 1] + frequency_arr[i]);
                        list_frequency[list_frequency.Count - 1] += frequency_arr[i];
                    }
                    else
                    {
                        list_line.Add(line_arr[i]);
                        list_frequency.Add(frequency_arr[i]);
                    }
                }

                line_arr      = list_line.ToArray();
                frequency_arr = list_frequency.ToArray();

                // sort by frequency DES
                Array.Sort(frequency_arr, line_arr);
                Array.Reverse(frequency_arr);
                Array.Reverse(line_arr);

                line_freq_arr = new SingleLine[line_arr.Length];

                for (int i = 0; i < line_arr.Length; i++)
                {
                    line_freq_arr[i] = new SingleLine(line_arr[i], frequency_arr[i]);
                }
            }

            return(line_freq_arr);
        }