CS552 Assignment 4 ("fun" and games)
Start on this one right away, because this can be time-consuming to debug.
It's probably going to seem a little weird, but after you work through it,
you'll have prepared yourself for an essential aspect of the project.
Your assignment is to make the web server play the "guess the number game"
with the user. This game goes like as follows:
- The computer thinks up a number between 1 and 100.
- The player guesses a number.
- If the player's number is the computer's number, the computer says "You
got it" and the game is over. Otherwise the computer says "Nope, that's
not it" and invites the user to guess another number.
- The player guesses another number.
- If that number is the computer's number, the computer says "You got
it" and game is over.
- The computer says "you're getting warmer" if this guess was closer than
the previous guess. Otherwise, the computer says "you're getting
colder." In any case, the computer invites the player to guess another
number.
- Go back to step 4.
- At any stage, the player may get bored and decide to go watch a movie
instead of playing stupid games.
The constraints:
- This must be a cgi script or PHP script that stores absolutely
no state information about any games. It must take all parameters,
including the current state of the game, from the web browser and send
them back to the web browser, like the example in class.
- This should be just one script.
- Show a list or table of numbers, and have the user
click on one to make the guess. After the guess, you should still make
that number visible, but make it so that the user can't click on it
again.
- If you use the GET method (which you probably will), the computer's
number will show up in the URL display during gameplay. In any case,
it will show up in the document source. "Mask" this by
multiplying the computer's guess by some crazy number like 34510 when
you transmit it back to the browser for the next guess.
- However, you don't have to mask the previous guess if you don't want to.
- I don't care about it being fancy-looking, but I want it to work.
- Email the URL and the location of the script to
cs552-handin@cs.uchicago.edu.
Hints:
- You need to transmit the number to be guessed, the player's last guess,
and the numbers already picked to the web
server and back. In addition, you need to transmit a new pick to
the server along with the rest of the parameters.
- Start with the listing of numbers and the computer guessing a number.
The next to last thing you should do is make it so that when you click
on them, they "disable" as specified in the instructions.
The last thing you should do is "mask" the guessed number.
Don't bother with this until you get the rest working!
- Split the previous guesses into a list when you get them.
Then, when you send it back to the browser, join them again.
- This assignment is nothing but a bunch of if statements, while or for
loops, and maybe some regular expression matching.
- The lecture 4 notes can help you.
- Do this assignment one step at a time. Do one feature, then move on
to the next one only after that feature works right.