#30 Four in a Row

In this classic tile-dropping board game for two players, you must try to get four of your tiles in a row horizontally, vertically, or diagonally, while preventing your opponent from doing the same. This program is similar to Connect Four.

The Program in Action

When you run fourinarow.py, the output will look like this:

Four in a Row, by Al Sweigart al@inventwithpython.com
--snip--
     1234567
    +-------+
    |.......|
    |.......|
    |.......|
    |.......|
    |.......|
    |.......|
    +-------+
Player X, enter a column or QUIT:
> 3 1234567 +-------+ |.......| |.......| |.......| |.......| |.......| |..X....| +-------+ Player O, enter a column or ...

Get The Big Book of Small Python Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.