示例#1
0
        /// <summary>
        /// Take all modifyable parameters from the given data object.
        /// </summary>
        /// <param name="data"></param>
        public void TakeParametersFrom(AriadneSettingsData data)
        {
            // The Auto... flags for Width and Height have already been checked by the MazeUserControl.
            this.xSize = Math.Max(dimensionsObj.MinSize, Math.Min(dimensionsObj.MaxXSize, data.MazeWidth));
            this.ySize = Math.Max(dimensionsObj.MinSize, Math.Min(dimensionsObj.MaxYSize, data.MazeHeight));

            if (!data.AutoSeed)
            {
                this.seed = Math.Max(0, Math.Min(codeObj.SeedLimit - 1, data.Seed));
            }
            else
            {
                Random r = RandomFactory.CreateRandom();
                this.seed = r.Next(codeObj.SeedLimit);
            }
            this.random = RandomFactory.CreateRandom(seed);

            this.reservedAreas.Clear();
            this.reservedAreaShapes.Clear();
            this.outlineShape = null;
            this.embeddedMazeShapes.Clear();
            this.embeddedMazes.Clear();

            this.Irregular    = data.IrregularMaze;
            this.Irregularity = data.Irregularity;

            // Decode(data.Code);
        }
示例#2
0
        /// <summary>
        /// Constructor.
        /// Create a maze whose parameters are encoded in the given code (see property Code).
        /// </summary>
        /// <param name="code">a string of seven letters (case is ignored)</param>
        public Maze(string code)
        {
            int version = MazeCode.GetCodeVersion(code);

            this.dimensionsObj = MazeDimensions.Instance(version);
            this.codeObj       = MazeCode.Instance(version);

            codeObj.Decode(code
                           , out this.seed
                           , out this.xSize, out this.ySize
                           );
            this.random = RandomFactory.CreateRandom(seed);
        }
示例#3
0
        /// <summary>
        /// Background thread:
        /// Fills the queue with images.
        /// </summary>
        private void LoadImages()
        {
            Random r = RandomFactory.CreateRandom();

            #region Start with a few images, preferably without a contour.

            // The saved image paths are already ordered (see SaveImagePaths()).
            LoadAndEnqueue(r, true, LoadImagePaths());

            if (queue.Count >= queueLength)
            {
                ReduceThreadPriority();
            }
            else
            {
                LoadAndEnqueue(r, false, FindImages(imageFolder, queueLength + 1, true, r));
            }

            #endregion

            #region Continuously load more images, keeping the queue full.

            while (true)
            {
                int loadedImagesCount = 0;

                foreach (string imagePath in FindImages(imageFolder, 100, false, r))
                {
                    ContourImage img = LoadImage(imagePath, r);
                    if (img == null)
                    {
                        continue;
                    }

                    Enqueue(img);
                    ++loadedImagesCount;
                }

                // If no image was loaded successfully, enqueue a null value.
                if (loadedImagesCount == 0)
                {
                    Enqueue(null);
                }
            }

            #endregion
        }
示例#4
0
        /// <summary>
        /// Constructor.
        /// Create a maze with the given dimensions.
        /// </summary>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="version"></param>
        /// <param name="seed"></param>
        internal Maze(int xSize, int ySize, int version, int seed)
        {
            this.dimensionsObj = MazeDimensions.Instance(version);
            this.codeObj       = MazeCode.Instance(version);

            this.xSize = Math.Max(dimensionsObj.MinSize, Math.Min(dimensionsObj.MaxXSize, xSize));
            this.ySize = Math.Max(dimensionsObj.MinSize, Math.Min(dimensionsObj.MaxYSize, ySize));

            // Get an initial random seed and use that to create the Random.
            if (seed < 0)
            {
                Random r = RandomFactory.CreateRandom();
                this.seed = r.Next(codeObj.SeedLimit);
            }
            else
            {
                this.seed = seed;
            }
            this.random = RandomFactory.CreateRandom(this.seed);
        }