A Monte Carlo AI for Connect4 written in Python.
This project was tested in Python 3.8 and should work with any Python 3 install.
python Connect4.py
will run a simulated game AI vs AI.
--singleplayer
lets you play against the AI.
--multiplayer
lets you play against a friend (or yourself if you dont have any :().
--norush
will let the AI take its time, hey we aren't in a rush here!
--rush
will make the AI rush its simulations if simulations are not proving favorable. This is on by default.
--pretty
will allow you to live in the world of color TV. Makes use of Colorama
--clearable
makes the console clear itself when the board redraws.
--first
and --second
lets you choose if you go first or not in singleplayer mode. This defaults to first.
--easy
,--medium
,--hard
,--insane
,--master
,--demigod
, --god
are difficulty options, see if you can beat them all! However after insane the computer takes forever to move depending on your CPU single threaded performance.
BOARD_WIDTH
, BOARD_HEIGHT
, and AI_STRENGTH
can all be easily changed, just put in any non-zero positve integer.
BOARD_WIDTH
is the width of the game board.
BOARD_HEIGHT
is the height of the game board.
AI_STRENGTH
is how many simulations the AI runs on each of the possible moves.
Multithreading/Multiprocessing - run all 7 possible move simulations in parallel. Might not make sense considering the GIL.
Numpy - find a way to speed up calculations using numpy, or by using things other than expensive python objects.
Inspired by https://github.com/antirez/connect4-montecarlo. Antirez did a great job writing his version in C. C is nice, however Python is the language of the gods.