private void CreatePuzzle(string word) { var puzzle = PuzzleMaker.MakePuzzle(word); var startY = -1 * puzzle.height / 2; var startX = -1 * puzzle.width / 2; var start = new Vector2(startX, y: startY); for (var x = 0; x < puzzle.width; x++) { for (var y = 0; y < puzzle.height; y++) { var fy = start.y + y; var fx = start.x + x; if (y % 2 == 0) { fx += 0.5f; } var pos = new Vector2(fx, fy); var img2 = ImgDir + puzzle.puzzleData[x, y] + ".png"; var go = Instantiate(hexPrefab, pos, Quaternion.identity); go.GetComponent <SpriteRenderer>().sprite = LoadNewSprite(img2); go.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); } } }
public void LoadPuzzle(string word) { _words = word.ToUpper(new CultureInfo("tr-TR", false)).Split(' ').ToList(); foreach (Transform child in PuzzleParentTransform) { Destroy(child.gameObject); } var sentence = Regex.Replace(word.ToUpper(new CultureInfo("tr-TR", false)), @"\s+", ""); _currentPuzzle = PuzzleMaker.MakePuzzle(sentence); }
public Puzzle Generate(bool verbose = false, bool print_fixed_cells = false) { int [] solution_grid = new FastPopulator().PopulateGrid(shape, new PopulatorArgs() { alphabet = alphabet, print_fixed_cells = print_fixed_cells }, initial_grid); if (verbose) { shape.Print(solution_grid, alphabet); } int [] puzzle_grid = PuzzleMaker.GeneratePuzzle(shape, solution_grid, seed, min_clues); if (verbose) { shape.Print(puzzle_grid, alphabet); } int [] output_cells = new int [letters == null ? 0 : letters.Length]; if (letters != null) { if (pick_numbers_randomly) { List <int> [] letter_locations = new List <int> [shape.group_size]; for (int i = 0; i < shape.group_size; i++) { letter_locations [i] = new List <int> (); for (int j = 0; j < shape.num_cells; j++) { if (solution_grid [j] == i + 1 && puzzle_grid [j] == 0) { letter_locations [i].Add(j); } } } Random rng = new Random(seed); for (int i = 0; i < letters.Length; i++) { int l = letters [i]; int ind = rng.Next(letter_locations [l].Count); int loc = letter_locations [l] [ind]; letter_locations [l].RemoveAt(ind); output_cells [i] = loc; } } else { new RecursiveSolver().Solve( shape, puzzle_grid, new SolverArgs() { rng = new Random(seed + 1), max_solutions = 1, iteration_limit = 50000 }, out int diff, out int [] [] cell_fill_orders ); // We only care about the cell_fill_orders - we know what the solution grid is List <int> fill_orders = cell_fill_orders [0].Reverse().ToList(); for (int i = 0; i < letters.Length; i++) { int letter = letters [i]; int last_index = 0; for (int j = 0; j < fill_orders.Count; j++) { // Console.WriteLine (fill_orders [j] + " " + solution_grid [fill_orders [j]]); if (solution_grid [fill_orders [j]] == letter + 1) { last_index = j; break; } } int last_cell = fill_orders [last_index]; fill_orders.RemoveAt(last_index); Console.WriteLine(alphabet [letter] + " => " + last_cell); output_cells [i] = last_cell; } } } return(new Puzzle(this, puzzle_grid, solution_grid, output_cells)); }