Sign in to follow this  

Mankala: saving the board

This topic is 4811 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, I am working on mankala game_tree, so each node has to have a board to figure out the moves (using minimax). The way it is given in this project, the board is a 2D array passed by a single pointer. So, the structure for the node I came up with was: struct node { int *Board; ..... } game_tree_node; My question is: is it possibile to get around malloc()ing for it every time a node is created? Thanks in advance. Oh, yeah, that's in C

Share this post


Link to post
Share on other sites
The short answer is no, not really.

However, assuming that your objection to malloc is its slowness... there are many faster ways to allocate memory than the standard malloc, but you are going to have to write the allocation system yourself (or get it from someone else). The type of allocator you are looking for is generally called a "pool" or "fixed-size" allocator.

Now here's some advice -- don't worry speeding up allocation until everything else is working perfectly. Replacing malloc also means giving up the debugging tools built into it, and to make matters worse, bugs in your allocation system will make debugging the other parts of your code more difficult.

Share this post


Link to post
Share on other sites
Thanks a lot for the clarification.
I have a follow up question though. If I have a function int Update_Board() that returns status of the game based on the distribution of pieces (CAPTURE, GAME_OVER, etc.) defined as integers.

Obviuosly, the board (int *board) is updated as well. And then when I try to generate a list Generate(current_board) of nodes that essentially contain different board_positions (I malloc the node and the array as well), I would want to set the node->board to newly-generated board position; so first I set node->board = current_board and NOW:

if I call 'int Update_Board(node->board)' somewhere in the function (since its an int I cannot set it directly as node->board = Update_board), will the newly-generated board be updated correctly and also will the current_board be in its original state?

I guess it's a pointer issue I am confused about.
Thanks in advance.

Share this post


Link to post
Share on other sites

This topic is 4811 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