CPythonist

Tic-Tac-Toe Player vs Computer Program

Tic-tac-toe, noughts and crosses or Xs and Os is a paper-and-pencil game for two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. It is a solved game, with a forced draw assuming best play from both players.

This program is a player vs computer version of tic-tac-toe. Written in the Python programming language (Python 3.9). This program does not use the most efficient algorithm used for tic-tac-toe computer programs (i.e., the minimax algorithm). This program prioritises free corners over the centre, and the centre over the edges. If more than one favorable spaces are present (for example, three corners), then the program decides randomly for which corner to be filled. This leads to the unfavorable outcomes in the result of the game (from the perspective of the computer). This program was developed by me during my early stages of learning Python and computer science in general, so inefficient algorithm has been used, and the program is extremely buggy when playing as 'O'.

Download the source code

OR

View the source code