Connect4AI is a Player v Player and Player v AI Connect-4 game, where the aim is to connect 4 pieces of the same color in vertical, horizontal or diagnol line. This game is exclusively developed by:
- Download as .ZIP, extract into a folder.
- Right-click folder, and select 'Open in Terminal'.
- Install Python 3.7 from list of downloads https://www.python.org/downloads/
- Put 'pip install pygame' in terminal and press enter.
- Put 'python3 main.py' in terminal and press enter.
- Enjoy!
- W: Drop piece on column.
- A: Move selector to left.
- S: Move selector to right.
- Q: Quit game.
-
main.py: Main file that calls all other local modules, creates objects of each and runs the game in its chronological order. Also used for debugging by adding -d flag in terminal.
-
ai.py: Base class for AI Implementation of Minimax algorithm to decide what column should the AI drop its piece on. It calculates potential scores of its moves, and selects the column which yields the better score. Above all else, it prioritizes blocking Player's winning move unless it can win before the player. It uses multiple heuristic functions to calculate the scores and chooses the highest one.
-
board.py: Base class for the board, where it declares all sprites/sounds, number of slots, selectors, and consists of functions that initializes, creates, resets, clears, and designs the main board of connect 4. It also consists of functions that allows the player and the AI to place the piece onto a column.
-
menu.py: Base class for the main menu, which consists of sprites, and three different buttons, namely: 'Player v Player', 'Player v AI', and 'Quit.' This class describes use case for each button and activates appropriate function when the buttons are clicked.
-
settings.py: Base class for settings, which just describes two different states of the game, 'Active' and 'Inactive.'
-
slot.py: Base class for slots, which describes alternating turns and their appropriate piece color (red and yellow) and other settings.