ZOJ Problem Set - 1840
Recently, the organizers of the International Conference on Functional Programming had a programming contest for people to show that their language was best. The contest main web page is at http://www.ai.mit.edu/extra/icfp-contest/. Each entrant had to write an implementation of the game "pouse", for which the description went as follows:
Description of the game
The name of the game is "pousse" (which is French for "push").
It is a 2 person game, played on an N by N board (the original game was 4x4
but NxN is a simple generalisation to adjust the difficulty of the game, and
its implementation). Initially the board is empty, and the players take turns
inserting one marker of their color (X or O) on the board. The color X always
goes first. The columns and rows are numbered from 1 to N, starting from the
top left, as in:
1 2 3 4
A marker can only be inserted on the board by sliding it onto a particular
row from the left or from the right, or onto a particular column from the top
or from the bottom. So there are 4*N possible "moves" (ways to insert
a marker). They will be named "Li", "Ri", "Ti",
"Bi" respectively, where "i" is the number of the row or
column where the insertion takes place.
A row or a column is a "straight" of a given color, if it contains N markers of the given color.
The game ends when an insertion creates a configuration with more straights of one color than straights of the other color; the player whose color is dominant (in number of straights) WINS.
Process to the end of file.
Source: University of Waterloo Local Contest 1998.10.04