# Computing: Website and Database Programming

## Simple Nim.

1. The Nim game.

 Nim is a mathematical game of strategy in which two players take turns removing (or "nimming") objects from distinct heaps or piles. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap or pile. Depending on the version being played, the goal of the game is either to avoid taking the last object or to take the last object. There are lots of different versions of Nim, one of the best known is the Marienbad game, so called because having been played in the French New Wave film Last Year at Marienbad (1961). In this variant, there are 4 heaps (rows) with 1, 3, 5 and 7 objects (actually matches). The players may take any number of matches they want (at least one) but all from the same row. The player, who takes the last match, looses. Game variants, where the last object looses, are sometimes called misere variants If you like this kind of strategy games, you may want to download my Marienbad PC application from the Lazarus/Free Pascal Programming section of my site. In Fort Boyard Nim, there is one single heap with 15 objects (matches or sticks). The players may take 1, 2 or 3 matches at each turn. The player, who takes the last match, looses. The Game of Whytoff consists of several heaps and the players may take matches in one or two of them; if they take in two heaps, they must remove the same number of objects in each of them. The last match wins. In the Nimbi variant, there are 4 rows of 8 matches each. The players take 1, 2 or 3 matches, that are adjacent either in a row or a column. The last match wins or looses, depending on what has been said at the beginning of the game. Other variants, with more specific rules, are for example the Grundy game and Squayles.
2. My Simple Nim online application.

 My Simple Nim online application is based on Fort Boyard Nim, with the initial number of matches (10 to 30), as well as the winning rule being set at the beginning of the game. The application is for 1 human player, who plays against the computer. There are three strength levels available: Novice: The computer makes all random moves, including at the end of the game (may be seen as if it did not remember if the last match wins or looses). Intermediate: At the first half of the game (i.e. until half of the initial number of matches has been taken), the computer plays randomly or not (1 random move out of 3); in the second half, it plays at full strength. Expert: The computer plays at full strength, i.e. if there is a possibility to win the game, it will always win. To play the game, choose the number of initial matches, set the wanted game parameters and push the Start button. If the computer has to make the first move, it does it. Now it's your turn. Enter the number of matches, that you want to nim, then push Play. The computer moves automatically after you have done so. If the game is over, push New to prepare for a new one, set the game parameters and push Start to begin. Use the following link to start the online application.
3. The Simple Nim Perl script.

Simple Nim is a Perl application, user input validity check, input field focusing and display of the winner message being done by Javascript. The validity check is done by a function called when the submit button is pushed. This function, displaying a message if input isn't ok, returns a Boolean: If it is true, the Perl script is called, otherwise, nothing happens (concerning the Javascript code of this function, cf. below). The code for the field focusing and the message display is directly included into the website, generated by the Perl script. Use the following links to download the Simple Nim application (HTML, Javascript and Perl sources) resp. to show the Simple Nim Perl source code.