//Display the results in the required format
        public static Models.ResultFromrun formatOutput(pathData minValue)
        {
            nodesOnpath = String.Empty;

            pathData result = minValue;


            minpathValue = result.minValue.ToString();


            String sReplace = result.rows.Replace(",", String.Empty);

            char[] s1 = sReplace.ToCharArray();

            foreach (var item in s1)
            {
                nodesOnpath += (Int32.Parse(item.ToString()) + 1).ToString();
            }



            if (s1.Length == ColumnGlobal)
            {
                TravelledFromOneEndofMatrixToNext = "Yes";
            }
            else
            {
                TravelledFromOneEndofMatrixToNext = "No";
            }


            ResultFromrun Finalresult = new ResultFromrun(minpathValue, nodesOnpath, TravelledFromOneEndofMatrixToNext);

            return(Finalresult);
        }
示例#2
0
    //take inputs and apply path to unit/followers
    public void setPath(List <pathData> _path, float _delay, float parentDelay)
    {
        //set unit path to input
        for (int a = 0; a < _path.Count; a++)
        {
            pathData temp = new pathData(_path[a].path, _path[a].speed);
            path.Add(temp);
        }

        //add artificial delay based on inputs
        if (_delay != 0)
        {
            totalDelay = _delay + parentDelay;
            delay      = totalDelay;
        }

        //check if any followers
        if (follower != null)
        {
            foreach (unitWay obj in follower)
            {
                obj.setPath(_path, _delay, totalDelay);
            }
        }
    }
示例#3
0
    public void setPath(pathData _path, float _delay, float parentDelay)
    {
        List <pathData> temp = new List <pathData> ();

        temp.Add(_path);
        setPath(temp, _delay, parentDelay);
    }
示例#4
0
    void stateTakeCover()
    {
        //move to cover
        Debug.Log(Vector3.Distance(coverPos, transform.position));
        if (Vector3.Distance(coverPos, transform.position) < minDist + transform.localScale.y &&
            GetComponent <NavMeshAgent> ().remainingDistance < minDist)
        {
            //recharge peak cool down
            peakingCoolDown -= Time.deltaTime;

            //do crouching actions
            if (GameObject.FindObjectOfType <unitWaypoint> ().cover [index].lowCover &&
                peakingCoolDown > 0)
            {
                if (transform.localScale == startScale)
                {
                    transform.localScale = new Vector3(0.5f, 0.4f, 0.5f);
                }
            }
            else
            {
                //test if enemy can still see me
                if (enemyTarget)
                {
                    Debug.DrawLine(transform.position, enemyTarget.transform.position);
                    if (path.Count != 0)
                    {
                        if (path [0] == prevPath)
                        {
                            if (!ignoreIndex.Contains(index))
                            {
                                ignoreIndex.Add(index);
                            }
                        }
                        else
                        {
                            ignoreIndex.Clear();
                        }
                        prevPath = path [0];
                    }
                    else
                    {
                        if (!ignoreIndex.Contains(index))
                        {
                            ignoreIndex.Add(index);
                        }
                    }
                    GameObject.FindObjectOfType <unitWaypoint> ().requestCover(this, false, false, false, ignoreIndex);
                }
            }
        }
        else
        {
            //move to cover pos
            if (GetComponent <NavMeshAgent> ().destination != coverPos)
            {
                GetComponent <NavMeshAgent> ().SetDestination(coverPos);
            }
        }
    }
示例#5
0
        //Generate all possible paths runs. Each run has (weightedCost, nodes in the path)
        public static pathData GenerateSmallestPossiblePaths(int rows, int columns)
        {
            pathData[] RunContext        = new pathData[rows];
            var        listOfRunContenxt = new List <pathData> ();

            for (int i = 0; i < rows; i++)
            {
                //Call shortest path algorithim
                RunContext[i] = shortestPathHelperFunctions.cost(i, columns - 1);
                listOfRunContenxt.Add(RunContext [i]);
            }

            //This part is to get the least costly path from all the runs
            pathData minValue = new pathData(RunContext[0].minValue, RunContext[0].rows.ToString(), RunContext[0].columns.ToString());

            foreach (var item in listOfRunContenxt)
            {
                if (item.minValue < minValue.minValue)
                {
                    minValue.minValue = item.minValue;
                    minValue.rows     = item.rows;
                    minValue.columns  = item.columns;
                }
            }

            return(minValue);
        }
        //Generate all possible paths runs. Each run has (weightedCost, nodes in the path)
        public static pathData GenerateSmallestPossiblePaths(int rows, int columns)
        {
            pathData[] RunContext        = new pathData[rows];
            var        listOfRunContenxt = new List <pathData>();



            if (turns == 0)
            {
                columns = 0;
            }
            else
            {
                //no change ... keep the n-1 column
            }



            for (int i = 0; i < rows; i++)
            {
                //Call shortest path algorithim
                RunContext[i] = shortestPathHelperFunctions.cost(i, columns);
                listOfRunContenxt.Add(RunContext[i]);
            }

            //This part is to get the least costly path from all the runs
            pathData minValue = new pathData(RunContext[0].minValue, RunContext[0].rows.ToString(), RunContext[0].columns.ToString());

            foreach (var item in listOfRunContenxt)
            {
                if (item.minValue < minValue.minValue)
                {
                    minValue.minValue = item.minValue;
                    minValue.rows     = item.rows;
                    minValue.columns  = item.columns;
                }
            }

            if (turns == 0)
            {
                return(minValue);
            }

            else
            {
                minValue.minValue -= sourcematrix[rows - 1, columns]; //remove overlapping element to neutralize the double counting that happens. as the same element gets counted twice when overlapping occurs to maintain continuity.

                var rowArray    = minValue.rows.Split(',');
                var columnArray = minValue.columns.Split(',');

                rowArray    = rowArray.Skip(1).ToArray();
                columnArray = columnArray.Skip(1).ToArray();

                minValue.rows    = String.Empty;
                minValue.columns = String.Empty;

                for (int i = 0; i < rowArray.Length; i++)
                {
                    minValue.rows += rowArray[i].ToString() + ",";
                }

                for (int i = 0; i < columnArray.Length; i++)
                {
                    minValue.columns += columnArray[i].ToString() + ",";
                }

                String s1 = minValue.rows.Remove(minValue.rows.Length - 1);
                String s2 = minValue.columns.Remove(minValue.columns.Length - 1);
                minValue.rows    = s1;
                minValue.columns = s2;

                return(minValue);
            }
        }