private static int DepthLimitedDfs(OpcodeComputer opcodeComputer, int j, int depthLimit, int depth)
        {
            if (depth == depthLimit)
            {
                return(-1);
            }

            for (int i = 1; i < 5; i++)
            {
                if (i == j)
                {
                    continue;
                }
                opcodeComputer.SetInput(i);
                var output = opcodeComputer.GetOutput();

                if (output == 0)
                {
                    continue;
                }

                if (output == 2)
                {
                    Console.WriteLine(depthLimit);
                    var visitedPositions         = new HashSet <(int x, int y)>();
                    var lastVisitedPositionCount = -1;
                    int l;
                    for (l = depthLimit; lastVisitedPositionCount != visitedPositions.Count; l++)
                    {
                        lastVisitedPositionCount = visitedPositions.Count;
                        Console.WriteLine(lastVisitedPositionCount);
                        MapSpace(opcodeComputer, 0, l, 0, (0, 0), visitedPositions);
                    }
                    Console.WriteLine(l - 2);

                    return(1);
                }

                int k    = i % 2 == 0 ? i - 1 : (i + 1);
                var dist = DepthLimitedDfs(opcodeComputer, k, depthLimit, depth + 1);
                if (dist != -1)
                {
                    return(dist + 1);
                }
                opcodeComputer.SetInput(k);
                if (opcodeComputer.GetOutput() == 0)
                {
                    throw new InvalidDataException("WAT");
                }
            }
            return(-1);
        }
Example #2
0
        public Map(int height, int width)
        {
            Height = height;
            Width  = width;

            MapSpaces = new MapSpace[Height, Width];
        }
Example #3
0
    //build all the game objects from new mapSpaces array
    public void buildWorldFromMapSpaces()
    {
        for (int y = 0; y < map.getYLength(); y++)
        {
            for (int z = 0; z < map.getZLength(); z++)
            {
                for (int x = 0; x < map.getXLength(); x++)
                {
                    Interactible curInteractible = map.GetInteractible(new Vector3(x, y, z));
                    if (curInteractible != null && curInteractible.gameObjectScript == null)
                    {
                        instantiateInteractible(curInteractible, new Vector3(x, y, z));
                    }

                    MapSpace space = map.getMapSpace(new Vector3(x, y, z));

                    instantiateFloor(space.floorType, new Vector3(x, y, z));
                    instantiateWall(space.leftWall, new Vector3(x, y, z), WallOrientation.left);
                    instantiateWall(space.rightWall, new Vector3(x, y, z), WallOrientation.right);
                    instantiateWall(space.frontWall, new Vector3(x, y, z), WallOrientation.front);
                    instantiateWall(space.backWall, new Vector3(x, y, z), WallOrientation.back);
                }
            }
        }
    }
Example #4
0
        public void MapSpaceClick(object sender, RoutedEventArgs e)
        {
            MapSpace space = GetAssociatedMapSpaceFromButton((Button)sender);

            output.postMessage(space.X.ToString() + ", " + space.Y.ToString());
            output.postMessage(Enum.GetName(typeof(TerrainTypes), space.TerrainType));
        }
        public void GetAdjacentSpacesTests(string stateInput, int location, int[] expectedResults)
        {
            var      state         = State.Parse(stateInput);
            MapSpace startLocation = state.Map[location];

            MapSpace[] result = state.GetEmptyAdjacentSpaces(startLocation).ToArray();

            Assert.That(result, Has.Length.EqualTo(expectedResults.Length));
            IEnumerable <int> resultLocations = result.Select(x => x.Location);

            Assert.That(resultLocations, Is.EquivalentTo(expectedResults));
        }
 void Start()
 {
     for (int x = 0; x < 16; x++) {
         for (int y = 0; y < 9; y++) {
             map [x,y] = MapSpace.create(gameObject, new Vector3 (x - 7.5f, y - 4f),x,y);
         }
     }
     vehicles.Add (Airplane.create (this, map [0,8]));
     vehicles.Add (Train.create (this, map [0,0]));
     vehicles.Add (Boat.create (this, map [15,8]));
     depotSpace = map [15, 0];
     depotSpace.makeDepot ();
 }
Example #7
0
 //this is the constructor for the Airplane class.
 public static Vehicle create(GameControl controller, MapSpace startSpace)
 {
     GameObject go = Instantiate (prefab, startSpace.transform.position + Airplane.offset, Quaternion.identity) as GameObject;
     Airplane A = go.AddComponent<Airplane> ();
     A.myOrigin = startSpace;
     A.myLocation = startSpace;
     A.myDestination = startSpace;
     A.myControl = controller;
     A.myMaxCargo = 90;
     A.turnsUntilMove = 1;
     A.myMoveRate = 1;
     Color temp = Color.red; temp.a = 0.5f;
     go.GetComponent<Renderer> ().material.color = temp;
     go.GetComponent<ParticleSystem> ().startColor = Color.red;
     startSpace.addLocal (A);
     startSpace.addComing (A);
     return A;
 }
