Mankala: saving the board

Started by
1 comment, last by EvLer 19 years, 6 months ago
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
Advertisement
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.

This topic is closed to new replies.

Advertisement