Code Monkey home page Code Monkey logo

minimax-prolog's Introduction

minimax-prolog

A simple minimax implementation in SWI Prolog for Tic Tac Toe. There is also a ui client to play against this implementation under https://github.com/jaunerc/tictactoe_client

Minimax

The minimax algorithm can be used for several games to implement a computer opponent. The file minimax.pl contributes a predicate minimax/2. Which chooses the next best move to play by a given tic tac toe board. Notice this implementation is pretty basic. It should choose the best possible move.

By example the following statement matches NextMove with the chosen move for the given board.

minimax([n,n,o,n,n,n,n,n,n], NextMove).

The board is a one dimensional list that represents a tic tac toe situation. The atom n stands for an empty field.

0 | 1 | 2
3 | 4 | 5
6 | 7 | 8

REST backend

This repo also contains a simple REST backend. It uses only SWI Prolog standard modules. If you send a tic tac toe board you will receive a response with the computers move.

Usage

Starts the server on port 8080.

?- rest_server(8080).

Access the running server with a http POST request on localhost:8080/minimax with a tic tac toe board as JSON value.

Request JSON:
{ "board":["o","n","n","n","n","n","n","n","n"]}

You should get a response in the same form.

Response JSON:
{"board": ["o","n","n","n","x","n","n","n","n"]}

minimax-prolog's People

Contributors

jaunerc avatar

Watchers

Tadeusz Kurpiel 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.