Git Product home page Git Product logo

haresmahmood / gomoku-sensei Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 1.87 MB

A Monte Carlo Tree Search-based AI which dynamically adjusts its difficulty to that of its opponent.

Home Page: https://haresmahmood.github.io/gomoku-sensei/

HTML 15.42% JavaScript 28.54% CSS 19.22% TypeScript 36.81%
ai monte-carlo-tree-search pwa typescript dynamic-difficulty-adjustment game gomoku machine-learning

gomoku-sensei's Introduction

Gomoku Sensei AI

Designing a dynamic game-playing AI.

GitHub code size in bytes PWA Shields Figma Notion

Screenshot

Table of Contents
  1. Overview
    1. Aims & objectives
    2. Gomoku
  2. Development
    1. Codebase structure
    2. Installation
    3. Compilation
    4. Compilation
    5. Unit testing
  3. Resources
  4. Acknowledgements
    1. Frameworks & technologies

Overview

This software was developed as a fourth-year dissertation project for the University of Strathclyde.

Abstract

Artificially intelligent (AI) agents in games can be surprisingly unintelligent. Particularly in board games, players are often faced a range of AI opponents represented by convoluted difficulty selectors. Creating custom AI opponents not only results in extra work for the developers, but also impairs the player’s enjoyment of the game. Mismatches in the skill level of players can results in either player growing frustrated or becoming bored. Current dynamic difficulty adjustment (DDA) techniques rely on game-specific evaluations, restricting their application to the game industry at large.

This project introduces a new DDA technique, prolongation bias, whereby the Monte Carlo Tree Search algorithm is adapted to prioritise game elongation. Experiments carried out with a sample size of 81 participants show the AI utilising the prolongation bias technique can dynamically adapt its difficulty to players with a range of skill levels and increase the human player’s enjoyment and satisfaction of matches against computer-controlled opponents.

Gomoku

In order to test the AI, a two-player abstract board game had to be chosen. Gomoku, also known as Five in a Row, was picked as the best candidate out of various board games. Details about this decision can be found here.

The fofmat of the game are simple: two players take turns placing black and white tokens on a board whilst trying to chain these pieces five in a row, either horizontally, vertically or diagonally. Gomoku can be classified as an m, n, k-game. During the process of development, it was found that "pure" Monte Carlo Tree Search performs poorly on a traditional 15 by 15 Gomoku-board. Instead, a 7 by 7 board was used for the purposes of this research.

Development

Codebase structure

.
├── dist                      · JavaScript compiled from TypeScript. Mirrors \src\ts\.
├── res                       · Resources, such as images and icons.
├── test                      · Mocha Unit tests for JavaScript files in \dist\.
└── src                       · The website's source code.
    ├── css                      · Styling for all HTML pages, organized from high- to low-level.
    ├── html                     · All HTML pages, both high- and low-level.
    └── ts                       · Logic and back-end of the software.
        ├── controller              · Controllers connecting models and views, MVC design pattern.
        ├── factory                 · Classes following the factory method design pattern.
        ├── model                   · Part of the MVC. In practice, defines games as a Markov decision process.
        ├── player                  · Defines a hierarchy of player-classes, including various AI players.
        ├── script                  · Files referenced directly by HTML pages. Instantiates MVC classes.
        ├── utility                 · Common utility classes used extensively in other parts of the system.
        └── view                    · Part of MVC. Utilises JQuery to manipulate the DOM.

Installation

Please refer to instructions on setting up a local test server if you wish to host and run the project locally. Alternatively, visit the web application hosted on GitHub Pages to run the software on any modern browser, as well as to install it as a Progressive Web App (PWA).

Compilation

The code located in the \dist\ directory is JavaScript (JS), compiled from TypeScript located in \src/ts\. TypeScript (TS) is a strongly-typed language, also allowing for additional object oriented features to be used on top of what JS already used. If making any changes to the TS code, any changed files must be re-compiled. Please refer to the official TypeScript page for instructions on downloading, running and using TS.

For this project, v4.6.2 of TS was used. To compile modified JS files, run the following command in the root directory of the project:

tsc build

Unit testing

Mocha and Chai for testing, two open-source JS unit testing frameworks. Testing was focused on the Model (i.e., the game) and related classes. To simplify the process, tests were written for and run on compiled JS, as opposed to the source TypeScript files. Unit tests are located in the \test\ directory.

Node.js must be installed before unit tests can be executed (v14.18.1 is used in this project). Assuming this is the case, and you're located in the project's root folder, the following commands will both install dependencies in the package.json for this project, and run all unit tests:

npm install
npm test

Resources

  • For additional details, as well as the development process for this project, visit this Notion Workspace. The paper written as part of this project can be read here. The UI was designed in Figma; an interactive prorotype can be found at this page.

Acknowledgements

I want to thank Dr. John Levine for supervising, and providing his invaluable support and guidance troughout this project.

Frameworks & technologies

Resource Usage
Material Design 3 Guidelines for the design and creation of the UI.
TypeScript Back-end of system, particularly the model (the game) and the several AI agents.
JQuery UI animations, particularly navigating from page-to-page.
PWA technology Making the app installable on multiple platforms. The PWA Builder extension for VS Code was used in particular.
GitHub Pages Hosting the web app.
Mocha and Chai Unit testing.
TypeDoc Exporting documentation to HTML.
Zapsplat In-game sound-effects.

gomoku-sensei's People

Contributors

haresmahmood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

vlaskk

gomoku-sensei's Issues

25/2 User Experience

The page directly navigates to the game, skipping the homepage. This somehow results in the game not working correctly. Refreshing lands the user on the same page.

Navigating forward in history

Overview

When navigating to the Game-page from the Home-page by going forward in history, the Game-page's UI doesn't fully load.

Reproduction steps

  1. From the Home-page, navigate to the Game-page.
    • Both player select-components must be populated before being able to continue to the Game-page.
  2. From the Game-page, navigate to the Home-page by either:
    • Pressing the browser's back button.
    • Utilizing your OS-specific back gesture.
  3. From the Home-page, navigate to the Game-page by pressing the browser's foward button.

Logs

127.0.0.1-1645203549437.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.