Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include "general.h"
void CopyMap (struct Map *Mdest, const struct Map *Morig)
{
memcpy((void *) Mdest, (void *) Morig, sizeof (struct Map));
}
static int are_boxes_equal(const struct Position b1[], const struct Position b2[],
int n)
{
int i;
char tmp[MAX_Y][MAX_X]; /* !!!argh */
memset(tmp, 0, sizeof(tmp));
for (i=0; i < n; i++)
{
tmp[b1[i].y][b1[i].x] = 1;
}
for (i=0; i < n; i++)
{
if (tmp[b2[i].y][b2[i].x] != 1)
return FALSE;
}
return TRUE;
}
int is_new_map(const struct Map maps[], const int depth)
{
const struct Map *m = &maps[depth];
int i;
extern int max_depth;
for(i=0; i<max_depth; i++)
{
/* No l'hem de comparar amb ell mateix */
if (i == depth)
continue;
if (m->NumBoxesInPlatform != maps[i].NumBoxesInPlatform)
continue;
else
{
if (!are_boxes_equal(m->Box, maps[i].Box, m->NumBoxes))
continue;
}
return FALSE;
}
return TRUE;
}