Example #8
0
 //this is the constructor for the Train class.
 public static Vehicle create(GameControl controller, MapSpace startSpace)
 {
     GameObject go = Instantiate (prefab, startSpace.transform.position + Vehicle.offset, Quaternion.identity) as GameObject;
     Train T = go.AddComponent<Train> ();
     T.myOrigin = startSpace;
     T.myLocation = startSpace;
     T.myDestination = startSpace;
     T.myControl = controller;
     T.myMaxCargo = 200;
     T.turnsUntilMove = 1;
     T.myMoveRate = 2;
     Color temp = Color.green; temp.a = 0.5f;
     go.GetComponent<Renderer> ().material.color = temp;
     go.GetComponent<ParticleSystem> ().startColor = Color.green;
     startSpace.addLocal (T);
     startSpace.addComing (T);
     return T;
 }
Example #9
0
 //this is the constructor for the Boat class.
 public static Vehicle create(GameControl controller, MapSpace startSpace)
 {
     GameObject go = Instantiate (prefab, startSpace.transform.position + Vehicle.offset, Quaternion.identity) as GameObject;
     Boat B = go.AddComponent<Boat> ();
     B.myOrigin = startSpace;
     B.myLocation = startSpace;
     B.myDestination = startSpace;
     B.myControl = controller;
     B.myMaxCargo = 550;
     B.turnsUntilMove = 1;
     B.myMoveRate = 3;
     Color temp = Color.blue; temp.a = 0.5f;
     go.GetComponent<Renderer> ().material.color = temp;
     go.GetComponent<ParticleSystem> ().startColor = Color.blue;
     startSpace.addLocal (B);
     startSpace.addComing (B);
     return B;
 }
Example #10
0
        public void UpdateZoom(double percent, Boolean create, string[] mapSections)
        {
            canvas.Width  = 2700 * percent;
            canvas.Height = canvas.Width / yLength / 0.9 * xLength;

            string[] townY   = { };
            string[] infraY  = { };
            string[] forestY = { };
            TerrainTypes[,] terrainMap = { };

            if (create)
            {
                terrainMap = new TerrainTypes[xLength, yLength];

                string[] terrainY = mapSections[1].Split('{');

                for (int i = 0; i < yLength; i++)
                {
                    string[] terrainX = terrainY[i].Split(';');

                    for (int o = 0; o < xLength; o++)
                    {
                        int Value = Convert.ToInt16(terrainX[o]);
                        terrainMap[i, o] = (TerrainTypes)Value;
                    }
                }

                townY = mapSections[2].Split('{');

                infraY = mapSections[3].Split('{');

                forestY = mapSections[4].Split('{');
            }

            Boolean isOdd  = true;
            double  height = canvas.Height / yLength;
            double  width  = canvas.Width / xLength;
            double  xMod   = 0;
            double  yMod   = 0;

            for (int y = 0; y < yLength; y++)
            {
                isOdd = !isOdd;

                yMod = y * (0.75 * height);

                string[] townX   = { };
                string[] infraX  = { };
                string[] forestX = { };

                if (create)
                {
                    townX = townY[y].Split(';');

                    infraX = infraY[y].Split(';');

                    forestX = forestY[y].Split(';');
                }

                for (int x = 0; x < xLength; x++)
                {
                    xMod = width * x;
                    if (isOdd)
                    {
                        xMod = xMod + width / 2;
                    }

                    if (create)
                    {
                        MapSpaceGrid[x, y] = new MapSpace(x, y);
                        MapSpaceGrid[x, y].GetButton().Name = "Button" + x.ToString() + y.ToString();
                        ButtonGrid[x, y] = MapSpaceGrid[x, y].GetButton();
                        canvas.Children.Add(ButtonGrid[x, y]);

                        ButtonGrid[x, y].Click += MapSpaceClick;

                        MapSpaceGrid[x, y].TownLevel = Convert.ToInt32(townX[x]);

                        MapSpaceGrid[x, y].SetInfrastructureLevel(Convert.ToInt32(infraX[x]));
                    }


                    ButtonGrid[x, y].Width  = width;
                    ButtonGrid[x, y].Height = height;
                    Canvas.SetTop(ButtonGrid[x, y], yMod);
                    Canvas.SetLeft(ButtonGrid[x, y], xMod);
                }
            }
        }