Click to return Home

  Newsreel
  Products & Services
  Web Watch
  Software Update
  Events Diary
  Articles
  The Magazine
  Subscribe
  Contact Us


Overview of the game processes

  
DNJ Dilemma is like the layers of an onion - inside each statistics session is a series of games, inside each game is a series of rounds, and inside each round is a pair of card-plays (left and right). The basic procedural spec reads "keep doing card-plays until the round is finished, keep doing rounds until the game is finished, and keep doing games until the session is finished, or the page is unloaded".

Processing begins with a block of inline JScript code in the <HEAD> section, executed once when the page loads. This creates the game's custom data objects and history session arrays, and sets system values such as the points awarded for the four possible card combinations. When this code finishes executing, the game does nothing, while waiting for the <body> tag's onload event to fire.

The <body> tag's onload event handler is the function waitToStart()., which monitors these three asynchronous start-of-run processes:

  • Strategy function hookup - creating an array of pointers to the strategy functions held in the game page's parent frameset document, and loading the strategies' names into the game control panel list boxes.
  • User logon - the user typing their name into the 'Welcome to DNJ Dilemma' dialog that overlays the display when the page first loads.
  • Image file download - the browser downloading the image files (.gif and .jpg) for the page's <img> elements, as well as other files which will be substituted into those elements during the game's progress.  

waitToStart() doesn't let the game start until all three processes are complete. Each time it's called, it checks to see if any of them are still unfinished, and if so,  creates a setTimeout() event to call itself again one second later. When all three processes are done, waitToStart() calls the function initpage() instead.

initpage() performs further start-of-run tasks, which require the waitToStart() processes to be completed first. When it ends, the page enters a dormant state, with no functions running. However the game control panel is visible, which means that the user can select game options ( left-hand player, high-speed play etc) then press the Start Game button. This calls the functions initGame().

initGame() does the following:

  • Sets score, current round number and other registers to zero.
  • Randomly chooses the number of rounds for this game (between 6 and 16).
  • Randomly selects a computer strategy for the right-hand player (unless the user has chosen a strategy).
  • Randomly selects a left-hand player strategy, if the game is in self-play mode and the user hasn't chosen a strategy.
  • Clears down the game history display (the column of butterfiles and spiders).

It then calls the function initRound().

initRound() increments the current round number and displays 'no card' images in bother player columns. It then fires off asynchronous player processes for the left and right hand players (click here for details). 

The game is now in a dormant state again, which will be punctuated by two calls to the function processCard(), as the two players play their cards. processCard() doesn't do much; it simply displays a 'back-of-card' image in the appropriate column, and stores the player's option (cooperate or defect) in a variable. However it also checks to see if both players have now played their cards for this round. If they have, it calls the end-of-round function processRound().

processRound() does the following:

  • Turns the cards over to show each player's option (cooperate or defect) in that round;
  • Calculates each player's score for that round;
  • Updates the on-screen scoreboard and game history displays;
  • Updates the game statistics variables.

It then checks to see if this was the last round of the game. If not, it calls initRound() for he next round of the game. If this was the last round, it calls endGame() instead.

endGame() updates the statistics session data arrays, and displays an 'End of game' message. If the game is in self-play (computer vs computer) mode, it checks to see if this was the last game of the set (in this mode the user can tell the page to play a number of games between the chosen strategies). If this was the non-last game of a self-play set, it increments the game counter and calls initGame(). If not, it makes the game control panel visible, and the page enters a dormant state, ready for the user's options.


 

 



 

 

 

 

DNJ Dilemma
The Inside Story

Inside DNJ Dilemma

Overview of the game's processes

Indirectly-called strategy functions

Graphical scoreboards

Animated buttons

Dynamically-loaded list boxes

Asynchronous left/right players

Where are the strategy functions?

Play DNJ Dilemma