About People Prospective Undergraduate Postgraduate Research
Home > Undergraduate > Human Computer Interaction CITS3201 > Labs   

HUMAN COMPUTER INTERACTION (233.411)


Lab 3: Downloading Grids from the Web

Aim

This lab continues the construction of the sudoku "widget" - the example interactive HTTP application from Labs 1 and 2.

The aim of this lab is to obtain the grid information for the sudoku widget automatically from over the internet.

References

The reference for this lab is once again the PHP On-line Manual.

The Task

In Lab 2 you manually stored the sudoku grid information in an array, and wrote code to generate the grid from that array, as well as code to verify the validity of the grid. In this lab we wish to retrieve the information for the array from an internet location.
  1. Using functions

    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.

  2. Downloading the grids as text files

    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.

  3. Choosing a grid at random

    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.

  4. Parsing the grid into an array

    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.