public static MinValue GetMinValue(float3 position, MapValues values, float3 goal, NativeList <float> matrix)
        {
            var index = QuadrantVariables.IndexFromPosition(position, position, values);

            if (goalPoints.Length <= 0)
            {
                return(new MinValue()
                {
                    index = index.key,
                    offsetVector = new float3(0, 0, 0),
                    value = 0f,
                    goalPoint = goal,
                });
            }
            var min = ClosestGoalPoint(goal);

            if (index.key < 0)
            {
                return(new MinValue()
                {
                    index = index.key,
                    offsetVector = new float3(0, 0, 0),
                    value = 0f,
                    goalPoint = goal,
                });
            }
            return(GetMinValue(index.key + min * values.LayerSize, values, min, matrix));
        }
Esempio n. 2
0
 private void CheckInMap(int i, int j, MapValues value, ref int sum)
 {
     if (Map[i, j] == value)
     {
         sum++;
     }
     CheckForVictoryConditions(sum);
 }
        public static bool IsIn(int index, MapValues values)
        {
            var small  = index % values.LayerSize;
            var height = small / values.heightPoints;
            var width  = small % values.heightPoints;

            return(!(height < 1 || width < 1 || height > values.heightPoints - 2 || width > values.widthPoints - 2));
        }
Esempio n. 4
0
 public void SetValues(MapValues mapValues, int sector, float plusSpeed = 0)
 {
     this.mapValues = mapValues;
     distance       = mapValues.StartDistance;
     this.sector    = sector;
     speed          = MapObjectGenerator.Speed + plusSpeed;
     minDistance    = mapValues.EndDistance;
 }
Esempio n. 5
0
        public object GetEndGameMessage(MapValues winner)
        {
            DialogResult result = MessageBox.Show($"Player {winner} win!\rDo you want to continue round?",
                                                  "The End",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.None,
                                                  MessageBoxDefaultButton.Button1,
                                                  MessageBoxOptions.DefaultDesktopOnly);

            return(result);
        }
Esempio n. 6
0
    public MapGenerator(MapValues mapValues, float distance, float resolution)
    {
        Vector3 farLeft = -mapValues.right.normalized * mapValues.sectorSize * (mapValues.sectorNumber / 2.0f);

        for (int i = 0; i < mapValues.sectorNumber; i++)
        {
            Vector3 currentLeft  = farLeft + mapValues.right.normalized * mapValues.sectorSize * i;
            Vector3 currentRight = farLeft + mapValues.right.normalized * mapValues.sectorSize * (i + 1f);
            meshElements.Add(new SectorMesh(currentLeft, currentRight, mapValues.curve, distance, resolution));
        }
    }
 private static void SetMinValue(ref MinValue tmp, int index, MapValues value, float3 offsetvector, NativeList <float> matrix)
 {
     if (IsIn(index, value))
     {
         var next = matrix[index];
         if (next >= 0f && next < tmp.value)
         {
             tmp.value        = next;
             tmp.index        = index;
             tmp.offsetVector = offsetvector;
         }
     }
 }
Esempio n. 8
0
 // Start is called before the first frame update
 void Start()
 {
     Speed     = speed;
     mesh      = GetComponent <MapMesh>();
     mapValues = mesh.mapValues;
     NewRule();
     sideRuleSet.Set(mapValues, enviroment, transform);
     StartCoroutine(sideRuleSet.MakeAll());
     MakeSideObjects();
     if (gameOver != null)
     {
         gameOver.continueGame += Continue;
     }
 }
 private void Debug(MapValues values, int groupId, Color color)
 {
     DebugProxy.Log("Debug Draw Before");
     if (goalPoints.Length == 0 || groupId < 0)
     {
         return;
     }
     DebugProxy.Log("Debug Draw");
     for (int index = values.LayerSize * groupId; index < values.LayerSize * (groupId + 1); index += 7)
     {
         var small  = index % values.LayerSize;
         var height = small / values.heightPoints;
         var width  = small % values.heightPoints;
         var point  = QuadrantVariables.ConvertToWorld(new float3(height, 0, width), values);
         if (densityMatrix[index] > 0f)
         {
             var minValue = GetMinValue(index, Map.Values, groupId, ShortestPathSystem.densityMatrix);
             DebugProxy.DrawLine(point, point + minValue.offsetVector, color);
         }
     }
 }
