Git Product home page Git Product logo

command-line-checkers's Introduction

OCaml Checkers with AI

Summary

The vision for this project was to implement a terminal-based version of checkers with two game modes:

  • A 1v1 showdown with two human players battling to capture all of the opponent's pieces.
  • A single-player mode where the player battles an AI with three difficulty levels (easy, medium, and hard).

The game is user-friendly for beginner checkers players, with an option to take hints. The hint feature suggests the best move from the current board layout.

Functionality

There are three AI difficulty levels for the single-player mode:

  • Easy AI: Always moves the first available piece with its first available move (unless there is a capture available).
  • Medium AI: Chooses random moves from those available.
  • Hard AI: Uses a Minimax game tree to find the best possible move, evaluated with a fine-tuned point system. The best move is calculated by looking at all possible moves available to the AI (depth in tree = 1) and then all possible opponent moves in response (depth in tree = 2).

AI Move Evaluation

The resulting positions of the AI pieces after each potential opponent response are evaluated with a point system that:

  • Weighs king pieces more heavily than pawns.
  • Assigns more weight to pieces with stronger positions, depending on the stage of the game.
  • Evaluates position strength based on criteria like moving pawns to the opposite end of the board, to the edges, keeping pawns in the back row, making captures, avoiding captures, and coordinating kings.

Rules Adherence

All AI levels follow all the rules of the game, including capturing when available and performing multi-captures if possible. The AI does not make invalid moves. The hint command uses the same algorithm as the hard AI to highlight the best moves for the player.

Getting started

Install depedencies with

opam install ounit ANSITerminal

To begin the game, use

make play

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.