The Simplest Algorithm for Creating a Field Puzzle (Part 1)

Hi, Khabrovtsy. In this article, I want to share with you a little my experience and show you my simple algorithm that I came up with to create the Filward.


By Filward, I will mean this familiar game.



The game has a field usually sized NxN filled with words. Our goal is to find all the words.
In our version there will be no letters in the field that do not belong to any word and serve to knock down the player, and there will be no letters that belong to several words at once. The usual classic fileword. And so, the task is set. Need to decide.


The first thing I always break the task into subtasks. To solve this problem I will need:


  1. DB with words.
  2. An algorithm that inserts words into a field.
  3. An algorithm that checks a user-selected word for correctness. For example, we put the word “programming” in the field, and the user saw “world” there and selects this word. The user is right - there is such a word, but we did not guess it. We need an algorithm that will check the user's guesses and tell him whether he is right or not.

, . .


1) .


, . words_2 . words_3 . :



words_2
-
-
-
-
words_3
-
-
-
-
words_4
-
-
words_5
-
-


.. ( , ).


5x5.


. 5x5, , = 25. 2 :


  1. - N- - , = 25.
  2. - , = 25.

1


- N, . N = 6. - .


25/6 = 4. words_4 .
N 1, .
25 – 4 = 21
6-1 = 5;
N!=1;


++

giveWord() – , , .


wordsArray.Push() – , .


N=6;
freePlace =25;
While(N!=1)
{
wordsArray.Push( giveWord( freePlace/N ) ); //    
freePlace-= freePlace/N; //  -  
N--; // - 
}

wordsArray, 5 (4,4,4,4,4).


, = freePlace.


wordsArray.Push( giveWord( freePlace ) );

(4,4,4,4,4,5). =25. .


, . .


.


0 1 ( 0 1) 0 1 freePlace / N. .


2


- , . – 25. , . - - . - , , - . , 25 , 2 , 12 13 . . 25 – 5x5, 9 – 3x3, ? , - 1- . - .


So. 1/3 of the part we have completed. We have a database and an algorithm for forming an array of words with which we will fill our field and the first part ends here. Next parts we will shove these words in the field so that they all fit.

Source: https://habr.com/ru/post/undefined/


All Articles