Skip to content

A tictactoe CLI game where you play against a computer player with a minimax algorithm implementation.

Notifications You must be signed in to change notification settings

ItsThompson/tictactoe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  _   _      _             _             
 | | (_)    | |           | |            
 | |_ _  ___| |_ __ _  ___| |_ ___   ___ 
 | __| |/ __| __/ _` |/ __| __/ _ \ / _ \
 | |_| | (__| || (_| | (__| || (_) |  __/
  \__|_|\___|\__\__,_|\___|\__\___/ \___|

A tictactoe CLI game where you play against a computer player with a minimax algorithm implementation.

GitHub top language GitHub last commit (branch) GitHub code size in bytes

Introduction

I was inspired to build a tic-tac-toe AI solver from one of the exercise sets for Programming 1 (CM12003) at University of Bath. My main objectives for this project were to deepen my understanding of algorithms for (AI) and gain practical experience in functional programming/Haskell. When researching algorithms, I stumbled across the Minimax algorithm. This algorithm is designed specifically for two-person, perfect information, zero-sum games like Tic-Tac-Toe. By systematically evaluating potential moves, assuming players play the best move and maximize their chance of winning, the Minimax algorithm selects the most advantageous move by considering all possible outcomes.

Showcase

showcase.mov

Build Instructions

Using a Haskell compiler, such as GHC, you can compile the code to a standalone executable. (Source: Haskell Wiki)

ghc -o tictactoe main.hs

Usage

Running in Glasgow Haskell Compiler's interative environment (GHCi)

There are two ways to run the program inside the interative environment. You can call the main function:

$ ghci main.hs
ghci> main

Alternatively you can also call the tictactoe function:

$ ghci main.hs
ghci> tictactoe 

Running the Executable

If you compiled the code into a executable, you can directly run the executable (./tictactoe on Unix systems, tictactoe.exe on Windows).

$ ./tictactoe

Reflection

There are definetly better and more efficient ways of approaching this question. For example, during the problem lecture, Professor Willem Heijltjes explained the optimal move can be determined by simply checking if you are currently winning and if the opponent has no winning move. With this method, assuming optimal play, it will always result in a draw. However, the advantage of a Minimax algorithm is the notion of how it can expand to other zero-sum games such as Chess, Monopoly, and even card games.

Further Investigations

It would be interesting to explore a Minimax implementation for different cardgames such as poker or blackjack because the winstate is more complicated than tic-tac-toe.

About

A tictactoe CLI game where you play against a computer player with a minimax algorithm implementation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published