1.13  Pousse Tic-Tac-Toe-like Game

To play Pousse, run the PLT Games program. (Under Unix, it’s called plt-games).

Pousse (French for “push,” pronounced “poo-ss”) is a 2 person game, played on an N by N board (usually 4 by 4). 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


   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 are named Li, Ri, Ti, and Bi respectively, where i is the number of the row or column where the insertion takes place.

When a marker is inserted, there may be a marker on the square where the insertion takes place. In this case, all markers on the insertion row or column from the insertion square up to the first empty square are moved one square further to make room for the inserted marker. Note that the last marker of the row or column will be pushed off the board (and must be removed from play) if there are no empty squares on the insertion row or column.

A row or a column is a straight of a given color if it contains N markers of the given color.

The game ends either when an insertion

A game always leads to a win by one of the two players. Draws are impossible.

This game is from the 1998 ICFP programming contest.