예제 #1
0
        public FallbackMap(int bmx, int bmy)
        {
            _mapX = bmx;
            _mapY = bmy;

            Color dbgColor;
            var   exitEast  = BigMapManager.BigMapMgrSingleton.CanMove(bmx, bmy, MovementDirection.EAST, out dbgColor);
            var   exitNorth = BigMapManager.BigMapMgrSingleton.CanMove(bmx, bmy, MovementDirection.NORTH, out dbgColor);
            var   exitWest  = BigMapManager.BigMapMgrSingleton.CanMove(bmx, bmy, MovementDirection.WEST, out dbgColor);
            var   exitSouth = BigMapManager.BigMapMgrSingleton.CanMove(bmx, bmy, MovementDirection.SOUTH, out dbgColor);

            string name = string.Format("cm {0} {1}", _mapX, _mapY);
            var    h    = name.GetHashCode();

            _randomGenerator = new System.Random(h);

            _constraintState = new ConstraintState();

            GhostNames = new Ghost.GhostName[] {
                Ghost.GhostName.BLINKY,
                Ghost.GhostName.PINKY,
                Ghost.GhostName.INKY,
                Ghost.GhostName.CLYDE
            };


            Constrain(exitEast, exitNorth, exitWest, exitSouth, _randomGenerator);
        }
예제 #2
0
        internal ConstraintState Clone()
        {
            var clone = new ConstraintState {
                _westWalls  = new ConstraintMap.IsWall [9, 9],
                _northWalls = new ConstraintMap.IsWall [9, 9],
                _isLocked   = new bool [9, 9],
                _tileSets   = new List <int> [9, 9]
            };

            for (int x = 0; x <= 8; ++x)
            {
                for (int y = 0; y <= 8; ++y)
                {
                    clone._westWalls [y, x]  = _westWalls [y, x];
                    clone._northWalls [y, x] = _northWalls [y, x];
                    clone._tileSets [y, x]   = new List <int> (_tileSets [y, x]);
                    clone._isLocked [y, x]   = _isLocked [y, x];
                }
            }
            return(clone);
        }
예제 #3
0
        private void AddInitialConstraintState(
            bool exitEast,
            bool exitNorth,
            bool exitWest,
            bool exitSouth,
            System.Random r)
        {
            var s = new ConstraintState();

            s.Init();

            // left cage
            s.ConstrainLoc(3, 3, 11);

            // right cage
            s.ConstrainLoc(4, 3, 12);

            if (exitEast)
            {
                // pick a loc with x=7, open East

                var y = r.Next(8);
                s.SetWall(7, y, MovementDirection.EAST, IsWall.NO);

                if (_lrSymmetry)
                {
                    // and then with x = 0, open West
                    s.SetWall(0, y, MovementDirection.WEST, IsWall.NO);
                }
            }
            else if (exitWest)
            {
                // pick a loc with x=0, open West
                var y = r.Next(8);
                s.SetWall(0, y, MovementDirection.WEST, IsWall.NO);
            }

            if (exitNorth)
            {
                // pick a loc with y=0, open North

                Debug.Log("Opening exit to North");

                var x = r.Next(8);
                s.SetWall(x, 0, MovementDirection.NORTH, IsWall.NO);
            }

            if (exitSouth)
            {
                Debug.Log("Opening new exit to South");
                // pick a loc with y=7, open South
                var x = r.Next(8);
                s.SetWall(x, 7, MovementDirection.SOUTH, IsWall.NO);
            }

            s.Tighten();

            if (!s.IsOverTight())
            {
                _constraintStates.Add(s);
            }
        }
예제 #4
0
        public bool Constrain()
        {
            int dbgBailOutCount = 6000;

            while (_constraintStates.Count > 0)
            {
                if (dbgBailOutCount <= 0)
                {
                    Debug.LogError("bailed out in constrain");
                    return(false);
                }
                dbgBailOutCount--;

                var workState = _constraintStates [0];
                _constraintStates.RemoveAt(0);

                if (workState.IsOverTight())
                {
                    continue;
                }

                if (workState.IsSolution())
                {
                    Debug.LogFormat("found solution after {0} steps", dbgBailOutCount);
                    _foundSolution = workState;
                    return(true);
                }

                workState.FindMostConstrainedLoc(out int cx, out int cy);
                if ((cx == -1) || (cy == -1))
                {
                    continue;
                }

                var possibilities = workState.GetTileIndexPossibilities(cx, cy);
                MathUtil.Shuffle(possibilities, _randomGenerator);
                foreach (var tileIndex in possibilities)
                {
                    //Debug.LogFormat ("considering {0} for {1} {2}", tileIndex, cx, cy);
                    var workStateClone = workState.Clone();
                    workStateClone.ConstrainWithSymmetry(cx, cy, tileIndex, _lrSymmetry, _nsSymmetry);
                    workStateClone.Tighten();

                    /*
                     * // check if we've closed off the maze too early
                     * bool foundUnlocked = workStateClone.FloodFillFromLocReachedUnlockedLoc (cx, cy, out int visitedCount);
                     *
                     * if ((!foundUnlocked) &&
                     *  (visitedCount < 62)) {
                     *  // closed loop
                     *  Debug.LogFormat ("could not find unlocked location, vis count {0}", visitedCount);
                     *  continue;
                     * }
                     */

                    if (!workStateClone.IsOverTight())
                    {
                        _constraintStates.Insert(0, workStateClone);
                    }
                }
            }
            Debug.LogError("ran out of states in constrain");
            return(false);
        }