Git Product home page Git Product logo

checkers-ai's Introduction

Checkers AI for ECE469

Caleb Zulawski

Requirements

This software was developed with gcc 4.9.2+ and make on Linux and Windows (using Cygwin). Other C++11 compatible compilers and older versions of gcc may work but no guarantees. Building in the Cygwin environment requires the mingw-pthreads package. To play the game, you must be using a terminal emulator that supports ANSI color codes.

Installing and running

To build and run:

git clone https://github.com/calebzulawski/checkers-ai.git
cd checkers-ai
make
./checkers-ai

To load a board state:

./checkers-ai /path/to/board/file

Implementation details

Board representation

The board is represented as a 32-bit bitboard. This allows efficient access and copy mechanisms. This also allows the use of the hamming distance (set bit count) functions on many processor architectures.

AI

Search algorithm

The AI uses iterative deepening with alpha-beta pruning. The search deepens by 2 every turn, which seems to provide slightly deeper searches, on average, than deepening by 1. If the entire tree is explored, the iterative deepening will end. To time the iterative deepening algorithm, a second thread is spawned that keeps track of the current time, ending the search early if the time reaches within 100ms of the maximum search time.

Heuristic function

The value of a board state is evaluated as a signed integer, with a higher value indicating a winning board. The heuristic function contains several separate functions that evaluate the board state. These functions are then weighted by importance: heuristic function

h0 counts the number of the maximizing player's pawns minus the number of the opponent's pawns, and multiplies this by 3. It then adds the number of the maximizing player's kings minus the number of the opponent's kings, multiplied by 5.

h1 is the number of the maximizing player's total pieces minus the opponent's total number of pieces. This allows the AI to make more favorable trades when winning.

h2 returns 0 if both players have more than 3 pieces. Otherwise, it returns a higher value if the maximizing player's pieces are in near the double corners, and low if the opponent's pieces are there. This is intended to help edge out a player holding the double corner.

h3 promotes board advancement by returning the sum of the distance of the maximizing player's pieces to the other end of the board, minus the opponent's sum. It also promotes keeping the back row occupied by weighing that higher.

r is a random value between 0 and 99, preventing the AI from making deterministic decisions in the case of ties.

checkers-ai's People

Contributors

calebzulawski avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.