The program is a digital version of the classic Connect 4 game. The game is played on a 6x7 grid, where two players, the user and an AI will take turns dropping white and black discs respectively into the grid. The goal of the game is to connect four discs of the same color vertically, horizontally, or diagonally. The AI uses the minimax algorithm with alpha-beta pruning to determine the best move.
When the game starts, the user is presented with a blank grid. The user can click on a column to drop a disc into that column. The program checks if the move is valid (i.e., the column is not full), and then updates the grid with the new disc. The program then checks if the move resulted in a win or a draw. If neither, the program switches to the other player's turn.
The AI uses the minimax algorithm with alpha-beta pruning to determine the best move. The AI will look ahead in depth of 4 moves recursively. The AI will then choose the move that results in the highest score. The score will prioritize winning moves in fewer moves, and losing moves in more moves.
The AI will also use alpha-beta pruning to reduce the number of nodes that need to be evaluated. Alpha-beta pruning will reduce the number of nodes that are bad moves by either the AI or the user. This will make the AI more efficient and faster.
This repository uses CI/CD to automatically build and release the program for Windows, macOS, and Linux. The program is packaged as a JAR file. The JAR file is then packaged into an EXE file for Windows, a DMG file for macOS, and a DEB file for Linux. The program is built using GitHub Actions and is released using GitHub Releases. The program is built for the following platforms:
- Windows (64-bit)
- macOS (64-bit)
- Linux (64-bit)
- JAR File
You can find them here in the Releases section.
- Open the terminal and navigate to the directory where you downloaded the .deb file.
cd ~/Downloads
- Run the following command to install the package:
sudo dpkg -i ./connect4-v1.1.0-linux_amd64.deb # Replace the filename/version with the name of the DEB file you downloaded
- If you get an error, run the following command to install the dependencies:
sudo apt-get install -f
- Run the following command to start the game:
You can start the game by searching for it in the applications menu named connect4
or by running the following command in the terminal:
/opt/connect4/bin/connect4
-
Installing Java (if it's not already installed):
sudo apt update sudo apt install default-jre
-
Navigate to the Download Location:
cd ~/Downloads
-
Provide Execute Permissions (Optional, but useful if you want to execute it directly):
chmod +x connect4-1.0.0.jar # Replace the filename with the name of the JAR file you downloaded
-
Run the JAR File:
java -jar connect4-1.0.0.jar # Replace the filename with the name of the JAR file you downloaded
There are 2 methods. Downloading the dmg file or downloading the jar file.
I am not a registered Apple developer, That is why you will get a warning when you try to open the app. Thus, you will have to bypass the security settings to run the app. Here are the steps:
-
Click on the .dmg file you have downloaded.
-
Drag the app to the Applications folder.
-
In the Finder on your Mac, locate the Connect4 app.
(Don’t use Launchpad to do this. Launchpad doesn’t allow you to access the shortcut menu.)
-
Press and hold Control then click the app icon.
-
Click Open.
The app is saved as an exception to your security settings, and you can open it in the future by double-clicking it just as you can any registered app.
Make sure you have JRE installed on your computer. You can download JRE here or here.
-
Navigate to the Download Location (using Terminal):
cd ~/Downloads
-
Provide Execute Permissions (Optional):
chmod +x connect4-1.0.0.jar # Replace the filename with the name of the JAR file you downloaded
-
Run the JAR File:
java -jar connect4-1.0.0.jar # Replace the filename with the name of the JAR file you downloaded
- Open the folder where you downloaded the EXE file.
- Double-click on the EXE file to run it.
At this point, the Windows smart screen will block the app from running. As I am not a signed developer by Microsoft, this warning will appear.
- If you get the warning, click on "More Info" and then click on "Run Anyway".
- Wait for the installation to complete.
- Run the game from the Desktop shortcut.
-
Confirming Java:
Make sure you have JRE installed on your computer. You can download JRE here or here.
Ensure that Java is added to your
PATH
so that it can be accessed from the command prompt. During the JRE installation, You will have the option to add to your path. It is unchecked by default. Make sure to enable it. To check if Java is installed, run the following command in Command Prompt or PowerShell:java -version
If Java is installed, you should see the version number. If you see an error, you need to install Java. See above for instructions on installing Java.
-
Navigate to the Download Location (using Command Prompt or PowerShell):
cd c:\Users\username\Downloads # Replace username with your username
-
Run the JAR File:
java -jar connect4-1.0.0.jar
In all cases, once the commands are followed, the Java application packaged inside the JAR file should start running.
The game is written in Java and can be compiled using the following steps:
- Go to the root directory
- Run the command
javac -d bin src/*.java
to compile the Java file. - Run the command
java -cp bin/ App
to run the game.
I have not found any bugs in the program yet. If you find any, please let me know by opening an issue from here