Ejemplo n.º 1
0
        public angleCheckStruct GetAngleCheckStruct(Vector2 startVec, Vector2 endVec)
        {
            angleCheckStruct curStruct = new angleCheckStruct();

            curStruct.angle            = GetAngleForVectors(startVec, endVec);
            curStruct.distance         = GetDistance(startVec, endVec);
            curStruct.asteroidLocation = endVec;
            return(curStruct);
        }
Ejemplo n.º 2
0
        public AsteroidField(string[] sourceData)
        {
            ySize         = sourceData.Length;
            xSize         = sourceData[0].Length;
            asteroidField = new CellContentsStruct[xSize * ySize];

            for (int intJ = 0; intJ < sourceData.Length; intJ++)
            {
                for (int intI = 0; intI < sourceData[intJ].Length; intI++)
                {
                    CellContentsStruct curStruct = new CellContentsStruct();
                    curStruct.curChar = sourceData[intJ][intI];
                    asteroidField[(intJ * xSize) + intI] = curStruct;
                }
            }



            for (int intI = 0; intI < asteroidField.Length; intI++)
            {
                if (asteroidField[intI].curChar == '.')
                {
                    continue;
                }
                Vector2 startVec = new Vector2();
                startVec = Helpers.GetCoordinatesFromIndex(intI, xSize);
                asteroidField[intI].curAngles     = new Dictionary <Vector2, angleCheckStruct>();
                asteroidField[intI].angleDistance = new Dictionary <double, List <angleCheckStruct> >();
                for (int intJ = 0; intJ < asteroidField.Length; intJ++)
                {
                    if (intI != intJ) // skip if it's us
                    {
                        if (asteroidField[intJ].curChar != '.')
                        {
                            Vector2          endVec       = Helpers.GetCoordinatesFromIndex(intJ, xSize);
                            angleCheckStruct curAngleData = GetAngleCheckStruct(startVec, endVec);
                            asteroidField[intI].curAngles[endVec] = curAngleData;
                            if (asteroidField[intI].angleDistance.ContainsKey(curAngleData.angle))
                            {
                                asteroidField[intI].angleDistance[curAngleData.angle].Add(curAngleData);
                            }
                            else
                            {
                                List <angleCheckStruct> newAngleList = new List <angleCheckStruct>();
                                newAngleList.Add(curAngleData);
                                asteroidField[intI].angleDistance.Add(curAngleData.angle, newAngleList);
                            }
                        }
                    }
                }

                /*int visibleAsteroids = asteroidField[intI].angleDistance.Count;
                 * if(visibleAsteroids> visibleCount)
                 * {
                 *  visibleCount= visibleAsteroids;
                 *  visibleIndex= intI;
                 * }*/
            }
            for (int intI = 0; intI < asteroidField.Length; intI++)
            {
                if (asteroidField[intI].curChar == '#')
                {
                    if (asteroidField[intI].angleDistance.Count > visibleCount)
                    {
                        visibleCount = asteroidField[intI].angleDistance.Count;
                        visibleIndex = intI;
                    }
                }
            }
        }