Javascript Artificial Intelligence Tutorial – For beginners

Here is a simple JavaScript Artificial Intelligence Tutorial for beginners using the reinforced learning method. You need to have basic knowledge on HTML, CSS and JavaScript, as well as programming basics.

This tutorial is a starting point for people who want to implement A.I. in their projects. You are free to “steal” ideas and techniques from this 🙂

In this tutorial we will create a car with an A.I. driver, which will drive along a road avoiding obstacles. The avoiding will be made by the A.I. and not by direct programming (like using IF-statements).

There are multiple ways to achieve this, but this is just my take on it, and you should research other people’s versions too and their solutions for a Javascript Artificial Intelligence Tutorial.

Thank you for your interest in this, let’s start!

Code at jsfiddle: https://jsfiddle.net/niandrei/durho073/

Part two:

Code at jsfiddle: https://jsfiddle.net/niandrei/6gn7m7uu/9/

In this second part we’ll create some functions which will move the wall towards the car.

Part three:

Code at jsfiddle: https://jsfiddle.net/niandrei/6gn7m7uu/13/

In this third part we’ll create some functions which will move the car down when one of its sensors collides with the moving wall.

Part four:

Code at jsfiddle: https://jsfiddle.net/niandrei/6gn7m7uu/21/

In this fourth part we’ll improve the collision detection and move the debug area, and also add some new things to it.

Part five:

Code at jsfiddle: https://jsfiddle.net/niandrei/6gn7m7uu/27/

In this fifth part we’ll split the road into two imaginary zones, and construct a ‘database’ that will hold all the possible positions the A.I. and the wall can have in those two zones.

Part six:

Code at jsfiddle: https://jsfiddle.net/niandrei/6gn7m7uu/33/

In this sixth part we’ll finish by making the AI avoid the wall by using its experience.

Project at github: https://github.com/NiscoveanuAndreiPFA/JavaScript_AI_ReinforcedLearning

Also, you can check out my book about AI with JavaScript examples.

Share this info with your audience:
Was this helpful?

8 thoughts on “Javascript Artificial Intelligence Tutorial – For beginners

  1. Hi, I just finished watching your tutorials, I copied your code on Sublime Text 3 and opened in chrome and it didn’t work: there are this error messages “Uncaught TypeError: Cannot read property ‘offsetLeft’ of null at moveWall at tick” when I click the start button and “Uncaught TypeError: Cannot read property ‘style’ of null at runSim” when I click the stop button. I don’t know why it doesn’t work, I’ll be very thankful if you reply and explain to me how to fix the program.

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.