/// <remarks> /// Shuffles up to 256 times. /// Otherwise, about 60 words did not fit in 720 levels. /// </remarks> public static List <CrossedWord> Generate(CrosswordGenerator generator) { int maxAttempts = 256; List <CrossedWord> originalCrossedWords = null; List <string> originalWords = null; for (int attempt = 0; attempt < maxAttempts; ++attempt) { generator.crossedWords = generator.TryGenerate(); if (generator.allWordsFit && generator.crossedWords.Count > 0) { return(generator.crossedWords); } if (originalCrossedWords == null) { originalCrossedWords = new List <CrossedWord>(generator.crossedWords); } if (originalWords == null) { originalWords = new List <string>(generator.words); } Deck.ShuffleList(generator.words); } generator.crossedWords = originalCrossedWords; generator.words = originalWords; Debug.LogError("Not all words fit. First word in generator was " + generator.words[0]); return(generator.crossedWords); }
private static void LogErrorIfMissingAnswerInCrossword() { CrosswordGenerator generator = new CrosswordGenerator(); var levels = AnagramLevelsController.instance.Levels; foreach (var level in levels) { var wordList = CUtils.BuildListFromString <string>(level.answers); generator.SetWords(wordList); generator.RTL = ConfigController.Config.isRightToLeftLanguage; var crossedWords = CrosswordShuffler.Generate(generator); if (generator.allWordsFit) { continue; } Debug.LogError("Not all words fit in level word=" + level.word); } }
static void Main() { IWords englishDictionary = new EnglishWordsDictionary(); var wordsOperator = new WordsOperator(englishDictionary); var randomGenerator = new RandomGenerator(); var painter = new Painter(); var listOfAllWords = wordsOperator.ListOfAllWords; painter.ChooseAGame(); var gameOfChoice = int.Parse(Console.ReadLine()); while (gameOfChoice != 1 || gameOfChoice != 2) { if (gameOfChoice == 1) { string[,] crossword = new string[GlobalConstants.MatrixSize, GlobalConstants.MatrixSize]; var crosswordGenerator = new CrosswordGenerator(crossword, wordsOperator); crosswordGenerator.GenerateFrame(); painter.PaintMatrix(crossword, 0, 0); crosswordGenerator.GenerateCrossword(); break; } else if (gameOfChoice == 2) { var wordsExplorerFieldGenerator = new WordsExplorerFieldGenerator(); var validWordsCounter = new ValidWordsCounter(); var wordsExplorerSolver = new WordsExplorerSolver(); var wordsExplorerField = wordsExplorerFieldGenerator.GenerateField(englishDictionary.GetAplphabet); var listOfExistingWords = validWordsCounter.GetListWithDecodedWords(wordsExplorerField, listOfAllWords); painter.PaintWordsExplorer(wordsExplorerField); painter.GuessingAWordVisualizer(listOfExistingWords); var guessedWords = Console.ReadLine(); wordsExplorerSolver.GuessAWord(wordsExplorerField, listOfExistingWords, guessedWords); break; } else { Console.Clear(); painter.ChooseAGame(); gameOfChoice = int.Parse(Console.ReadLine()); } } }
private void wordsFileBtn_Click(object sender, EventArgs e) { List <Word> words = new List <Word>(); using (StreamReader reader = new StreamReader(wordsFileBox.Text)) { while (!reader.EndOfStream) { string word = reader.ReadLine(); words.Add(new Word(word)); } } CrosswordGenerator generator = new CrosswordGenerator(words); generator.Generate(); int sizeN = generator.blocks.GetLength(0) - 1; int sizeM = generator.blocks.GetLength(1) - 1; crosswordGridView.Columns.Clear(); crosswordGridView.Rows.Clear(); crosswordGridView.BackgroundColor = Color.Black; crosswordGridView.DefaultCellStyle.BackColor = Color.Black; for (int i = 0; i < sizeN; i++) { crosswordGridView.Columns.Add("Column", "Column"); } for (int i = 0; i < sizeM; i++) { crosswordGridView.Rows.Add(); } foreach (DataGridViewColumn c in crosswordGridView.Columns) { c.Width = 50; } //set width of row foreach (DataGridViewRow r in crosswordGridView.Rows) { r.Height = 50; } //set width of column foreach (DataGridViewColumn c in crosswordGridView.Columns) { c.Width = crosswordGridView.Width / crosswordGridView.Columns.Count; } //set width of row foreach (DataGridViewRow r in crosswordGridView.Rows) { r.Height = crosswordGridView.Height / crosswordGridView.Rows.Count; } //make all cells read only for (int row = 0; row < crosswordGridView.Rows.Count; row++) { for (int col = 0; col < crosswordGridView.Columns.Count; col++) { crosswordGridView[col, row].ReadOnly = true; } } for (int i = 0; i < sizeN; i++) { for (int j = 0; j < sizeM; j++) { if (generator.blocks[i, j] != null) { crosswordGridView[i, j].Value = generator.blocks[i, j].letter.Character; crosswordGridView[i, j].Style.BackColor = Color.White; } } } }