// Constructor public Maze(int x_in, int y_in) { Height = y_in; Width = x_in; int x = x_in + 1; int y = y_in + 1; Cells = new Location[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { Cells[i, j] = new Location(); } } for (int i = 0; i < x; i++) { Cells[i, 0].up_wall = true; Cells[i, y - 1].up_wall = true; } for (int i = 0; i < y; i++) { Cells[0, i].left_wall = true; Cells[x - 1, i].left_wall = true; } }
private static Place Move(Location[,] world, bool vaildDir, string arrowKey, Place currentPlace) { //Console.SetCursorPosition(st_X, st_Y); if (vaildDir == true && arrowKey == "East") { Place nextPlace = new Place(currentPlace.Y, currentPlace.X + 1); return(nextPlace); //Console.Write("\n({0},{1})\n",nextPlace.Y, nextPlace.X); // test next line display } if (vaildDir == true && arrowKey == "West") { Place nextPlace = new Place(currentPlace.Y, currentPlace.X - 1); return(nextPlace); } if (vaildDir == true && arrowKey == "North") { Place nextPlace = new Place(currentPlace.Y - 1, currentPlace.X); return(nextPlace); } if (vaildDir == true && arrowKey == "South") { Place nextPlace = new Place(currentPlace.Y + 1, currentPlace.X); return(nextPlace); } else { return(currentPlace); } }
private static void DisplayError(string arrowKey, Location[,] world) { //SetTextColour(); Console.SetCursorPosition(0, (world.GetLength(0)) * 3 + 5); Console.Write("You can't go {0} ", arrowKey); //ResetTextColour(); }
public World(string name, Location[,] locations, List <Entity> entities, List <Item> items) { Name = name; Locations = locations; Entities = entities; Items = items; }
private static void inputError(string userInput, Location[,] world) { //SetTextColour(); Console.SetCursorPosition(0, (world.GetLength(0)) * 3 + 5); Console.Write("Please try again {0} ", userInput); //ResetTextColour }
private static void ClearError(Location[,] world) { //SetTextColour(); Console.SetCursorPosition(0, (world.GetLength(0)) * 3 + 5); Console.Write("{0}", new String(' ', Console.BufferWidth)); //ResetTextColour(); }
public Map(int width, int height) { Width = width; Height = height; LocationGrid = new Location[width, height]; HeightMap = new int[width, height]; }
public Map(int width, int height, int XStartPos, int YStartPos, ref Player player) { this.width = width; this.height = height; this.player = player; map = new Location[this.width, this.height]; directions = new Directions(); if ((XStartPos < width) && (XStartPos >= 0) && (YStartPos < height) && (YStartPos >= 0)) { pos = new Position() { Xposition = XStartPos, Yposition = YStartPos }; } else { Console.Clear(); Console.WriteLine("Error: Position is outside the map"); Console.WriteLine("Press a key to continue..."); Console.ReadKey(); } }
private void InitLocations() { locations = new Location[Utils.SUGAR_CAPACITIES.GetLength(0), Utils.SUGAR_CAPACITIES.GetLength(1)]; int height = locations.GetLength(0); int width = locations.GetLength(1); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { locations[y, x] = new Location(x, y, Utils.SUGAR_CAPACITIES[y, x]); } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int up = y == 0 ? height - 1 : y - 1; int down = (y + 1) % height; int left = x == 0 ? width - 1 : x - 1; int right = (x + 1) % width; locations[y, x].SetNeighbors( locations[up, x], locations[down, x], locations[y, right], locations[y, left] ); } } }
private bool Solve(Location[,] Maze, int xf, int yf) { int N = 1; bool NoSolution; do { NoSolution = true; for (int x = 0; x < 8; x++) { for (int y = 0; y < 4; y++) { if (Mark[y, x] == N) { for (int i = 0; i < 4; i++) { if (CanGo(x, y, dx[i], dy[i], Maze) && Mark[y + dy[i], x + dx[i]] == 0) { NoSolution = false; Mark[y + dy[i], x + dx[i]] = N + 1; if (x + dx[i] == xf && y + dy[i] == yf) { return(true); } } } } } } N++; }while (NoSolution == false); return(false); }
private bool Solve(Location[,] Maze, int xf, int yf) // that function search solution { int N = 1; // start flooding from 1 bool NoSolution; do { NoSolution = true; // pessimistically believe that there is no solution for (int x = 0; x < 8; x++) { for (int y = 0; y < 4; y++) { if (Mark[y, x] == N) // find the cell of the N step { for (int i = 0; i < 4; i++) // flood in all directions { if (CanGo(x, y, dx[i], dy[i], Maze) && Mark[y + dy[i], x + dx[i]] == 0) { NoSolution = false; //if we could spill, then maybe there is a solution Mark[y + dy[i], x + dx[i]] = N + 1; // we put on the cell the next step spill if (x + dx[i] == xf && y + dy[i] == yf) // if you find a finish then win { return(true); //and exit from function!!! } } } } } } N++; // while there is plenty to pour }while (NoSolution == false); // while there is empty cells or not find finish coord return(false); // fail }
protected override object SolvePartOne() { var input = Input.SplitByNewline(); depth = int.Parse(input[0].Split(' ')[1]); string[] target = input[1].Split(new[] { ' ', ',' }); p = new Point(int.Parse(target[1]), int.Parse(target[2])); depth = 510; p = new Point(10, 10); cave = new Location[p.Y + 6, p.X + 6]; int height = cave.GetLength(0); int width = cave.GetLength(1); Console.SetBufferSize(Console.WindowWidth, height + 20); for (int i = 0; i < height; i++) { cave[i, 0] = new Location(0, i, depth); } for (int i = 0; i < width; i++) { cave[0, i] = new Location(i, 0, depth); } cave[p.Y, p.X] = new Location(p.X, p.Y, depth); cave[p.Y, p.X].GeologicIndex = 0; for (int y = 1; y < height; y++) { for (int x = 1; x < width; x++) { if (cave[y, x] != null) { continue; } cave[y, x] = new Location(x, y, depth); cave[y, x].GeologicIndex = cave[y - 1, x].ErosionLevel * cave[y, x - 1].ErosionLevel; } } WriteConsole(height, width, 20, 5, (y, x) => { int i = cave[y, x].RegionType; char c; if (i == 0) { c = '.'; } else if (i == 1) { c = '='; } else { c = '|'; } return(ConsoleColor.White, c); });
StaticMapAdjust() { int a = (136 - 72 + 1) * AdjustLevel; int b = (55 - 17 + 1) * AdjustLevel; PointArray = new Location[a, b]; LoadLoLa(); }
private List <Location> getAdjacentWalkable(ref Location[,] walkMap, ref Location fromLocation, Vector2Int goal) { //TODO This function will need to also take into account the variable count of squares, when those are implemented List <Location> walkList = new List <Location>(); List <Vector2Int> points = new List <Vector2Int> { new Vector2Int(fromLocation.point.x, fromLocation.point.y + 1), new Vector2Int(fromLocation.point.x + 1, fromLocation.point.y), new Vector2Int(fromLocation.point.x, fromLocation.point.y - 1), new Vector2Int(fromLocation.point.x - 1, fromLocation.point.y) }; for (int i = 0; i < points.Count; i++) { Vector2Int point = points[i]; int x = point.x; int y = point.y; //Ignore squares outside the map //if (x > w || x < 0) { continue; } //if (y > h || y < 0) { continue; } Location loc; try { loc = walkMap[x, y]; } catch (IndexOutOfRangeException) { continue; //If it's out of range, don't bother trying } //If it doesn't exist yet, add it if (loc == null) { loc = new Location(x, y, fromLocation.g + 10, (int)Math.Round(Vector2Int.Distance(new Vector2Int(x, y), goal)), Location.State.Open, fromLocation); walkMap[x, y] = loc; walkList.Add(loc); } //If it's already been checked, but is still open else if (loc != null && loc.state == Location.State.Open) { int gCost = (int)Math.Round(Vector2Int.Distance(new Vector2Int(x, y), goal)) + 10; if (gCost < loc.g) { loc.prev = fromLocation; walkList.Add(loc); } } //If it's actually the goal, add it anyway else if (point == goal) { loc.prev = fromLocation; walkList.Add(loc); } } return(walkList); }
private static void diplayDot(Location[,] world, Place nextPlace, int Y, int X) { Console.OutputEncoding = System.Text.Encoding.Unicode; // need to do some testing in here to increment x, and y Console.SetCursorPosition(Y, X); Console.WriteLine("♦"); Console.ReadKey(); }
private static void AddRandomObject(ref Location[,] world, List <string> Items) { Random random = new Random(Guid.NewGuid().GetHashCode()); int i = random.Next(world.GetLength(0)); int j = random.Next(world.GetLength(1)); world[i, j].Thing = Items[random.Next(Items.Count)]; Console.WriteLine("({0}, {1}) has {2}", i, j, world[i, j].Thing); }
public void UpdateMarks(Location[,] Maze) { for (int y = 0; y < 5; y++) { for (int x = 0; x < 9; x++) { Maze[y, x].Content.Text = Convert.ToString(Mark[y, x]); } } }
public Location GetNorth() { if (CurrentLocation.Y + 1 <= SizeY) { Location[,] locs = GetLocations(); Location loc = locs[CurrentLocation.X, CurrentLocation.Y + 1]; return(loc); } return(new Location("Off Map", -1, -1)); }
public HeatMap(int gridsize, IGameState asdfstate) { state = asdfstate; heatMapGridSize = gridsize; heatMap = new float[(int)Math.Ceiling((float)state.Height / heatMapGridSize), (int)Math.Ceiling((float)state.Width / heatMapGridSize)]; heatMapCentre = new Location[heatMap.GetLength(0), heatMap.GetLength(1)]; for (int y = 0; y < heatMapCentre.GetLength(0); y++) for (int x = 0; x < heatMapCentre.GetLength(1); x++) heatMapCentre[y, x] = new Location(y * heatMapGridSize, x * heatMapGridSize); }
public GameState(int width, int height, int turntime, int loadtime, int viewradius2, int attackradius2, int spawnradius2, int seed) { Width = width; Height = height; LoadTime = loadtime; TurnTime = turntime; PlayerSeed = seed; ViewRadius2 = viewradius2; AttackRadius2 = attackradius2; ViewRadius = (int)Math.Sqrt(viewradius2); AttackRadius = (int)Math.Sqrt(attackradius2); SpawnRadius2 = spawnradius2; MyAnts = new List<Location>(); MyHills = new List<Location>(); EnemyAnts = new List<Location>(); EnemyHills = new List<Location>(); DeadTiles = new List<Location>(); FoodTiles = new List<Location>(); map = new Location[height, width]; for (int i = 0; i < map.GetLength(0); ++i) { for (int j = 0; j < map.GetLength(1); ++j) { map[i, j] = new Location(i, j); } } foreach (Location l in map) { int col = (l.Col - 1) % width; if (col < 0) col += width; int row = (l.Row - 1) % height; if (row < 0) row += height; l.Neighbors[0] = map[row, l.Col]; l.Neighbors[3] = map[l.Row, col]; row = (l.Row + 1) % height; col = (l.Col + 1) % width; l.Neighbors[1] = map[row, l.Col]; l.Neighbors[2] = map[l.Row, col]; } }
public MainWindow() { InitializeComponent(); Maze = new Location[5, 9]; dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += dispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 1); GenerateMaze(); floodfill = new Floodfill(); }
public Map(int width, int height) { this.Width = width; this.Height = height; this.locations = new Location[height, width]; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { locations[row, col] = new Location { TerrainType = TerrainTypeRepository.Instance.Get(DefaultTerrainTypeName), Row = row, Column = col }; } } }
public BFSGridGraph(int width, int height) : base(width, height) { frontier = new Queue(); cameFrom = new Location[gridWidth, gridHeight]; for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridHeight; j++) { cameFrom [i, j] = new Location(-1, -1); } } }
// Find unvisited neighbours to this address static List <Place> FindNeighbours(Location[,] World, Place address) { List <Place> unVisitedNeighbours = new List <Place>(); // Look west if (address.X > 0) { // If western neighbour hasn't been visited if (World[address.Y, address.X - 1].Visited == false) { // Western neighbour can be added to the list unVisitedNeighbours.Add(new Place(address.Y, address.X - 1)); } } // Look north if (address.Y > 0) { // If northern neighbour hasn't been visited if (World[address.Y - 1, address.X].Visited == false) { // Northern neighbour can be added to the list unVisitedNeighbours.Add(new Place(address.Y - 1, address.X)); } } // Look east if (address.X < World.GetLength(1) - 1) { // If eastern neighbour hasn't been visited if (World[address.Y, address.X + 1].Visited == false) { // Eastern neighbour can be added to the list unVisitedNeighbours.Add(new Place(address.Y, address.X + 1)); } } // Look south if (address.Y < World.GetLength(0) - 1) { // If southern neighbour hasn't been visited if (World[address.Y + 1, address.X].Visited == false) { // Southern neighbour can be added to the list unVisitedNeighbours.Add(new Place(address.Y + 1, address.X)); } } // Return all the valid neighbours, could be empty return(unVisitedNeighbours); }
public World(int width, int height) { this.Width = width; this.Height = height; map = new Location[height, width]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[y, x] = new Location(); } } }
public HeatMap(int gridsize, IGameState asdfstate) { state = asdfstate; heatMapGridSize = gridsize; heatMap = new float[(int)Math.Ceiling((float)state.Height / heatMapGridSize), (int)Math.Ceiling((float)state.Width / heatMapGridSize)]; heatMapCentre = new Location[heatMap.GetLength(0), heatMap.GetLength(1)]; for (int y = 0; y < heatMapCentre.GetLength(0); y++) { for (int x = 0; x < heatMapCentre.GetLength(1); x++) { heatMapCentre[y, x] = new Location(y * heatMapGridSize, x * heatMapGridSize); } } }
// Create default world, populate with defaults public static void CreateWorld(ref Location[,] World) { for (int i = 0; i < World.GetLength(0); i++) { for (int j = 0; j < World.GetLength(1); j++) { // This means a wall, or more specifically NO door Place wall = new Place(-1, -1); World[i, j].Address = new Place(i, j); // set address World[i, j].Visited = false; World[i, j].Neighbours = new Doors(wall, wall, wall, wall); } } }
// Generates a 2d grid and assigns all tiles a generic color. public void GenerateMap() { grid = new Location[mapX + 1, mapY + 1]; for (int i = 0; i < mapX; i++) { for (int j = 0; j < mapY; j++) { grid[i, j] = new Location(i, j); grid[i, j].TileColor = Colors.LightGreen; } } PopulateSpecialLocations(); }
private static bool checkValidPath(Location[,] World, Place dir, string arrowKey) { bool condition = true; { Doors validRoom = World[dir.X, dir.Y].Neighbours; if (validRoom.East.X != -1 && arrowKey == "East") { condition = true; } else if (validRoom.East.X == -1 && arrowKey == "East") { Console.WriteLine("Can not go East, try again!: "); condition = false; } if (validRoom.West.X != -1 && arrowKey == "West") { condition = true; } else if (validRoom.West.X == -1 && arrowKey == "West") { Console.WriteLine("Can not go that way, try again!: "); condition = false; } if (validRoom.North.Y != -1 && arrowKey == "North") { condition = true; } else if (validRoom.North.X == -1 && arrowKey == "North") { Console.WriteLine("Can not go that way, try again!: "); condition = false; } if (validRoom.South.Y != -1 && arrowKey == "South") { condition = true; } else if (validRoom.South.X == -1 && arrowKey == "South") { Console.WriteLine("Can not go that way, try again!: "); condition = false; } } return(condition); }
public GameSessionViewModel(Player player, List <string> initialMessages, Location[,] gameMap, GameMapCoordinates currentLocationCoordinates) { _player = player; _messages = initialMessages; _gameMap = gameMap; _maxRows = _gameMap.GetLength(0); _maxColumns = _gameMap.GetLength(1); _currentLocationCoordinates = currentLocationCoordinates; _currentLocation = _gameMap[_currentLocationCoordinates.Row, _currentLocationCoordinates.Column]; }
// Options for displaying current selected row / column // These are only set through function that checks that these are in range and only update then public GameState() { boardState = new Location[BOARDWIDTH, BOARDHEIGHT]; for (int i = 0; i < BOARDHEIGHT; i++) { for (int j = 0; j < BOARDWIDTH; j++) { boardState[i, j] = Location.Empty; } } numShots = 0; ships = new List <Ship>(); allShipLocations = new Dictionary <Tuple <int, int>, string>(); moveHistory = new HashSet <Tuple <int, int> >(); }
//private static string keyStroke() //{ // bool isValid = true; // while (isValid) // { // ConsoleKey readKey = Console.ReadKey().Key; // if (readKey == ConsoleKey.RightArrow) return "East"; // if (readKey == ConsoleKey.LeftArrow) return "West"; // if (readKey == ConsoleKey.UpArrow) return "North"; // if (readKey == ConsoleKey.DownArrow) return "South"; // if (readKey == ConsoleKey.Q) return "quit"; // } // return "none"; //} // Recursive Backtracker Algorithm static void BackTracker(ref Location[,] World, Place current, ref Stack stack, ref List <Place> Path) { // Exit case if (stack.Count() == 0) { return; } // Save path Path.Add(current); // Mark the current place as visited World[current.Y, current.X].Visited = true; // Get current neighbours List <Place> neighbours = FindNeighbours(World, current); // If no neighbours recurse / backtrack hence the name while (neighbours.Count == 0) { current = stack.Pop(); if (stack.Count() == 0) { return; } neighbours = FindNeighbours(World, current); } // Save our place Place previous = current; // We have neighbours, pick one current = GetRandomNeighbour(neighbours); // What direction did we go in? string direction = Direction(previous, current); // Open that door SetDoor(ref World, direction, previous); // Push the new place onto the statck stack.Push(current); // Recurse BackTracker(ref World, current, ref stack, ref Path); }
public AstarSearch(WeightedGridGraph parGraph) { graph = parGraph; cameFrom = new Location[graph.getGridWidth(), graph.getGridHeight()]; costSoFar = new int[graph.getGridWidth(), graph.getGridHeight()]; frontier = new HeapPriorityQueue <Location> (graph.getGridWidth() * graph.getGridHeight()); for (int i = 0; i < graph.getGridWidth(); i++) { for (int j = 0; j < graph.getGridHeight(); j++) { cameFrom [i, j] = new Location(-1, -1); // costSoFar [i, j] = LARGEVALUE; } } }
public Map() { locations = new Location[MapSizeX, MapSizeY]; for (int i = 0; i < MapSizeX; i++) { for (int j = 0; j < MapSizeY; j++) { double probability = 0.7 * rand.NextDouble(); int density = rand.Next(6); locations[i, j] = Location.CreateLocation(this, probability, density, i, j); } } locations[0, 0].Probability = 0; }
public Map(int width, int height, int XStartPos, int YStartPos) { this.width = width; this.height = height; map = new Location[this.width, this.height]; directions = new Directions(); if ((XStartPos < width) && (XStartPos >= 0) && (YStartPos < height) && (YStartPos >= 0)) { pos = new Position() { Xposition = XStartPos, Yposition = YStartPos }; } else { Console.Clear(); Console.WriteLine("Error: Position is outside the map"); Console.WriteLine("Press a key to continue..."); Console.ReadKey(); } }
public MainWindow() { InitializeComponent(); //////// Below is generating and saving a location array. //////// Currently it is set up to save rather than load. //////// Change the comments as appropriate to change that. DisplayedTiles = new Location[XDimension, YDimension]; DisplayedTiles = GridFunctions.GenerateTileArray(XDimension, YDimension); CSVFunctions.SaveCSV(DisplayedTiles, "locations.csv", XDimension, YDimension); /// DisplayedTiles = CSVFunctions.LoadCSV("locations.csv"); /// Create player sprite MainCanvas.Children.Add(PlayerSprite = new Image { Height = TileHeight, Width = TileWidth }); Canvas.SetLeft(PlayerSprite, LeftGrid + (ThePlayer.XRef * TileWidth)); Canvas.SetTop(PlayerSprite, TopGrid + (ThePlayer.YRef * TileHeight)); PlayerSprite.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Player/Player.png", UriKind.Absolute)); CreateGrid(GridWidth, GridHeight); UpdateGridCentre(ThePlayer.XRef, ThePlayer.XRef, ThePlayer.YRef, ThePlayer.YRef); }
public Table() { IsBallSelected = false; SelectedPoint = new Point(-1, -1); gametable = new short[tableWidth, tableHeight]; for (int i = 0; i < 3; ) { Random rand = new Random(); int x = rand.Next(tableWidth); int y = rand.Next(tableHeight); int value = rand.Next(7); ++value; if (gametable[x, y] == 0) { gametable[x, y] = (short)value; ++i; } } locations = new Location[tableWidth, tableHeight]; engine = new RouteEngine.RouteEngine(); for (int i = 0; i < tableWidth; i++) { for (int j = 0; j < tableHeight; j++) { locations[i, j] = new Location() { Identifier = i + "," + j }; engine.Locations.Add(locations[i, j]); } } }
public WorldMap() { this.locations = new Location[15, 15]; this.locations[8, 8] = new Town("Startville", true, true, true); }
public InfluenceMap(Location[,] map) { this.map = map; influence = new float[map.GetLength (0), map.GetLength (1)]; }
public void CreateMapField(int x, int y) { Heigth = y; Width = x; location = new Location[x,y]; for (int i = 0; i<x; i++) { for (int j = 0; j<y; j++) { location[i,j] = new Location(i, j, new BasicObject()); } } }
public LocationPool(int width, int height) { Unmarked = new HashSet<Location>(); locations = new Location[width, height]; }
public static void Init(TileSet ts) { tiles = ts; map = new Location[ts.Width, ts.Height]; for (int x = 0; x < tiles.WidthIndex; x++) { for (int y = 0; y < tiles.HeightIndex; y++) { map[x, y] = Location.unknown; } } initialized = true; }