Code Monkey home page Code Monkey logo

ai_connect4's Introduction

Simple AI Connect 4

This is a simple JavaScript implementation of a reinforcement algorithm which simply weights states 'visited' in order to win, and reduces weights visited on a loss. Draw has no effect.

The permutations of options are in the billions for a full board, so the board can be set to smaller (4x4 is the smallest possible).

How clever are the players after 2000 iterations?

Not very.

The permutations are still pretty large, so it hasn't seen the same conditions sufficiently to make a judgement to lower or increase weights.

This is not very fast, and doesn't have any hashing of the board to consider similar states such as a mirror image or shifted left/right.

How can I see it in action?

You can view this in this repository GitHub Pages.

The JS will run 2000 iterations and then show the moves the players are making for each run from there.

Additional Models

There is an second model added, which uses the surrounding neighbors as a view of state which will reduce the states and attempts to do some simplistic model which will allow same shapes to match in different positions.

The third model is a rough TensorFlow.js implementation. This doesn't do reinforcement, and just simply provides the grid input. This is trained with 500 totally random plays, and the training data is just the last state of the board with the winning move.

Bugs

There is some bug somewhere which allows a play a non-existent column on the far right (or possible a negative one on the left) which crops up, but I can't find what it is. That's what I get for not writing any tests for this.

Why?

Why not?

This was inspired by the 2019 Royal Institution Christmas Lectures which had a match-box powered Noughts and Crosses player which used the same algorithm (but used coloured beads for moves, rather than an array of columns as I have).

ai_connect4's People

Contributors

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