/// <summary>Initialize the GeneratorOptions</summary>
        /// <param name="size">The size of the puzzle to be generated.</param>
        /// <param name="difficulty">The difficulty of the puzzle to generate.</param>
        /// <param name="minimumFilledCells">The minimum number of filled cells in the generated puzzle.</param>
        /// <param name="maximumNumberOfDecisionPoints">The maximum number of times brute-force techniques can be used in solving the puzzle.</param>
        /// <param name="numberOfPuzzles">The number of puzzles to generate in order to pick the best of the lot.</param>
        /// <param name="techniques">The techniques to use while generating the puzzle.</param>
        /// <param name="ensureSymmetry">Whether all puzzles generated should be symmetrical.</param>
        private GeneratorOptions(
            PuzzleDifficulty difficulty, int minimumFilledCells, int?maximumNumberOfDecisionPoints, int numberOfPuzzles,
            EliminationTechnique [] techniques, bool ensureSymmetry)
        {
            if (difficulty != PuzzleDifficulty.Easy &&
                difficulty != PuzzleDifficulty.Medium &&
                difficulty != PuzzleDifficulty.Hard &&
                difficulty != PuzzleDifficulty.VeryHard)
            {
                throw new ArgumentOutOfRangeException("difficulty");
            }
            if (minimumFilledCells < 0)
            {
                throw new ArgumentOutOfRangeException("minimumFilledCells");
            }
            if (numberOfPuzzles < 1)
            {
                throw new ArgumentOutOfRangeException("numberOfPuzzles");
            }
            if (techniques == null)
            {
                throw new ArgumentNullException("techniques");
            }

            _difficulty                    = difficulty;
            _minimumFilledCells            = minimumFilledCells;
            _maximumNumberOfDecisionPoints = maximumNumberOfDecisionPoints;
            _numberOfPuzzles               = numberOfPuzzles;
            _ensureSymmetry                = ensureSymmetry;
            _eliminationTechniques         = new List <EliminationTechnique>(techniques);
        }
Exemple #2
0
        public void Create(
            string manufacturer,
            string title,
            PuzzleDifficulty difficulty,
            int partsCount,
            decimal price,
            string imageUrl,
            PartsMaterial partsMaterial,
            string description,
            string userId
            )
        {
            var puzzle = new Puzzle
            {
                Manufacturer  = manufacturer,
                Title         = title,
                Difficulty    = difficulty,
                PartsCount    = partsCount,
                Price         = price,
                ImageUrl      = imageUrl,
                PartsMaterial = partsMaterial,
                Description   = description,
                UserId        = userId
            };

            this.db.Add(puzzle);
            this.db.SaveChanges();
        }
        /// <summary>Creates generator options that will create a puzzle of the specified difficulty level.</summary>
        /// <param name="difficultyLevel">The difficulty level.</param>
        /// <returns>Generator options appropriate for this level.</returns>
        public static GeneratorOptions Create(PuzzleDifficulty difficultyLevel)
        {
            switch (difficultyLevel)
            {
            case PuzzleDifficulty.Easy:
                return(new GeneratorOptions(PuzzleDifficulty.Easy, 32, 0, 2,
                                            new EliminationTechnique[] {
                    new BeginnerTechnique()
                }, true));

            case PuzzleDifficulty.Medium:
                return(new GeneratorOptions(PuzzleDifficulty.Medium, 0, 0, 15,
                                            new EliminationTechnique[] {
                    new BeginnerTechnique(),
                    new NakedSingleTechnique(),
                    new HiddenSingleTechnique(),
                    new BlockAndColumnRowInteractionTechnique(),
                    new NakedPairTechnique(),
                    new HiddenPairTechnique(),
                }, true));

            case PuzzleDifficulty.Hard:
                return(new GeneratorOptions(PuzzleDifficulty.Hard, 0, 0, 30,
                                            new EliminationTechnique[] {
                    new BeginnerTechnique(),
                    new NakedSingleTechnique(),
                    new HiddenSingleTechnique(),
                    new BlockAndColumnRowInteractionTechnique(),
                    new NakedPairTechnique(),
                    new HiddenPairTechnique(),
                    new NakedTripletTechnique(),
                    new HiddenTripletTechnique(),
                    new NakedQuadTechnique(),
                    new HiddenQuadTechnique(),
                    new XwingTechnique()
                }, true));

            case PuzzleDifficulty.VeryHard:     // may require "guessing" technique
                return(new GeneratorOptions(PuzzleDifficulty.VeryHard, 0, null, 45,
                                            new EliminationTechnique[] {
                    new BeginnerTechnique(),
                    new NakedSingleTechnique(),
                    new HiddenSingleTechnique(),
                    new BlockAndColumnRowInteractionTechnique(),
                    new NakedPairTechnique(),
                    new HiddenPairTechnique(),
                    new NakedTripletTechnique(),
                    new HiddenTripletTechnique(),
                    new NakedQuadTechnique(),
                    new HiddenQuadTechnique(),
                    new XwingTechnique()
                }, true));

            default:
                throw new ArgumentOutOfRangeException("difficultyLevel");
            }
        }
