Bridge

Game Bridge-It was invented by David Gale and described by Martin Gardner in his Mathematical recreations column.

Rules

The object of the game is to build continuous bridge of hash signs from left to right while computer opponent tries to build his own bridge of dashed squares from top to bottom. At each turn players place their respective symbols on the empty squares denoted by dots. Computer starts first by placing his symbol in top left cell.

Here is example of final position won by a computer.

Code and comments


Download the BRIDGE.NSG code or its internationalized version.

You can change size of a game field by changing assignment N=5 in line 1 to something else. Be careful when you do this: line one has just one spare symbol left and it will start truncating symbols from the end of the line if enter too much characters.

Strategy

Gardner's article reveals simple winning strategy for the first player. This porgram implements this simple strategy. In addition, it also enforces the rules and detects when the game is finished. Note that there is no "You win" message.

History

The program was inspired by the following masterpiece from the world of programmable calculator МК-54 (or Б3-34), which implements winning strategy for this game.
00. П→x4   64
01. +      10
02. x→П9   49
03. В↑     0e
04. КП→x9  d9
05. -      11
06. С/П    50
07. БП     51
08. 00     00
(The last 2 byte command, БП 00, is not really necessary and added for convenience).

Then initialize registers to

7 x→П0 x→Пd (also x→Пe for МК-61, МК-52)
10 x→Пb
11 x→П4
12 x→Пc
15 x→П1 x→П2 x→П3 x→Па
The game is played on a field shown in the picture. Possible moves are marked with numbers from 1 to 41. To start game player enters Сx В/О С/П and calculator makes first move (always 1, connecting blue dots). Player then makes his move connecting red dots and enters the number crossed by the line as n С/П, calculator responds, etc. Program does not detect if rules are violated and does not detect end game -- this is left to the player.

I do not know who is the author of this program or where it was published first. BLK showed me this program and he says he learned about it circa 1984-1985. I do not have original copy of the program, so I had to restore it from memory, so constants and register addresses may differ from the original. I will be grateful for information about exact form of the original program, as well as for information where it was first published.


[ MSX BASIC | << Previous | Next >> | Feedback ]