You will use Perl's CGI capabilities with HTML forms to implement a version of the Sukoku puzzle game.
Our version of sudoku is played on a 4x4 grid, which is divided into four 2x2 regions (top left, top right, bottom left, bottom right). The goal of the game is to place the numbers 1-4 into the grid such that every number appears exactly once in each row, column, and region. The game begins with several numbers that cannot be moved already in place; the player must reason logically to determine how to fill the remaining squares. There is a great deal more information to be found at Wikipedia's article on Sudoku, and there are many online versions available, though usually on larger 9x9 grids. Web Sudoku is one such version.
| 2 | |||
| 1 | 4 | ||
| 3 | 4 | ||
| 2 | 3 |
| 2 | 4 | 3 | 1 |
| 1 | 3 | 4 | 2 |
| 3 | 2 | 1 | 4 |
| 4 | 1 | 2 | 3 |
You will write a single Perl script, sudoku.cgi, that
allows a user to play a game of Sudoku from beginning to end, checking
his/her moves along the way and allowing him/her to undo them.
sudoku.cgi, your program will read an
initial Sudoku board from the file initboard.txt, in the
same directory as your script. The file will be four lines long, and
each line will contain four space-delimited numbers. Numbers will be
either 1-4, to signify that that number goes in the corresponding
space, or 0, to signify that the space is blank.
initboard.txt (equivalent to the starting
game board shown above)2 0 0 0 1 0 4 0 3 0 0 4 0 0 2 3
Your program must generate an HTML page that displays the Sudoku board
as a table, similar to the ones shown above. The numbers that were
initialized from initboard.txt must be uneditable text,
and each empty cell must contain a text field so that the user can
enter his/her input. The HTML page must also contain a button to submit
the form (i.e., play one move).
The user will play the game by repeatedly filling in a single text box and submitting the form. Upon receiving the user's input, your script must perform the following three tests:
| 2 | |||
| 1 | 4 | ||
| 3 | 4 | ||
| 2 | 3 |
initboard.txt so that the user may start over.
Because the user is not allowed to edit legally placed values after he has submitted them, you are required to implement an "Undo" button. The Undo button should appear in the page whenever there is a move to be undone, but it should not appear when there is not (i.e., before the user has placed any numbers or after he has undone all his/her moves). Each press of the undo button should return a new page with the user's previous move removed from the board. The user must be able to undo all his/her moves by repeatedly pressing the button.
You may want to store the list of past moves as a space-delimited string value to a hidden <input> component. You will need to update it whenever the user makes a legal move or presses Undo.
Allowing multiple users to run Perl CGI scripts on the same machine raises some security problems, so the tech staff has installed CGIWrap. CGIWrap allows the web server to run your script under your user account, which means, in brief, that you can read and write files that you own but not those owned by others.
To run a Perl script using CGIWrap, you must place it in
your public_html/cgi-bin directory
on cs1520.cs.pitt.edu. Be aware that your account on
this computer is not your usual Pitt account, and your home directory
is not your AFS directory. Your username is the same as the userID
that you used to submit the first assignment. The initial password is
your PeopleSoft ID number which was emailed to you. You are advised
to change your password when you log in by running the
passwd command and following its instructions.
To copy your script to cs1520.cs.pitt.edu, you may find
it useful to use scp to transfer it
from unixs.cis.pitt.edu or another Unix machine. If your
script is titled yourscript.cgi and your username
is userXX, then the following command would copy
the script to the appropriate directory:
scp yourscript.cgi userXX@cs1520.cs.pitt.edu:public_html/cgi-bin
Your script must begin with a line that tells CGIWrap to call the Perl interpreter.
#!/usr/bin/perl -w
It must also have its executable bit set.
chmod 755 yourscript.cgi
If your username is userXX and your script is
titled yourscript.cgi, then there are two URL's
that you can visit to see its output:
http://cs1520.cs.pitt.edu/~userXX/cgi-bin/yourscript.cgihttp://cs1520.cs.pitt.edu/~userXX/cgi-debug/yourscript.cgi
Note that you do not create a cgi-debug
directory to view debugging output; the web server still runs the
program in your cgi-bin directory; only the URL is
different.
/afs/cs.pitt.edu/public/incoming/CS1520/2/ cp sudoku.cgi /afs/cs.pitt.edu/public/incoming/CS1520/2/user01.cgi)
ls -l command in Unix) to make sure that your
submission is there and it has a non-zero file size.user01.second.cgi) and email the
instructor.Back to the class web page