Jump to content

learning to write a Javascript chess game


raenset
 Share

Recommended Posts

I would like to find a good tutorial for a Javascript chess engine. I mean, one where you play against the AI, not the chess board in which two human players can log in and play together (although the latter is of some interest to me, too).

I know that a chess engine can quickly become a very complicated matter, but what do you think that the best tutorials are on the web to start learning how to write one? This, limited to HTML5 / Javascript.

Link to comment
Share on other sites

I would like to find a good tutorial for a Javascript chess engine. I mean, one where you play against the AI, not the chess board in which two human players can log in and play together (although the latter is of some interest to me, too).

I know that a chess engine can quickly become a very complicated matter, but what do you think that the best tutorials are on the web to start learning how to write one? This, limited to HTML5 / Javascript.

 

i have no idea about tutorials. but you can try stockfish for your purpose!

 

Stockfish is one of the strongest chess engines!

 

someone ported in to javascript here: https://github.com/exoticorn/stockfish-js

Link to comment
Share on other sites

Thank you for the link, but what I need for the time being is some sort of primer on how to teach the computer the rules of chess, and how to make it play... just getting an idea of the "big picture", so that I can go into details later.  

 

Of course I can try it myself, from zero, using my brain, without any tutorial, but a "getting started" sort of tutorial would be very useful... 

Link to comment
Share on other sites

  • 1 month later...

You might want to look into the "min-max" algorithm and it's more complicated optimization "alpha-beta" algorithm.

 

Chess is a so called "zero-sum game". Other examples would be the nim-game, tic-tac-toe, and 4-in-a-row.

What these games have in common is, that two players move after each other and that a situation that is good for one player, is bad for the other player. In those kind of games you can use the min-max algorithm.

 

So google for something like "4-in-a-row min-max tutorial".

I found this, but I didn't watch the videos: https://www.youtube.com/results?search_query=chess+min+max

 

--------------------------------

 

Short explanation:

  • What is a bad situaltion for a player: When he doesn't have a king.
  • What is also a bad situation: When every move he could make would lead to a good situation for the opponent.
  • What is a good situation for a player: When there is any move that produces a bad situation for the opponent.

Think about it: These three rules would suffice to make a perfect chess ai - but it isn't efficient enough, so the computer would run out of memory and time (even a supercomputer). It is enought to solve chess problems, or tic-tac-toe, though.

 

The second best alternative is to stop after a certain depth and decide how good your situation is without considering the following moves. A simple option to do this is to calculate your pawn-power (e.g. a rook would be 4 or 5 pawns, an enemy queen would be -9 pawns).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...