English 中文(简体)
Chess game in JavaScript [closed]
原标题:
最佳回答

How does a chess algorithm work?:

What a chess computer tries to do is generate the board-position tree five or 10 or 20 moves into the future. Assuming that there are about 20 possible moves for any board position, a five-level tree contains 3,200,000 board positions. A 10-level tree contains about 10,000,000,000,000 (10 trillion) positions. The depth of the tree that a computer can calculate is controlled by the speed of the computer playing the game. The fastest chess computers can generate and evaluate millions of board positions per second.

Once it generates the tree, then the computer needs to "evaluate the board positions." That is, the computer has to look at the pieces on the board and decide whether that arrangement of pieces is "good" or "bad." The way it does this is by using an evaluation function. The simplest possible function might just count the number of pieces each side has. If the computer is playing white and a certain board position has 11 white pieces and nine black pieces, the simplest evaluation function might be:

  11 - 9 = 2 

Obviously, for chess that formula is way too simple, because some pieces are more valuable than others. So the formula might apply a weight to each type of piece. As the programmer thinks about it, he or she makes the evaluation function more and more complicated by adding things like board position, control of the center, vulnerability of the king to check, vulnerability of the opponent s queen, and tons of other parameters. No matter how complicated the function gets, however, it is condensed down to a single number that represents the "goodness" of that board position.

Source.

For building your own javascript engine that s able to play chess at a basic level check Step by Step Javascript Chess with CPU oppo

If you scroll down it contains the source code of this, must say very limited, chess engine purely based on javascript. It also has a working version of the game to try out and all the necessary resources for building your own.

Some useful resources:

问题回答

For algorithmic discussion, try the Chess Programming Wiki.

Techniques suited to serious chess engines are not necessarily right for web based games. Real chess engines run orders of magnitude faster, using multi-megabyte opening books and spending minutes or hours on each turn. A real chess engine will search deeper than 12 ply, while javascript won t get far past 6 ply in reasonable web time. Therefore something like a piece-square oracle, which has diminishing and possibly negative returns as search deepens and is consequently well out of fashion in chess programming circles, is arguably well suited to a javascript engine. If you do what people were doing in the 80s, you will end up with a snappy and manageable engine that will beat most visitors.

And of course you don t really want to look up what other people are doing. Just make sure you have some variation of a alpha-beta search, then tweak your evaluation function and everything else as you see fit.

In 2002 and 2012 I wrote then rewrote p4wn, a small public domain javascript engine. It uses alpha-beta and a piece-square oracle. It is probably weaker than Garbochess-JS, but then Garbochess has an opening book that is bigger that the entire p4wn engine.

The Computer Chess Blog documents the creation of a C# chess engine. It s not JavaScript but the syntax is similar enough that you might get a good understanding of the different chess engine components.

Also if you want your chess engine to be web enabled you might want to consider using C# with a Silverlight GUI. You will get better performance from .NET than you would with JavaScript. As you will learn this will translate into a stronger (deeper searching) chess program. A good example of Silverlight Chess can be found at GeeksWithChess.com





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签