Connect 4 in Prolog



Prolog implementation of a connection game known as Connect Four and Four In A Row.

Source code: conn4.pl

Try it for example with SWI-Prolog:
      $ swipl conn4.pl

      ?- play.
    
Example outputs: conn4_1.txt, conn4_2.txt

Ties between equally good moves are broken randomly, thus games typically differ from run to run.

If you have a PostScript viewer (like "gs") installed, you can also use a graphical and interactive version, with:
      ?- show.
    
At any turn, you can either press SPACE to let the computer choose a move, or press one of the numbers 1, 2, ..., 7 to drop a piece in that column.

Sample states of a game:
Game



Main page