Esempio n. 10
0
        public static BilinearData BilinearInterpolation(float3 position, MapValues max)
        {
            var indexPosition = ConvertToLocal(position, max);
            var iMin          = math.clamp((int)math.floor(indexPosition.x), 0, max.widthPoints - 1);
            var iMax          = math.clamp((int)math.ceil(indexPosition.x), 0, max.widthPoints - 1);
            var jMin          = math.clamp((int)math.floor(indexPosition.z), 0, max.heightPoints - 1);
            var jMax          = math.clamp((int)math.ceil(indexPosition.z), 0, max.heightPoints - 1);
            var ipercent      = indexPosition.x - iMin;
            var jpercent      = indexPosition.z - jMin;

            return(new BilinearData()
            {
                Index0 = Index(iMin, jMin, max),
                Index1 = Index(iMax, jMin, max),
                Index2 = Index(iMin, jMax, max),
                Index3 = Index(iMax, jMax, max),
                percent0 = (1f - ipercent) * (1f - jpercent),
                percent1 = (ipercent) * (1f - jpercent),
                percent2 = (1f - ipercent) * (jpercent),
                percent3 = (ipercent) * (jpercent)
            });
        }
        private static MinValue GetMinValue(int index, MapValues value, int goalIndex, NativeList <float> matrix)
        {
            var density = matrix[index];

            MinValue tmp = new MinValue()
            {
                index        = 0,
                value        = density,
                offsetVector = float3.zero,
                goalPoint    = goalPoints[goalIndex],
            };

            SetMinValue(ref tmp, index - 1, value, new float3(0, 0, -1) / (float)value.density, matrix);
            SetMinValue(ref tmp, index + 1, value, new float3(0, 0, 1) / (float)value.density, matrix);
            SetMinValue(ref tmp, index - value.heightPoints, value, new float3(-1, 0, 0) / (float)value.density, matrix);
            SetMinValue(ref tmp, index + value.heightPoints, value, new float3(1, 0, 0) / (float)value.density, matrix);

            SetMinValue(ref tmp, index - 1 + value.heightPoints, value, new float3(1, 0, -1) / (float)value.density, matrix);
            SetMinValue(ref tmp, index + 1 + value.heightPoints, value, new float3(1, 0, 1) / (float)value.density, matrix);
            SetMinValue(ref tmp, index - 1 - value.heightPoints, value, new float3(-1, 0, -1) / (float)value.density, matrix);
            SetMinValue(ref tmp, index + 1 - value.heightPoints, value, new float3(-1, 0, 1) / (float)value.density, matrix);
            return(tmp);
        }
