Giter Site home page Giter Site logo

pchampio / othello-prolog Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 5.0 1.46 MB

:scroll: A fully functional Othello (Reversi) game, with several AIs, made in prolog for swipl.

License: BSD 3-Clause "New" or "Revised" License

Prolog 100.00%
prolog logic-programming board-game student-project othello-game swipl alpha-beta minmax artificial-intelligence univ-lemans

othello-prolog's Introduction

Othello Prolog

A fully functional Othello game, with several AIs, made for the swi prolog interpreter

ScreenShot~ demo

Overview

This app allows 2 players to play an Othello game.

During de pre-game menu the admin can set the two players to human or AIs.

-- Set the Player x to be a --
 1. Human  ---> User input. prompt.pl
 2. Bot (random)   ---> A totally random AI. random.pl 
 3. Bot (minmax)   ---> An AI using the min-max algorithm. minmax.pl
 4. Bot (alphabeta) ---> An AI using the alpha-beta algorithm. alphabeta.pl  

Usage

Play

Load the file in the swipl-interpreter:

$ swipl ./othello.pl

Play the game:

>?- play.

Things about this implementation

Heuristic/Evaluation function

I used this excellent heuristic/evaluation function, made by researchers from the University of Washington.

This heuristic function is actually a collection of several heuristics and calculates the utility value of a board position by assigning different weights to those heuristics here.

The heuristic takes into account:

  • The coin parity here
  • The mobility here
  • The corners captured here
  • The stability here

Performances

To ensure the best performance and to improve the bot playing time the Game Engine use a cache.pl system.

The Cache saves the Heuristic value of a given board. here.

This method saves (roughly):

  • 20000 call out of 36000 when running a AlphaBeta of Depth 4 (-1min30 save on my machine 2min10 vs 3min40).
  • 66000 call out of 77000 when running a MinMax of Depth 4 (-9min save on my machine 11min vs 20min).

The Cache is also used to save some computing time of the next board generation witch in his own cut the number of call to this rule by half (20 seconds save).

MinMax Vs AlphaBeta (depth = 3)

MinMax vs AlphaBeta

Note that the overall trend in counts analyzed by Min-Max increases in the first third following a Gaussian strongly pronounced. This is because the board is free, and many combinations are allowed. In the next 2 thirds, the descent is also done according to the distribution of gauss, since the number of game combinations decreases gradually as we reach the edges.

In depth 6 we have 3.8 million board analyzed, to play an obvious shot find in depth 2.
Evidence appears: Alpha-Beta is still not the reincarnation of pure optimization ...

Note

I always write the test of the rule/predicate, below and indented by 3 tabs of the definition of itself.

Todo

 1. +/-inf heuristic when wining/losing. (some plays are more rewards than a winning one..)

 2. Dynamic stability_weights - The stability_weights penalize the player making a move on a adjacent corners cell. But if the same player own the related corner it's actualy not a bad move..

 3. Dynamic weights in the dynamic_heuristic_evaluation

     - At the start we need to reduce the opponent mobility
     - In the middle game we need to focus on the stability of your placement
     - In the very end of the game we only focus on the coin parity

 4. Remove the ugly if/then/else

 5. Make use of board symmetrys to improve the Cache systems

 6. GnuProlog (2x faster)

othello-prolog's People

Contributors

pchampio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.