Skip to content

chaerla/adversarial-adjacency-strategy-game-bot

Repository files navigation

Adversarial Adjacency-Strategy-Game


Introduction

The “Adjacency” program was designed as an interactive and strategic board game that is played between two players. Using X’s and O’s on an 8x8 board outputted on a computer screen, the objective of the game is for a player to get more X’s than O’s in total or vice versa after a specific number of rounds.

The initial game starts with 4 X’s in the bottom left corner and 4 O’s in the top right corner. The first player will begin by placing an X on an empty square (through clicking). In turn, all O’s that are on adjacent squares are then replaced with X’s. Play will continue with the second player taking his turn by placing an O on an empty square. In turn, all X’s that are on adjacent squares are then replaced with O’s.

This is an extended version of the game where the games has Bots implemented to play the game. On game initialization, the user can choose either Bot or Human as player X and player O. The game has 2 three types of Bot implemented:

Minimax Bot

This bot implements the minimax algorithm with alpha-beta pruning. It iterates all possible moves until it reaches a maximum depth defined in the app. This bot works by assuming that the opponent works optimally as well.

Local Search Bot

This bot implements a local search algorithm, simulated annealing to find the best move. It works by randomizing possible paths taken by player and both then chooses the best one by taking the instantaneous benefit and feature benefit (based on objective function) into consideration.

Genetic Algorithm Bot

This bot implements genetic algorithm to find the best solution.


Installation (IntelliJ)

To get started, please install the latest version of the Java Development Kit (JDK) and please install a Java IDE such as IntelliJ. Please note that the deployment instructions below use IntelliJ as the IDE.


Deployment (IntelliJ)

  1. Clone the repository through Git by running the following command:
    git clone https://github.com/GAIB20/adversarial-adjacency-strategy-game.git, or simply download the repository.
  2. Open the repository folder through IntelliJ.
  3. Set up the JDK by going to File -> Project Structure -> Project tab. In the Project tab, go to Project SDK, click New, and browse to the location of your JDK folder.
  4. NOTE: JavaFX has been removed starting from JDK 11, and it is now a standalone module. The JavaFX files needed to set up the Adjacency program are located in the repository folder itself. To set it up, go to File -> Project Structure -> Libraries tab. In the Libraries tab, press the + button, browse to the "javafx-sdk/lib" folder in the repository, and add it to the list of libraries.
  5. IMPORTANT: Go to Run -> Edit Configurations, and go to the VM options. In this line, please add in the full path to the lib folder of the javafx-sdk folder on your own computer, and then add the following line
    --add-modules=javafx.controls,javafx.fxml.

    For example, I added the following line to my VM options: --module-path "C:\Jed's Work\CS Side Projects\Adjacency-Strategy-Game\javafx-sdk\lib" --add-modules=javafx.controls,javafx.fxml
  6. Open the Main class in the IntelliJ file interface.

Deployment (Linux / WSL Windows 11 without IntelliJ)

Seharusnya bisa untuk windows non wsl jg (untested), dengan cara skip poin 2, dan ubah semua / di command jadi \

  1. Make sure you have JDK 11 installed
  2. Clone the repo and cd to the folder
git clone https://github.com/GAIB20/adversarial-adjacency-strategy-game.git
cd adversarial-adjacency-strategy-game
  1. Download JavaFX linux version
wget https://download2.gluonhq.com/openjfx/11.0.2/openjfx-11.0.2_linux-x64_bin-sdk.zip
unzip openjfx-11.0.2_linux-x64_bin-sdk.zip
mv javafx-sdk-11.0.2 javafx-sdk-linux
  1. Compile the program
javac -cp ./src --module-path "./javafx-sdk-linux/lib" --add-modules=javafx.controls,javafx.fxml src/*.java
  1. Run the program
java -cp ./src --module-path "./javafx-sdk-linux/lib" --add-modules=javafx.controls,javafx.fxml Main

Program Instructions

  1. Run the Main class to load the program, and the input window below will pop up. Input the names of Player (X) and Bot (O) into their respective text fields. Then, select the number of rounds (a number between 2 and 28) to play using the dropdown menu. You can select whether each player is bot or human and you can also choose the player that goes first.

    image

  2. Click Play, and the gameboard and scoreboard window will load. The first player starts the game by clicking on an empty button. If it is a Bot, it will calculate the best move and the result will be reflected in the game. Any adjacent O’s will change to X's as a result.
  3. Then, Player (O) has their turn by also clicking on an empty button. Any adjacent X’s will change to O's as a result. NOTE: This process is counted as 1 round (Player X and O both taking their turns).
  4. The game will continue until there are no more rounds left to play. In the end, the player with the greater number of letters is the winner of the game.

Experiment With Bots

Human vs Minimax Bot

image

Human vs Simulated Annealing Bot

image

Human vs GA Bot

MinimaxBot vs Simulated Annealing Bot

image

GA Bot vs Minimax Bot

GA Bot vs Simulated Annealing Bot

Bot Authors

  1. Rachel Gabriela Chen 13521044
  2. Jeffrey Chow 13521046
  3. Angela Livia Arumsari 13521094
  4. Rinaldy Adin 13521134

Notes

  • Built with JavaFX
  • Modified by ITB Graphics and AI Lab Assistant 2020

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •