map.c
author viric@llimona
Fri, 16 Feb 2007 22:57:36 +0100
changeset 26 95fccfcbd04c
parent 10 9148590f009d
permissions -rw-r--r--
Less calls to libc. Profiling is much better now.
viric@4
     1
#include <stdio.h>
viric@4
     2
#include <stdio.h>
viric@4
     3
#include <string.h>
viric@4
     4
#include "general.h"
viric@4
     5
viric@4
     6
void CopyMap (struct Map *Mdest, const struct Map *Morig)
viric@4
     7
{
viric@4
     8
	memcpy((void *) Mdest, (void *) Morig, sizeof (struct Map));
viric@4
     9
}
viric@4
    10
viric@8
    11
static int are_boxes_equal(const struct Position b1[], const struct Position b2[],
viric@6
    12
	int n)
viric@4
    13
{
viric@6
    14
	int i;
viric@6
    15
	char tmp[MAX_Y][MAX_X]; /* !!!argh */
viric@4
    16
viric@26
    17
	for (i=0; i < n; i++)
viric@26
    18
	{
viric@26
    19
		tmp[b2[i].y][b2[i].x] = 0;
viric@26
    20
	}
viric@6
    21
	for (i=0; i < n; i++)
viric@4
    22
	{
viric@6
    23
		tmp[b1[i].y][b1[i].x] = 1;
viric@4
    24
	}
viric@6
    25
	for (i=0; i < n; i++)
viric@4
    26
	{
viric@6
    27
		if (tmp[b2[i].y][b2[i].x] != 1)
viric@6
    28
			return FALSE;
viric@4
    29
	}
viric@6
    30
	return TRUE;
viric@4
    31
}
viric@4
    32
viric@10
    33
int is_new_map(const struct Map maps[], const int depth)
viric@8
    34
{
viric@10
    35
	const struct Map *m = &maps[depth];
viric@8
    36
	int i;
viric@10
    37
	extern int max_depth; 
viric@8
    38
viric@8
    39
	for(i=0; i<max_depth; i++)
viric@8
    40
	{
viric@8
    41
		/* No l'hem de comparar amb ell mateix */
viric@8
    42
		if (i == depth)
viric@8
    43
			continue;
viric@8
    44
viric@8
    45
		if (m->NumBoxesInPlatform != maps[i].NumBoxesInPlatform)
viric@8
    46
			continue;
viric@8
    47
		else
viric@8
    48
		{
viric@8
    49
			if (!are_boxes_equal(m->Box, maps[i].Box, m->NumBoxes))
viric@8
    50
				continue;
viric@8
    51
		}
viric@8
    52
		return FALSE;
viric@8
    53
	}
viric@8
    54
	return TRUE;
viric@8
    55
}