Esempio n. 12
0
 private static bool CheckForWin(MapValues value)
 {
     if (map[0, 0] == value && map[0, 1] == value && map[0, 2] == value)
     {
         return(true);
     }
     if (map[1, 0] == value && map[1, 1] == value && map[1, 2] == value)
     {
         return(true);
     }
     if (map[2, 0] == value && map[2, 1] == value && map[2, 2] == value)
     {
         return(true);
     }
     if (map[0, 0] == value && map[1, 1] == value && map[2, 2] == value)
     {
         return(true);
     }
     if (map[2, 0] == value && map[1, 1] == value && map[0, 2] == value)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 13
0
        public static KeyDistance IndexFromPosition(float3 realWorldPosition, float3 prev, MapValues max)
        {
            var indexPosition = ConvertToLocal(realWorldPosition, max);
            var i             = math.clamp((int)math.round(indexPosition.x), 0, max.widthPoints - 1);
            var j             = math.clamp((int)math.round(indexPosition.z), 0, max.heightPoints - 1);

            return(new KeyDistance()
            {
                key = Index(i, j, max),
                distance = math.length(ConvertToLocal(prev, max) - math.round(indexPosition)),
            });
        }
Esempio n. 14
0
 public void Set(MapValues mapValues, Enviroment enviroment, Transform parent)
 {
     this.mapValues  = mapValues;
     this.enviroment = enviroment;
     this.parent     = parent;
 }
Esempio n. 15
0
 public static int Index(int i, int j, MapValues max)
 {
     return((max.heightPoints * i) + j);
 }
Esempio n. 16
0
 public void ChangeTurnLabel(MapValues value)
 {
     PlayerLable.Text = $"Turn now: PLayer {value}";
 }
Esempio n. 17
0
 public static float3 ConvertToWorld(float3 position, MapValues max)
 {
     return(position * (1f / Map.density) - new float3(max.maxWidth, 0, max.maxHeight) + max.offset);
 }
Esempio n. 18
0
 public static void PutValuesInMap(MapValues[,] map, string buttonName, MapValues value)
 {
     map[Int32.Parse(buttonName[1].ToString()), Int32.Parse(buttonName[2].ToString())] = value;
 }
Esempio n. 19
0
 private static float3 ConvertToLocal(float3 realWorldPosition, MapValues max)
 {
     return((realWorldPosition - max.offset + new float3(max.maxWidth, 0, max.maxHeight)) * Map.density);
 }
Esempio n. 20
0
        private static List <(int, int)> CheckForVictoryCombination(MapValues value)
        {
            if ((map[0, 0] == value || map[0, 0] == MapValues.Null) && (map[0, 2] == value || map[0, 2] == MapValues.Null) && (map[2, 2] == value || map[2, 2] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 0),
                           (0, 2),
                           (2, 2)
                       }
            }
            ;

            if ((map[0, 0] == value || map[0, 0] == MapValues.Null) && (map[0, 2] == value || map[0, 2] == MapValues.Null) && (map[2, 0] == value || map[2, 0] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 0),
                           (0, 2),
                           (2, 0)
                       }
            }
            ;

            if ((map[0, 0] == value || map[0, 0] == MapValues.Null) && (map[2, 0] == value || map[2, 0] == MapValues.Null) && (map[2, 2] == value || map[2, 2] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 0),
                           (2, 0),
                           (2, 2)
                       }
            }
            ;


            if ((map[0, 2] == value || map[0, 2] == MapValues.Null) && (map[2, 0] == value || map[2, 0] == MapValues.Null) && (map[2, 2] == value || map[2, 2] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 2),
                           (2, 0),
                           (2, 2)
                       }
            }
            ;

            if ((map[0, 0] == value || map[0, 0] == MapValues.Null) && (map[1, 1] == value || map[1, 1] == MapValues.Null) && (map[0, 2] == value || map[0, 2] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 0),
                           (1, 1),
                           (0, 2)
                       }
            }
            ;

            if ((map[0, 0] == value || map[0, 0] == MapValues.Null) && (map[1, 1] == value || map[1, 1] == MapValues.Null) && (map[2, 0] == value || map[2, 0] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (0, 0),
                           (1, 1),
                           (2, 0)
                       }
            }
            ;

            if ((map[2, 2] == value || map[2, 2] == MapValues.Null) && (map[1, 1] == value || map[1, 1] == MapValues.Null) && (map[2, 0] == value || map[2, 0] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (2, 2),
                           (1, 1),
                           (2, 0)
                       }
            }
            ;

            if ((map[2, 2] == value || map[2, 2] == MapValues.Null) && (map[1, 1] == value || map[1, 1] == MapValues.Null) && (map[0, 2] == value || map[0, 2] == MapValues.Null))
            {
                return new List <(int, int)>
                       {
                           (2, 2),
                           (1, 1),
                           (0, 2)
                       }
            }
            ;


            return(new List <(int, int)> {
                (0, 0)
            });
Esempio n. 21
0
 public object GetEndGameMessage(MapValues winner)
 {
     GameState.EndGame.CurrentWinner      = winner.ToString();
     GameState.EndGame.ShowEndGameMessage = true;
     return("Yes");
 }
Esempio n. 22
0
        public object GetEndGameMessage(MapValues winner)
        {
            object a = null;

            return(a);
        }