reversi_game


reversi_game, a Python code which sets up an interactive match of the game reversi (also called Othello) between the computer and a player, using text-based graphics.

The computer uses a greedy strategy to choose its move against the player. It makes a catalog of all possible moves it can make. If any move takes a corner, that move is chosen. Otherwise, it chooses the move which flips the maximum number of player pieces.

The game always begins with four pieces arranged in the center. The program randomly chooses whether the player or computer goes first. Normally, play will continue until all 64 squares have been filled. If the player or computer cannot make a move, their turn is skipped. If neither can make a move, the game terminates early. The winner is the one who has the most number of pieces showing.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

reversi_game is available in a MATLAB version and a Python version.

Related Data and Programs:

lights_out_game, a Python code which sets up the Lights Out game, lighting up a few squares on a grid. An interactive user must then try to press squares in such a way that all the lights are turned off.

spelling_bee_game, a Python code which handles the Spelling-Bee puzzle popularized in the New York Times, in which one must make as many words as possible from a given set of seven letters. The first letter must appear in each word, while the other letters may be omitted or repeated. All words must be at least 4 letters long. The code is by Christian Hill.

Reference:

  1. Al Sweigart,
    Invent your own computer games with Python,
    4th Edition, 2017,
    No Starch Press,
    ISBN13: 978-1-59327-795-4
    LC: QA76.76.C672

Source Code:


Last revised on 23 June 2025.