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);
            }
        }
Example #2
0
        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;
                }
            }
        }
Example #3
0
        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}");
        }
Example #4
0
        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;
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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;
            }
        }