コード例 #1
0
        public void LocationWithKeyAddTest()
        {
            var item1 = new LocationWithKey {
                Location = new Point(1, 1)
            };

            item1.AddKey('a');
            Assert.True(item1.HasKey('a'));
        }
コード例 #2
0
        public void LocationWithKeyKeyCountTest()
        {
            var item1 = new LocationWithKey {
                Location = new Point(1, 1)
            };

            item1.AddKey('a');
            item1.AddKey('b');
            Assert.Equal(2, item1.KeyCount);
        }
コード例 #3
0
        private int StepsInShortestPath(Dictionary <Point, char> map)
        {
            var start         = map.Single(p => p.Value == '@').Key;
            var keyCount      = map.Values.Count(char.IsLower);
            var startLocation = new LocationWithKey {
                Location = start
            };
            var startNode       = new Node <LocationWithKey>(startLocation, 0);
            var terminationNode = BreadthFirst(startNode, Neighbors, map, keyCount);

            return(terminationNode.Depth);
        }
コード例 #4
0
        private int StepsInShortestPathSplitMap(Dictionary <Point, char> map)
        {
            var splitMap   = new SplitMap(map);
            var totalSteps = 0;
            var allKeys    = map.Values.Where(char.IsLower).ToList();

            for (int robot = 0; robot < 4; robot++)
            {
                var start         = splitMap.Entrances[robot];
                var myKeys        = FindMyKeys(start, NeighborsKeysOnly, map);
                var startLocation = new LocationWithKey {
                    Location = start
                };
                foreach (var key in allKeys.Where(k => !myKeys.Contains(k)))
                {
                    startLocation.AddKey(key);
                }
                var terminationNode = BreadthFirst(new Node <LocationWithKey>(startLocation, 0), Neighbors, map, allKeys.Count);
                totalSteps += terminationNode.Depth;
            }

            return(totalSteps);
        }
コード例 #5
0
 private bool Equals(LocationWithKey other)
 {
     return(Location.Equals(other.Location) && Keys == other.Keys);
 }