Exemple #4
0
		/// <summary>Creates generator options that will create a puzzle of the specified difficulty level.</summary>
		/// <param name="difficultyLevel">The difficulty level.</param>
		/// <returns>Generator options appropriate for this level.</returns>
		public static GeneratorOptions Create(PuzzleDifficulty difficultyLevel)
		{
			switch(difficultyLevel)
			{
				case PuzzleDifficulty.Easy:
					return new GeneratorOptions(PuzzleDifficulty.Easy, 32, 0, 2, 
						new EliminationTechnique[]{
													  new BeginnerTechnique()
												  }, true);

				case PuzzleDifficulty.Medium:
					return new GeneratorOptions(PuzzleDifficulty.Medium, 0, 0, 15,
						new EliminationTechnique[]{
													  new BeginnerTechnique(),
													  new NakedSingleTechnique(), 
													  new HiddenSingleTechnique(), 
													  new BlockAndColumnRowInteractionTechnique(),
                                                      new NakedPairTechnique(),
													  new HiddenPairTechnique(),
												  }, true);

				case PuzzleDifficulty.Hard:
					return new GeneratorOptions(PuzzleDifficulty.Hard, 0, 0, 30, 
						new EliminationTechnique[]{
													  new BeginnerTechnique(),
													  new NakedSingleTechnique(), 
													  new HiddenSingleTechnique(), 
													  new BlockAndColumnRowInteractionTechnique(),
													  new NakedPairTechnique(),
													  new HiddenPairTechnique(),
													  new NakedTripletTechnique(), 
													  new HiddenTripletTechnique(),
													  new NakedQuadTechnique(), 
													  new HiddenQuadTechnique(), 
													  new XwingTechnique()
												  }, true);

                case PuzzleDifficulty.VeryHard: // may require "guessing" technique
                    return new GeneratorOptions(PuzzleDifficulty.VeryHard, 0, null, 45,
                        new EliminationTechnique[]{
													  new BeginnerTechnique(),
													  new NakedSingleTechnique(), 
													  new HiddenSingleTechnique(), 
													  new BlockAndColumnRowInteractionTechnique(),
													  new NakedPairTechnique(),
													  new HiddenPairTechnique(),
													  new NakedTripletTechnique(), 
													  new HiddenTripletTechnique(),
													  new NakedQuadTechnique(), 
													  new HiddenQuadTechnique(), 
													  new XwingTechnique()
												  }, true);

				default:
					throw new ArgumentOutOfRangeException("difficultyLevel");
			}
		}
 /// <summary>Initializes the PuzzleState.</summary>
 /// <param name="state">The state to be cloned into this new instance.</param>
 private PuzzleState(PuzzleState state)
 {
     // We don't use MemberwiseClone here as the new state should not share references
     _boxSize     = state._boxSize;       // immutable once created
     _gridSize    = state._gridSize;      // immutable once created
     _grid        = (byte?[, ])state._grid.Clone();
     _status      = state._status;        // immutable once created
     _filledCells = state._filledCells;   // immutable once created
     _difficulty  = state._difficulty;    // immutable once created
 }
Exemple #6
0
        private static async Task ProcessPuzzleSet(int size, PuzzleDifficulty difficulty, [NotNull] string outputFolder,
                                                   CancellationToken cancellationToken)
        {
            Console.WriteLine($"Scheduling download task for {difficulty.ToString().ToLowerInvariant()} {size}x{size} puzzles");
            foreach (int number in Enumerable.Range(1, 9999))
            {
                cancellationToken.ThrowIfCancellationRequested();

                await ProcessPuzzle(size, difficulty, number, outputFolder);
            }
        }
Exemple #7
0
        public void RegenerateNewLocks(PuzzleDifficulty difficulty)
        {
            NumbersOrder = NumbersOrder.OrderBy(x => RandomValuesGenerator.GetRandomInt()).ToList();
            Locks.Clear();
            for (int i = 0; i < 10; i++)
            {
                switch (difficulty)
                {
                case PuzzleDifficulty.Easy:
                    Locks.Add(
                        new EasyPuzzleLockPreset(
                            number: NumbersOrder[i],
                            color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4)),
                            lowerRange: 0,
                            upperRange: 9)
                    {
                        NumberCypherType = PuzzleNumberCypherType.ReverseInRange,
                        ColorCypherType  = PuzzleColorCypherType.TextShuffle
                    });
                    break;

                case PuzzleDifficulty.Normal:
                    Locks.Add(
                        new NormalPuzzleLockPreset(
                            lockNumber: NumbersOrder[i],
                            color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4)),
                            caesarShift: RandomValuesGenerator.GetInt(1, 100))
                    {
                        NumberCypherType = PuzzleNumberCypherType.Caesar,
                        ColorCypherType  = PuzzleColorCypherType.RGB
                    });
                    break;

                case PuzzleDifficulty.Hard:
                    Locks.Add(
                        new HardPuzzleLockPreset(
                            lockNumber: NumbersOrder[i],
                            color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4)))
                    {
                        NumberCypherType = PuzzleNumberCypherType.Binary,
                        ColorCypherType  = PuzzleColorCypherType.Hex
                    });
                    break;
                }
            }

            PreviousLockNumber = null;
            CurrentLockNumber  = null;
            NextLockNumber     = null;
            CurrentOrderIndex  = 0;
            CurrentLockNumber  = NumbersOrder[CurrentOrderIndex];
            NextLockNumber     = NumbersOrder[CurrentOrderIndex + 1];
        }
