Sign in to follow this  

Better representation of Board Game AI

This topic is 2320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again.
I have programed a game of chess. However I have used dynamic memory allocation everywhere,when new moves are generated.This has slowed down the speed of my code.
I came up with an idea of making a multi-dimensional array, one stores the depth at which the moves are called and other stores the moves.
For this I have written a X's and O's game.
Here is the snippet.
[code]
static int moves[][]=new int[maxDepth][boardSize]
static int n[]=new int[maxDepth];
...
public static void possibleMoves(int board[][], int depth) {

n[depth] = 0; // here it acts as a counter, counts the number of legal moves, this can be used in the loop to play the legalmoves.
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if (board[i][j] == 0) {
mList[depth][n[depth]++] = size * i + j;
}
}
}

}[/code]
I doesnt work though, wanted to know if my basic idea is correct or not.
Basically my AI plays continuously, without me getting a chance to play.
Is this a common problem any sort of help is welcomed.
Thank you.

Share this post


Link to post
Share on other sites
[quote name='Druzil' timestamp='1312875354' post='4846572']
you are going to run out of memory very quickly on any reasonable (interesting) sized game
[/quote]

No, unless he is doing something very stupid, and this doesn't seem to be the case. As you perform the depth-first search that is minimax, you only need to keep around the list of moves at each node of the branch you are currently exploring, and that doesn't take much memory at all. The way he is indexing the array of moves by depth indicates he is probably doing it right.

Share this post


Link to post
Share on other sites
[quote] No, unless he is doing something very stupid, and this doesn't seem to be the case.[/quote]
But then this has always been the case.
My program now seems to be working correctly.

Share this post


Link to post
Share on other sites

This topic is 2320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this