Storing a lot of data (chess engine calculations)

I want my chess engine to evaluate positions to 2 ply (or ideally 4ply) and then calculate with an alpha-beta search from there. This means I need to store a minimum of ~ (35*35) positions (for 2ply) in variables along with a numerical evaluation for each. What is the best way to go about doing this?

I would like a solution that doesn’t involve C++ so that I can release this chess game on the web.

Thanks : )

Using structure variables ?

How do you declare so many and iterate over them?

When working in grid-based games I use object variables to store data in each cell of the grid, including an index. Then I build a function that query data from a specific cell of the grid, you just have to pass the index of the cell as an argument and then the function will iterate trough all the cells, find the specified cell and extract the information to global variables I call “result variables”, where other events and actions can access that data and make the necessary calculations.

I usually make a lot of spam about a game project I release in this forums the last year (Group-It). So, sorry about that, but it’s a good example of a grid based game, objects variables, simulation of an array, iteration trough it and use of functions with arguments. This is the post: viewtopic.php?f=19&t=5442

Hope it helps :sunglasses:

When working in grid-based games I use object variables to store data in each cell of the grid, including an index. Then I build a function that query data from a specific cell of the grid (a sprite object), you just have to pass the index of the cell as an argument and then the function will iterate trough all the cells, find the specified cell and extract the information to global variables I call “result variables”, where other events and actions can access that data and make the necessary calculations.

I usually make a lot of spam about a game project I release in this forums the last year (Group-It). So, sorry about that, but it’s a good example of a grid based game, objects variables, simulation of an array, iteration trough it and use of functions with arguments in GD. This is the post: viewtopic.php?f=19&t=5442

Hope it helps :sunglasses:

I don’t understand how that would work? :confused:

If I store data for each cell in the grid, then each cell will end up having hundreds of variables (thousands if I get to 4 ply brute force which is what many strong chess engines do before a-b search). I’m not sure how to easily access that or efficiently declare it all.

Tip : declaring a variable is not mandatory.

What I’m looking for is a way to do something like this:

int moves[64][1024]; 

void calculatemoves()
{
//Fill in array with moves and their evaluations here.  
}

You have to work with the “dynamic declaration” of structure variables: instead fixed names as “MyParent.myChild”, you can use strings like “MyParent[“myChild”]”, so you can use numerical data converted into string.

For example, for your example of two dimensional array, you could do something like:

Do = 0 the variable "x_loop" Repeat 64 times ........Do = 0 the variable "y_loop" ........Repeat 1024 times ................Do = "Some value" the string variable MyParent[VariableString(x_loop)][VariableString(y_loop)] ................Do +1 to variable "y_loop" ........Do +1 to variable "x_loop"
:exclamation: This code hasn’t been tested.

This way you make a doble iteration, with two scene variables as counters, and convert them into strings to dynamically create the childs from a vaiable name :slight_smile:

EDIT: Fixed ToString(Variable(var)) instead VariableString(var) :slight_smile:

You can use VariableString(myVar) instead of ToString(Variable(myVar)). It will convert the number to a string directly.

Thanks! , I don’t know why I wrote it in that way :blush: , it’s ugly, and just works to get strings from number variables (I don’t know, but maybe get a string variable through ToString(Variable(var)) forces GD to convert the string in number, of course 0, then you get “0”) :smiley:

EDIT: Fixed :slight_smile:

Thanks I will try this tonight.

One question : All these strings seem computationally expensive. Is there a way to do everything with ints without converting to strings at any time? I am hoping to add two AIs for this chess, one for which expensive computation does not matter, but I also would like to make a more standard a-b search AI and it seems they need to be able to check 100 000+ nodes / second to be at a reasonable level and it looks like there is no way this is happening using this method (is this even a reasonable expectation at all with an HTML game?).