Question

I'm starting to write a Chess program in JavaScript and possibly some Node.JS if I find the need to involve the server in the Chess AI logic, which is still plausible at least in my possibly ignorant opinion. My question is simple enough: Is the client-side FileSystem API for JavaScript a reasonable way to cache off minimax results for future reference, or is the resulting data just way too much to store in any one place? My idea was that it could be used as a way to allow the AI to adapt to the user and "learn" by being able to access previous decisions rather than manually re-determining them every time. Is this a reasonable plan or am I underestimating the memory usage this would need? If your answer is that this is plausible, some tips on the most efficient method for storing the data in this manner would be nice too.

Was it helpful?

Solution

I have written Chess Engines before in C++, but no Javascript.

What you describe is usually solved by a transposition table. You calculate a hash key that identifies the position and store additional data with it. See: https://www.chessprogramming.org/Transposition_Table https://www.chessprogramming.org/Zobrist_Hashing

Web storage provides per origin:

2.5 MB for Google Chrome
5 MB for Mozilla Firefox
10 MB for Internet Explorer

Each entry usually holds:

Zobrist Hash Key: 8 byte
Best Move: 2 byte
Depth: 1 byte
Score: 2 byte
Type of score (exact, upper bound, lower bound): 1 byte
= 16 byte

So e.g. Google Chrome can hold 160k entries. Usually for a chess position analysis you use over 1 GB of memory for the transposition table. Anyway, for a javascript engine I think the 2.5 MB is a good compromise.

To make sure that the javascript engine uses the optimal storage I advise you to convert the data to some sort of binary representation. Then I would index the localStorage by Zobrist Hash Key and store all the other information associated with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top