public string SolvePart2() { var locationsInSafeRegion = new List <Location>(); var currentLocation = new Location(0, 0); while (currentLocation.X <= XBoundary && currentLocation.Y <= YBoundary) { Dictionary <Location, int> distances = AllLocations.ToDictionary(location => location, location => CalculateManhattanDistance(currentLocation, location)); int totalDistance = distances.Sum(d => d.Value); if (totalDistance < 10000) { locationsInSafeRegion.Add(new Location(currentLocation.X, currentLocation.Y)); } // Move to the next location if (currentLocation.Y == YBoundary) { currentLocation.X++; currentLocation.Y = 0; } else { currentLocation.Y++; } } return($"Part 2: {locationsInSafeRegion.Count}"); }
//TODO /// <Summary>Does this page need to show the location selector?</Summary> //public bool ShowLocationSelector(MenuHelper currentMenu) //{ // return currentMenu.ShowLocationSelection && HasLocations; //} public JsonResult UpdateStatus(int locationId, string status) { var locationCacher = new LocationCacher(SharedDbContext); var location = AllLocations.SingleOrDefault(l => l.Id == locationId); if (location == null) { return(new { Saved = false }.AsJsonResult()); } if (location.TallyStatus != status) { SharedDbContext.Location.Attach(location); location.TallyStatus = status; SharedDbContext.SaveChanges(); locationCacher.UpdateItemAndSaveCache(location); } return(new { Saved = true, Location = LocationInfoForJson(location) }.AsJsonResult()); }
public void OnComplete(Android.Gms.Tasks.Task task) { if (task.IsSuccessful) { var documents = (QuerySnapshot)task.Result; foreach (var doc in documents.Documents) { Locations loc = new Locations(); loc.Centers = new List <string>(); loc.Location = (string)doc.Get("Location"); var centersDoc = doc.Get("Centers"); var centersList = new Android.Runtime.JavaList((System.Collections.IEnumerable)centersDoc); var list = centersList.ToArray(); for (int i = 0; i < list.Length; i++) { var o = (Java.Lang.Object)list[i].ToString(); loc.Centers.Add((string)o); } AllLocations.Add(loc); } HasLocations = true; } else { AllLocations.Clear(); } }
public Solution(IPuzzle puzzle) : base(puzzle, x => x.Trim('\n').Split("\n")) { foreach (var i in Input) { string[] split = i.Split(','); AllLocations.Add(new Location(int.Parse(split[0]), int.Parse(split[1]))); } }
internal void Filter(string text) { var filtered = AllLocations.Where(x => x.Name.ToLower().StartsWith(text.ToLower())).ToList(); Locations = new ObservableCollection <DeviceLocation>(); foreach (var item in filtered) { Locations.Add(item); } }
public App() { InitializeComponent(); MainPage = new MainPage(); Page AllItems = new AllItems(); Page AllLocations = new AllLocations(); Page AllTenants = new AllTenants(); Page AllToDo = new AllToDo(); }
public bool AddLocation(Location location) { var all = AllLocations.ToList(); if (all.Any(x => x == location)) { return(false); } all.Add(location); UpdateLocations(all); return(true); }
public void AddLocation(Location l) { if (l.TerrainType == Terrain.WalkableWater) { _locations[(int)Terrain.Swamp].Add(l); } else { _locations[(int)l.TerrainType].Add(l); } AllLocations.Add(l); _locsByCoords.Add(l.Coords, l); }
public bool ReplaceLocation(Location old, Location replacement) { if (AllLocations.Contains(old)) { var all = AllLocations.ToList(); var index = all.IndexOf(old); all.Remove(old); all.Insert(index, replacement); UpdateLocations(all); return(true); } return(false); }
public EditWindow(Location location, IEnumerable <Location> allLocations, bool isEdit) { InitializeComponent(); AllLocations = allLocations.ToList(); AllLocations.Remove(location); if (isEdit) { Title = "Edycja Lokalizacji"; } else { Title = "Tworzenie Lokalizacji"; } InitialLocation = location; CurrentLocation = new Location(location.Name, location.X, location.Y, location.Update); UpdateTextBoxes(location); }
//--------------------------------------------------------------------- public void Add(ActiveSite site) { AllLocations.Add(site.Location); this.activeArea = AllLocations.Count * Model.Core.CellArea; //set site var SiteVars.Stand[site] = this; //loop- really just 2 locations, relative (-1, 0) and relative (0, -1) foreach (RelativeLocation neighbor_loc in neighborsAboveAndLeft) { //check this site for neighbors that are different Site neighbor = site.GetNeighbor(neighbor_loc); if (neighbor != null && neighbor.IsActive) { //declare a stand with this site as its index. Stand neighbor_stand = SiteVars.Stand[neighbor]; //check for non-null stand //also, only allow stands in same management area to be called neighbors if (neighbor_stand != null && this.ManagementArea == neighbor_stand.ManagementArea) { //if neighbor_stand is different than this stand, then it is a true //neighbor. add it as a neighbor and add 'this' as a neighbor of that. if (this != neighbor_stand) { //add neighbor_stand as a neighboring stand to this AddNeighbor(neighbor_stand); //add this as a neighboring stand to neighbor_stand neighbor_stand.AddNeighbor(this); } } //take into account other management areas just for stand-adjacency issue else if (neighbor_stand != null && this.ManagementArea != neighbor_stand.ManagementArea) { if (this != neighbor_stand) { //add neighbor_stand as a ma-neighboring stand to this AddMaNeighbor(neighbor_stand); //add this as a ma-neighbor stand to neighbor_stand neighbor_stand.AddMaNeighbor(this); } } } } }
public void UpdateVisit() { UpdateReachable(); foreach (var l in AllLocations.Where(l => _v[l.YPos - 30, l.XPos])) { l.Reachable = true; if (!_connectionsDm.Keys.Contains(l)) { continue; } var l2 = _connectionsDm[l]; foreach (var l3 in l2) { l3.Reachable = true; _v[l3.YPos - 30, l3.XPos] = true; } } }
public HtmlString GetLocationOptions(bool includeWhichIfNeeded = true) { var currentLocation = UserSession.CurrentLocation; var selected = 0; if (currentLocation != null) { selected = currentLocation.Id; } return (( (selected == 0 && includeWhichIfNeeded ? "<option value='-1'>Which Location?</option>" : "") + AllLocations .OrderBy(l => l.SortOrder) .Select(l => new { l.Id, l.Name, Selected = l.Id == selected ? " selected" : "" }) .Select(l => "<option value={Id}{Selected}>{Name}</option>".FilledWith(l)) .JoinedAsString()) .AsRawHtml()); }
internal async Task AddOrUpdateLocation() { var service = ServicesManager.SelfService; try { if (CurrentLocation == null || string.IsNullOrEmpty(CurrentLocation.Name)) { MainWindow.Instance.AddNotification(new BaseResponse() { Error = ErrorCode.ValidationError, Message = "Name and details cannot be empty." }); return; } if (AllLocations.Count(x => x.Name == CurrentLocation.Name) > 1) { MainWindow.Instance.AddNotification(new BaseResponse() { Error = ErrorCode.ValidationError, Message = "Client name already exists." }); return; } var locationsResponse = await service.UpdateLocation(Token, CurrentLocation); MainWindow.Instance.AddNotification(locationsResponse ?? new BaseResponse() { Error = ErrorCode.InternalError, Message = "Failed to receive response from host." }); } catch (ServiceException ex) { //TODO: HIGH Add logging MainWindow.Instance.AddNotification(ex); } }
public string SolvePart1() { var currentLocation = new Location(0, 0); while (currentLocation.X <= XBoundary && currentLocation.Y <= YBoundary) { Dictionary <Location, int> distances = AllLocations.ToDictionary(location => location, location => CalculateManhattanDistance(currentLocation, location)); IExtremaEnumerable <KeyValuePair <Location, int> >?sortedDistances = distances.MinBy(d => d.Value); KeyValuePair <Location, int> shortestDistance = sortedDistances.First(); if (sortedDistances.Count() == 1 || sortedDistances.Count(s => s.Value == shortestDistance.Value) == 1) { // Only add if the current location is closest to a single point. var newLocation = new Location(currentLocation.X, currentLocation.Y) { IsInfinite = currentLocation.X == 0 || currentLocation.Y == 0 || currentLocation.X == XBoundary || currentLocation.Y == YBoundary }; AllLocations.SingleOrDefault(l => l == shortestDistance.Key)?.ClosestLocations.Add(newLocation); } // Move to the next location if (currentLocation.Y == YBoundary) { currentLocation.X++; currentLocation.Y = 0; } else { currentLocation.Y++; } } List <Location> nonInfiniteLocations = AllLocations.Where(l => l.ClosestLocations.All(c => !c.IsInfinite)).ToList(); Location? largestNonInfinite = nonInfiniteLocations.MaxBy(l => l.ClosestLocations.Count).First(); return($"Part 1: {largestNonInfinite.ClosestLocations.Count}"); }
void buttonBuild(Form form) { allLocations = new AllLocations(); List <Location> locations = allLocations.getAllLocations(); foreach (Location location in locations) { Button button = new Button(); button.Text = location.name; button.Top = buttonStartX; button.Left = buttonStartY; button.Width = buttonWidth; labelBuild(button, form, location); if (locationEnabled(location)) { button.Enabled = true; } else { button.Enabled = false; } button.Click += (object sender, EventArgs e) => { new MainMenu().changeLocationLabel(location); form.Hide(); LocationForm locationForm = new LocationForm(location); this.travel.travelTo(location); locationForm.Show(); }; form.Controls.Add(button); buttonStartX += 30; } }
public void UpdateVisit() { UpdateReachable(); foreach (var l in AllLocations.Where(l => l.YPos > 30).Where(l => _v[l.YPos - 30, l.XPos])) { l.Reachable = true; if (!_connections.Keys.Contains(l)) { continue; } var l2 = _connections[l]; if ((l.NeedBagu && (_bagu.Reachable || _hy._spellGet[(int)Spells.Fairy]))) { l2.Reachable = true; _v[l2.YPos - 30, l2.XPos] = true; } if (l.NeedFairy && _hy._spellGet[(int)Spells.Fairy]) { l2.Reachable = true; _v[l2.YPos - 30, l2.XPos] = true; } if (l.NeedJump && _hy._spellGet[(int)Spells.Jump]) { l2.Reachable = true; _v[l2.YPos - 30, l2.XPos] = true; } if (l.NeedFairy || l.NeedBagu || l.NeedJump) { continue; } l2.Reachable = true; _v[l2.YPos - 30, l2.XPos] = true; } }
public void MergeData(List <RhitLocation> locations, StorageKey key) { if (locations == null) { return; } if (key == StorageKey.Top) { TopLocations = MakeDict(locations); DataStorage.SaveState(StorageKey.Top, TopLocations); } foreach (RhitLocation location in locations) { if (AllLocations.ContainsKey(location.Id)) { AllLocations[location.Id].Merge(location); } else { AllLocations[location.Id] = location; } } DataStorage.SaveState(StorageKey.All, AllLocations); }
protected Location GetLocationByMap(int map, int world) { return(AllLocations.FirstOrDefault(loc => loc.LocationBytes[2] == map && loc.World == world)); }
public static int GetLocationId(AllLocations myLocationName) { return((int)myLocationName); }
public void UpdateVisit() { var changed = true; while (changed) { changed = false; for (var i = 0; i < _mapRows; i++) { for (var j = 0; j < _mapCols; j++) { if (_v[i, j] || ((_map[i, j] != Terrain.WalkableWater || !_hy._itemGet[(int)Items.Boots]) && _map[i, j] != Terrain.Road && _map[i, j] != Terrain.Palace && _map[i, j] != Terrain.Bridge)) { continue; } if (i - 1 >= 0) { if (_v[i - 1, j]) { _v[i, j] = true; changed = true; continue; } } if (i + 1 < _mapRows) { if (_v[i + 1, j]) { _v[i, j] = true; changed = true; continue; } } if (j - 1 >= 0) { if (_v[i, j - 1]) { _v[i, j] = true; changed = true; continue; } } if (j + 1 < _mapCols) { if (_v[i, j + 1]) { _v[i, j] = true; changed = true; } } } } } foreach (var l in AllLocations.Where(l => _v[l.YPos - 30, l.XPos])) { l.Reachable = true; } }
public LocationsJSON(List <double> Xs, List <double> Ys) { /*elevations = new double[Xs.Count, Ys.Count]; * for (int x = 0; x < elevations.GetLength(0); x++) * { * for (int y = 0; y < elevations.GetLength(1); y++) * { * elevations[x, y] = 0; * } * }*/ //elevations = new double[(int)Mathf.Ceil((Xs.Count/5)+1), (int)Mathf.Ceil((Ys.Count/5)+1)]; elevations = new double[Xs.Count, Ys.Count]; for (int x = 0; x < elevations.GetLength(0); x++) { for (int y = 0; y < elevations.GetLength(1); y++) { elevations[x, y] = 0; } } int j = 0; for (int y = 0; y < Ys.Count; y++) { AllLocations alllocations = new AllLocations() { locations = new List <Coordinates>() }; for (int x = 0; x < Xs.Count; x++) { Coordinates coordinate = new Coordinates() { latitude = Ys[y], longitude = Xs[x] }; alllocations.locations.Add(coordinate); } locationsJsonString = JsonConvert.SerializeObject(alllocations); var postData = new StringContent(locationsJsonString, Encoding.UTF8, "application/json"); var response = client.PostAsync("http://172.18.72.17:8080/api/v1/lookup", postData).Result; var responseString = response.Content.ReadAsStringAsync().Result; ResultList resultList; resultList = JsonConvert.DeserializeObject <ResultList>(responseString); for (int i = 0; i < elevations.GetLength(0); i++) { elevations[i, j] = resultList.results[i].elevation; } j++; } /*foreach (double y in Ys) * { * AllLocations alllocations = new AllLocations() * { * locations = new List<Coordinates>() * }; * foreach (double x in Xs) * { * Coordinates coordinate = new Coordinates() * { * latitude = y, * longitude = x * }; * alllocations.locations.Add(coordinate); * } * locationsJsonString = JsonConvert.SerializeObject(alllocations); * var postData = new StringContent(locationsJsonString, Encoding.UTF8, "application/json"); * var response = client.PostAsync("http://172.18.105.193:8080/api/v1/lookup", postData).Result; * var responseString = response.Content.ReadAsStringAsync().Result; * ResultList resultList; * resultList = JsonConvert.DeserializeObject<ResultList>(responseString); * * for (int i = 0; i < Xs.Count; i++) * { * elevations[i, j] = resultList.results[i].elevation; * } * j++; * }*/ }
public JsonResult EditLocation(int id, string text) { var locationCacher = new LocationCacher(SharedDbContext); var location = locationCacher.AllForThisElection.SingleOrDefault(l => l.Id == id); var changed = false; if (location == null) { location = new Location { ElectionGuid = UserSession.CurrentElectionGuid, LocationGuid = Guid.NewGuid() }; SharedDbContext.Location.Add(location); changed = true; } else { SharedDbContext.Location.Attach(location); } int locationId; string locationText; string status; var success = false; if (text.HasNoContent() && location.Id > 0) { // don't delete last location if (AllLocations.Count() > 1) { // delete existing if we can var used = new BallotCacher(SharedDbContext).AllForThisElection.Any(b => b.LocationGuid == location.LocationGuid); if (!used) { SharedDbContext.Location.Remove(location); SharedDbContext.SaveChanges(); locationCacher.RemoveItemAndSaveCache(location); status = "Deleted"; success = true; locationId = 0; locationText = ""; } else { status = "Cannot deleted this location because it has Ballots recorded in it"; locationId = location.Id; locationText = location.Name; } } else { // only one status = "At least one location is required"; locationId = location.Id; locationText = location.Name; } } else if (text.HasContent()) { locationText = location.Name = text; locationId = location.Id; // may be 0 if new changed = true; status = "Saved"; } else { status = "Nothing to save"; locationId = 0; locationText = ""; success = true; changed = false; } if (changed) { SharedDbContext.SaveChanges(); locationId = location.Id; locationCacher.UpdateItemAndSaveCache(location); success = true; } return(new { // returns 0 if deleted or not created Id = locationId, Text = locationText, Success = success, Status = status }.AsJsonResult()); }
public bool Terraform() { _bcount = 900; while (_bcount > 801) { _map = new Terrain[_mapRows, _mapCols]; for (var i = 0; i < _mapRows; i++) { for (var j = 0; j < 29; j++) { _map[i, j] = Terrain.None; } for (var j = 29; j < _mapCols; j++) { _map[i, j] = Terrain.WalkableWater; } } int x; int y; foreach (var l in AllLocations.Where(l => l.TerrainType != Terrain.Bridge && l != _magicCave)) { do { x = _hy.R.Next(_mapCols - 2) + 1; y = _hy.R.Next(_mapRows - 2) + 1; } while (_map[y, x] != Terrain.None || _map[y - 1, x] != Terrain.None || _map[y + 1, x] != Terrain.None || _map[y + 1, x + 1] != Terrain.None || _map[y, x + 1] != Terrain.None || _map[y - 1, x + 1] != Terrain.None || _map[y + 1, x - 1] != Terrain.None || _map[y, x - 1] != Terrain.None || _map[y - 1, x - 1] != Terrain.None); _map[y, x] = l.TerrainType; l.XPos = x; l.YPos = y + 30; if (l.TerrainType != Terrain.Cave) { continue; } var dir = _hy.R.Next(4); var s = _walkable[_hy.R.Next(_walkable.Length)]; switch (dir) { //south case 0: _map[y + 1, x] = s; _map[y + 1, x + 1] = s; _map[y + 1, x - 1] = s; _map[y, x - 1] = Terrain.Mountain; _map[y, x + 1] = Terrain.Mountain; _map[y - 1, x - 1] = Terrain.Mountain; _map[y - 1, x] = Terrain.Mountain; _map[y - 1, x + 1] = Terrain.Mountain; break; //west case 1: _map[y + 1, x] = Terrain.Mountain; _map[y + 1, x + 1] = Terrain.Mountain; _map[y + 1, x - 1] = s; _map[y, x - 1] = s; _map[y, x + 1] = Terrain.Mountain; _map[y - 1, x - 1] = s; _map[y - 1, x] = Terrain.Mountain; _map[y - 1, x + 1] = Terrain.Mountain; break; //north case 2: _map[y + 1, x] = Terrain.Mountain; _map[y + 1, x + 1] = Terrain.Mountain; _map[y + 1, x - 1] = Terrain.Mountain; _map[y, x - 1] = Terrain.Mountain; _map[y, x + 1] = Terrain.Mountain; _map[y - 1, x - 1] = s; _map[y - 1, x] = s; _map[y - 1, x + 1] = s; break; //east case 3: _map[y + 1, x] = Terrain.Mountain; _map[y + 1, x + 1] = s; _map[y + 1, x - 1] = Terrain.Mountain; _map[y, x - 1] = Terrain.Mountain; _map[y, x + 1] = s; _map[y - 1, x - 1] = Terrain.Mountain; _map[y - 1, x] = Terrain.Mountain; _map[y - 1, x + 1] = s; break; } } if (!GrowTerrain()) { return(false); } do { x = _hy.R.Next(_mapCols - 2) + 1; y = _hy.R.Next(_mapRows - 2) + 1; } while (!_walkable.Contains(_map[y, x]) || _map[y + 1, x] == Terrain.Cave || _map[y - 1, x] == Terrain.Cave || _map[y, x + 1] == Terrain.Cave || _map[y, x - 1] == Terrain.Cave); _map[y, x] = Terrain.Rock; _magicCave.YPos = y + 30; _magicCave.XPos = x; //check bytes and adjust WriteBytes(false, 0x665C, 801, 0, 0); } WriteBytes(true, 0x665C, 801, 0, 0); var loc = 0x7C00 + _bcount; var high = (loc & 0xFF00) >> 8; var low = loc & 0xFF; _hy.RomData.Put(0x47A5, (Byte)low); _hy.RomData.Put(0x47A6, (Byte)high); _v = new bool[_mapRows, _mapCols]; for (var i = 0; i < _mapRows; i++) { for (var j = 0; j < _mapCols; j++) { _v[i, j] = false; } } for (var i = 0x610C; i < 0x6149; i++) { if (!_terrains.Keys.Contains(i)) { _hy.RomData.Put(i, 0x00); } } return(true); }
protected Location GetLocationByCoords(Tuple <int, int> coords) { return(AllLocations.FirstOrDefault(loc => loc.Coords.Equals(coords))); }
public bool IsLocationCodeValid(string code, int id) { var result = AllLocations.Any(x => x.Code == code && x.Id != id); return(result); }
protected Location GetLocationByMem(int mem) { return(AllLocations.FirstOrDefault(loc => loc.MemAddress == mem)); }