Figure 3


Pseudocode for processing a user's move in a Web game.

#define MAX_ENTRIES 100  /* max number of CGI input fields */
#define MAXLEN 120       /* max length of a string */ 
/* CGI data structure for entry */
/* Data structure for Game */
/* Data structure for a Move */
enum player_type {USER,COMPUTER};
typedef enum player_type Player;

int main()
{
  entry entries[MAX_ENTRIES];
  int etnum = 0; 
  Game G; 
  Move mv;
  char user_name[MAXLEN];

  start_reply("Move Outcome");
  cgi_errs();
  etnum = build_entries(entries);

  read_state(entries, etnum, &G, &mv, user_name); 
  printf("

Hello %s

\n", user_name); display_game(G); if (!legal_move(G, mv)) { printf("

%s, please try again...

\n", user_name); display_form(G, user_name); } else { make_move(USER, user_name, mv, &G); display_game(G); if (game_over(G)) /* the user has won */ give_result(G, COMPUTER, user_name); else { comp_move(G, &mv); make_move(COMPUTER, user_name, mv, &G); display_game(G); if (game_over(G)) /* the computer has won */ give_result(G, USER, user_name); else { printf("

%s, your turn

\n", user_name); display_form(G, user_name); } } } printf(""); return 0; }