Play Sudoku For Kids Online - Creating a Game, and Link to Game
This article is all about developing a web page that
implements a kids version of the popular Sudoku game. If you are knowledgeable about the standard (nine ) version of Sudoku but not
familiar with the four versions it is possible to jump to the section below
entitled,"Sudoku For Kids: Four By Four Version." If this is all new to you just keep on
reading.The standard version of Sudoku is played on a nine by nine grid, where
in an entirely solved puzzle each cell of the grid contains an integer between
1 and nine (inclusive). The principle
that defines a correct solution is: all the nine cell rows (horizontal
collection of cells) must contain every integer from one to nine once and only
once, each column (vertical collection of cells) must comprise each integer
from one to nine once and only once, and every three sub-group of cells must
contain every single integer from one to 2 once and only once. You will find nine sub-groups, three rows of
3 sub-groups each row (every sub-group is a three by three collections of human
cells) which cover the whole nine by nine grid .Sudoku For Children: Four By
Four Model My version of Sudoku For Kids utilizes a four by four grid of cells
in which in a totally solved puzzle every cell of the grid includes an integer
between one and four (inclusive).
Analogous to the standard version, Sudoku For Kids needs each row,
column and sub-group to contain every integer from one to four. Sudoku For Kids: User InterfaceI place the
game near the top of the page on the ideal side and display an advertisement of
our merchandise only to the left of this match.
The game grid's four quadrants have four different background colors to
make it easier for young kids to think about those groups of four cells when
making sure all four integers are found.Four buttons appear only under the
grid:"New" (start a new mystery ) /"Reset" (start exactly the
exact same puzzle from the beginning) /"Hint" (fill in one of the
empty cells for me) /"Check" (display wrong cells at red, or inform
me whether the mystery is totally solved).
The"Tip" and"Assess" buttons are important for young
kids. Any kid who will use a computer
mouse and click a button can solve the puzzle, the limiting case being
requesting hints until the whole grid is full of. If the mystery is solved and the consumer
clicks on"Check" an alert box is displayed that congratulates the
user for solving the mystery and tells him how many hints have been obtained
and how many times"Check" was clicked prior to the final period when
the mystery had been solved. The hope is
that the kid will continue playing before"Hints: 0 / PreChecks: 0" is
displayed at which time the child might be ready to move on to playing standard
Sudoku.Instructions are displayed just below the game, not in the top. This is for the advantage of returning users
who need not be distracted by reading the instructions again.Sudoku For Kids:
Operation of the Web PageIn order to make the web page self contained, all
puzzles that the game can display are downloaded as part of the Javascript in
the HTML file (both options and starting places are downloaded). The simple fact that the user's browser
desire not speak with the server when playing also allows the user to save the
web page to his pc and play later even if he is no more connected to the
Internet.The four Sudoku For Kids game has only 288 unique solutions (legal
ways to fill in all sixteen cells).
Every one the solutions could be"forced" by initially filling
in four cells (four cells of the solution can be chosen such that just this
particular one of the 288 possible solutions is consistent with the values
selected for the four initially filled in cells). Some of those 288 solutions have 12 different
four-cells-filled-in-starting-positions and a few have 128 different
four-cells-filled-in-starting-positions.
Not one of those 288 unique solutions could be uniquely specified with
less than four cells in the beginning position.I decided to only implement
starting places with the minimal four filled in cells for 2 reasons. 1) Sudoku For Kids is already far easier than
standard Sudoku due to the decreased size of the playing grid; it appeared
reasonable to make it as hard as possible.
2) Any user wishing to play an easier puzzle can click on
the"Hint" button to fill in additional cells prior to starting to
fill in cells .I chose to execute all 288 solutions with seven starting
positions for each solution allowing"thousands of puzzles"
(288x7=2016). The encoding I chose for
every puzzle employs an ASCII character for each cell, sixteen characters to
spell out the entire grid. The sixteen
personalities of the solution are each'1'/''two'/'3'/'4' and also the sixteen
characters of every starting position also include'0's (later displayed by the
web page within an empty cell). Each
solution together with its seven beginning positions is represented in the
Javascript with a series of length 128 figures ((solutions+7starts)x16=128).Here
is an example of a string representing a solution and its own seven starting
positions:pzl[147]="31242431134242133004000000000210300000010040020001200000000040030100003000024000002004000300001000042000030000100000043010020000";This
is not a very space efficient method of representing the data, but all 288
services and their starting positions require just about forty kilobytes of
information transfer to the user's computer.
When compared to hundreds of kilobytes necessary to download images
associated with our product advertisement, the forty kilobytes is not enough to
significantly impact the user experience.
Representing the data as ASCII text made data manipulation by Javascript
functions simple.New (calls work NewPuzzle):1) Create a random number out of
0-287 to choose one of those 288 unique options. 2) Generate a random number from 0-6 to pick
one of the seven starting places for the solution. 3) Initialize"solution"
and"startpt" utilizing parts of the two kilobytes of downloaded
information (which components are used is specified from the random numbers
chosen in steps 1 and 2 ). 4) Call
function ResetPuzzle (see following button).
Reset (calls function ResetPuzzle):1) Set font color to black for all
cells (might have previously been red if incorrect response ). 2) For many cells if a part of beginning
place fills in number and make cell read only, otherwise make cell blank and
writable. 3) Set number of hints
received and PreChecks done to zero.
Hint (calls function HintPlease):1) Repeatedly generate random amount
from 0-15 until it corresponds to a blank cell or until you have attempted
1,000 times. Two ) In case you failed to
obtain a blank cell in step 1, go through each cell from 0-15 looking to get a
sterile cell. 3) In case you have
detected a sterile cell, copy the value from the corresponding cell
in"alternative" to the cell in the displayed grid. 4) Increment amount of hits received. Assess (calls function CheckPuzzle): 2) For
every cell if the value does not match"alternative" (and if the cell
is not blank) then change the font color to red. 3) If all cells
matched"alternative" then congratulate the user. 4) Increment the number of PreChecks. Sudoku For Children: Establishing the
PuzzlesI utilized a"C" program to generate the strings used by the
Javascript to signify the answers and start points. You can download the"C" source code
from php/SudokuForKids.c comparative to your own home page link in the author's
resource box. The code begins by
discovering the 288 unique Sudoku For Kids solutions, then for every
alternative it tries all probable combinations of four starting cells and tests
which starting places can only result in this one end solution. After finding all possible starting places
for all solutions, it writes each option and seven associated starting
positions to a file as a string in the format shown previously (see pzl[147]=
"312..." above).The arrangement that represents the Sudoku For Kids
grid includes a 3 dimensional array containing every possible value which could
be found in every grid cell (elements[rows]
[columns][num_vals_still_poss_for_cell]).
SudokuSolver is a recursive function (it calls itself) that finds all
solutions by"imagining" each possible value of each cell one at a
time and then calling itself on the"guess"-containing puzzle
(num_vals_still... for that cell is equivalent to 1 and the"guess"
has become the value at that cell), terminating a branch of the tree when it
encounters an unsolvable position (num_vals_still... for some cell is
equivalent to 0, which means some previous guess was incorrect).Sudoku For
Children: Decision In summary, because generating the Sudoku For Kids options and starting positions was
computationally expensive it had been beneficial to create them in advance
(maybe not in real-time) so that the HTML and Javascript are running about the
user's computer had little to do so as to implement the match, thereby allowing
the match to run quickly from the user's browser. Downloading the answers and starting places
inside the web page also removed the need for server-client communicating after
web page download has been complete, allowing the user to save the web page and
continue to play after ceasing to be connected to the Internet.
Click here: coding for kids
Comments
Post a Comment