Skip to content

rsoylu/tictactoe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Tic Tac Toe

This is an implementation of the classic tic tac toe game in Python. The game can be played on the command line. Instructions for how to play are written below.

The computer side for the tic tac toe game uses the minimax algorithm to calculate the next best move. The pseudocode used to do this is below.

image

Additionally, I have implemented the tic tac toe game using alpha beta pruning, with the following pseudocode.
image

How it works

To run the program, you must use the command line. The program accepts 3 command line arguments, so the code can be executed with
python cs480_P01_AXXXXXXXX.py ALGO FIRST MODE
where:
■ cs480_P01_AXXXXXXXX.py is your python code file name,
■ ALGO specifies which algorithm the computer player will use:
◆ 1 – MiniMax,
◆ 2 – MiniMax with alpha-beta pruning,
■ FIRST specifies who begins the game:
◆ X
◆ O
■ MODE is mode in which your program should operate:
◆ 1 – human (X) versus computer (O),
◆ 2 – computer (X) versus computer (O)

Example:
python cs480_P01_A11111111.py 2 X 1

The above command will run the program with the minimax alpha beta pruning algorithm where the player who begins the game is X and the mode is human versus computer.

If the number of arguments provided is NOT three (none, one, two or more than three) or arguments are invalid (incorrect ALGO, FIRST or MODE) the program displays the following error: ERROR: Not enough/too many/illegal input arguments. and exits.

Program Details

■ The Tic-Tac-Toe game board is represented by 3 x 3 grid with cells numbered as follows
image

■ Possible moves/actions for both players match cell numbers (if a player wants to place an ‘X’ in the middle of the board, the move/action is ‘5’,

Example Game

image
image

About

A tic tac toe game.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages