|
|
| Home > Undergraduate > Human Computer Interaction CITS3201 > Labs |
HUMAN COMPUTER INTERACTION (233.411)
The aim of this lab is to obtain the grid information for the sudoku widget automatically from over the internet.
When Lab 2 was issued we hadn't covered functions in the lectures. From now on functions should be used where appropriate. For example, if you haven't done so already, put your code to validate a grid (held in an array) in a function so that it can be called at any point in your code. You might also put the code you wrote to print out the grids (both as plain text and as html) in functions so that you can easily call either as required.
If you have a look at Dr Royle's Sudoku Patterns site, you will see that a link has been added that allows you to download the grids.
If you follow this link, you will see that it retrieves the grids as a text file with rows of numbers. Each line contains the information for a separate pattern or grid. Write php code to download the text file, and store it in a string variable.
Write code that firstly counts the number of grids (lines) in the downloaded file. (You may like to later add code that allows the user to choose which puzzle family to select the grid from. Different families contain different numbers of grids.)
Once you know the number of grids, generate a random integer (from a uniform random distribution) between 1 and the number of grids. Then obtain the corresponding grid (line) from the downloaded text and store it in a string variable.
Each digit in a line reprents the contents of a sudoku square, numbering from left to right, top to bottom.
(You will recall from Data Structures and Algorithms that this is called row-major order.)
Read the characters from the line into the array (the zeros represent empty squares). Finally verify that the grid is valid, and produce the displayed version.
|
Copyright © 2005,
Cara MacNish School of Computer Science & Software Engineering The University of Western Australia. |
![]() |