Exemple #8
0
 public PuzzleHost(SocketCommandContext context, PuzzleDifficulty difficulty)
 {
     Guid         = Guid.NewGuid();
     Guild        = context.Guild;
     Channel      = (SocketTextChannel)context.Channel;
     Difficulty   = difficulty;
     Locks        = new List <PuzzleLockBase>();
     NumbersOrder = new List <int> {
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9
     };
     RegenerateNewLocks(difficulty);
     LockSolved += UpdateMessage;
 }
Exemple #9
0
        public void Edit(
            int Id,
            string manufacturer,
            string title,
            PuzzleDifficulty difficulty,
            int partsCount,
            decimal price,
            string imageUrl,
            PartsMaterial partsMaterial,
            string description)
        {
            var puzzle = this.FindById(Id);

            puzzle.Manufacturer  = manufacturer;
            puzzle.Title         = title;
            puzzle.Difficulty    = difficulty;
            puzzle.PartsCount    = partsCount;
            puzzle.ImageUrl      = imageUrl;
            puzzle.PartsMaterial = partsMaterial;
            puzzle.Description   = description;

            db.SaveChanges();
        }
Exemple #10
0
    public static DifficultyParameters GetDifficultyParameters(PuzzleDifficulty difficulty)
    {
        DifficultyParameters difficultyParameters = null;

        switch (difficulty)
        {
        case PuzzleDifficulty.Easy:
            difficultyParameters = GetEasy();
            break;

        case PuzzleDifficulty.Medium:
            difficultyParameters = GetMedium();
            break;

        case PuzzleDifficulty.Hard:
            difficultyParameters = GetHard();
            break;

        case PuzzleDifficulty.VeryHard:
            difficultyParameters = GetVeryHard();
            break;
        }
        return(difficultyParameters);
    }
Exemple #11
0
        private static async Task ProcessPuzzle(int size, PuzzleDifficulty difficulty, int number, [NotNull] string outputFolder)
        {
            string url        = string.Format(UrlTemplate, size, (int)difficulty, number);
            string puzzlePath = outputFolder + string.Format(@"\{0}\{1:00}x{1:00}\Puzzle{2:0000}.txt", difficulty, size, number);

            if (!File.Exists(puzzlePath))
            {
                string html = await ExecuteRequestAsync(url);

                var parser = new ResponseParser(html, size);
                if (!parser.IsValid)
                {
                    throw new Exception($"Failed to parse puzzle from {url}: '{parser.PuzzleText}'");
                }

                string puzzleName = puzzlePath.Substring(outputFolder.Length);
                Console.WriteLine("Writing " + puzzleName);

                Directory.CreateDirectory(Path.GetDirectoryName(puzzlePath));

                var writer = new TextPuzzleWriter();
                writer.Save(puzzlePath, parser.PuzzleText);
            }
        }
Exemple #12
0
		/// <summary>Initialize the GeneratorOptions</summary>
		/// <param name="size">The size of the puzzle to be generated.</param>
		/// <param name="difficulty">The difficulty of the puzzle to generate.</param>
		/// <param name="minimumFilledCells">The minimum number of filled cells in the generated puzzle.</param>
		/// <param name="maximumNumberOfDecisionPoints">The maximum number of times brute-force techniques can be used in solving the puzzle.</param>
		/// <param name="numberOfPuzzles">The number of puzzles to generate in order to pick the best of the lot.</param>
		/// <param name="techniques">The techniques to use while generating the puzzle.</param>
		/// <param name="ensureSymmetry">Whether all puzzles generated should be symmetrical.</param>
		private GeneratorOptions(
			PuzzleDifficulty difficulty, int minimumFilledCells, int? maximumNumberOfDecisionPoints, int numberOfPuzzles,
			EliminationTechnique [] techniques, bool ensureSymmetry)
		{
			if (difficulty != PuzzleDifficulty.Easy &&
				difficulty != PuzzleDifficulty.Medium &&
				difficulty != PuzzleDifficulty.Hard &&
                difficulty != PuzzleDifficulty.VeryHard) throw new ArgumentOutOfRangeException("difficulty");
			if (minimumFilledCells < 0) throw new ArgumentOutOfRangeException("minimumFilledCells");
			if (numberOfPuzzles < 1) throw new ArgumentOutOfRangeException("numberOfPuzzles");
			if (techniques == null) throw new ArgumentNullException("techniques");

			_difficulty = difficulty;
			_minimumFilledCells = minimumFilledCells;
			_maximumNumberOfDecisionPoints = maximumNumberOfDecisionPoints;
			_numberOfPuzzles = numberOfPuzzles;
			_ensureSymmetry = ensureSymmetry;
			_eliminationTechniques = new List<EliminationTechnique>(techniques);
		}