Bentley
Member
Hello, I'm working on a Chess game (no AI, I'm sooo far from that). Atm, I'm just setting up the board. I highly recommend @matharoo 's tutorial here https://gdpalace.wordpress.com/
Every grid position holds an array. I was wondering about the order the board should be initialized:
1. Set every grid position to an array, and then set every grid position where a piece should be to an array.
2. Set every grid position where a piece should be to an array, and then set every other grid position to an array.
The difference being #1 creates (I think) 32 extra arrays. I know GM does garbage collection, so is this something I should be thinking about?
Here's the two different ways:
1.
2.
Thanks for reading.
Every grid position holds an array. I was wondering about the order the board should be initialized:
1. Set every grid position to an array, and then set every grid position where a piece should be to an array.
2. Set every grid position where a piece should be to an array, and then set every other grid position to an array.
The difference being #1 creates (I think) 32 extra arrays. I know GM does garbage collection, so is this something I should be thinking about?
Here's the two different ways:
1.
Code:
///// Setup board /////
// Empty squares
var array;
array[COLOR] = NONE;
array[PIECE] = NONE;
ds_grid_clear(board, array_clone(array));
// Pieces
for (var i = 0; i < 8; i++)
{
board[# i, 1] = [BLACK, PAWN];
board[# i, 6] = [WHITE, PAWN];
}
Code:
///// Setup board /////
// Pieces
for (var i = 0; i < 8; i++)
{
board[# i, 1] = [BLACK, PAWN];
board[# i, 6] = [WHITE, PAWN];
}
// Empty squares
var array;
array[COLOR] = NONE;
array[PIECE] = NONE;
for (var i = 0; i < 8; i++)
{
for (var j = 0; j < 8; j++)
{
if (!is_array(board[# i, j]))
{
board[# i, j] = array_clone(array);
}
}
}