map.c
changeset 6 bfbca2c0fc70
parent 4 d9259a605dec
child 8 b41a580b3abe
--- a/map.c	Sat May 06 00:33:47 2006 +0200
+++ b/map.c	Sat May 06 00:34:04 2006 +0200
@@ -8,115 +8,23 @@
 	memcpy((void *) Mdest, (void *) Morig, sizeof (struct Map));
 }
 
-void ReadMap(struct Map *M, char *FileName)
+int are_boxes_equal(const struct Position b1[], const struct Position b2[],
+	int n)
 {
-	FILE *Fitxer;
-	int i,j;
-
-	if(!(Fitxer = fopen(FileName, "r")))
-	{
-		printf("Error opening %s!", FileName);
-		exit(1);
-	}
+	int i;
+	char tmp[MAX_Y][MAX_X]; /* !!!argh */
 
-	M->SizeX=0;
-	M->SizeY=0;
-	while (!feof(Fitxer))
-	{
-		fgets(M->Cells[M->SizeY], MAX_X, Fitxer);
-		M->SizeY++;
-	}
-	M->SizeY--;
-	M->SizeX = strlen(M->Cells[0]) - 1;
-
-	M->NumPlatforms = 0;
-	M->NumBoxesInPlatform = 0;
-	M->NumBoxes = 0;
-	for (j = 0; j<M->SizeY; j++)
-		for (i=0; i<M->SizeX; i++)
-		{
-			if (M->Cells[j][i] == MAN)
-			{ 
-				M->Man.x = i; M->Man.y = j; 
-				M->Cells[M->Man.y][M->Man.x] = BLANK;
-			}
+	memset(tmp, 0, sizeof(tmp));
 
-			if (M->Cells[j][i] == PLATFORM)
-				M->NumPlatforms++;
-			else if (M->Cells[j][i] == BOXINPLATFORM)
-			{
-				M->Cells[j][i] = PLATFORM;
-
-				M->NumPlatforms++;
-				M->NumBoxesInPlatform++;
-
-				M->Box[M->NumBoxes].x = i;
-				M->Box[M->NumBoxes].y = j;
-				M->NumBoxes++;
-			} else if (M->Cells[j][i] == BOX)
-			{
-				M->Cells[j][i] = BLANK;
-
-				M->Box[M->NumBoxes].x = i;
-				M->Box[M->NumBoxes].y = j;
-				M->NumBoxes++;
-			} else if (M->Cells[j][i] == CORNER)
-			{
-				M->Cells[j][i] = CORNER;
-			} else if (M->Cells[j][i] != WALL)
-			{
-				if (    (M->Cells[j][i-1] == WALL &&
-					 M->Cells[j-1][i] == WALL) ||
-					(M->Cells[j][i-1] == WALL &&
-					 M->Cells[j+1][i] == WALL) ||
-					(M->Cells[j][i+1] == WALL &&
-					 M->Cells[j-1][i] == WALL) ||
-					(M->Cells[j][i+1] == WALL &&
-					 M->Cells[j+1][i] == WALL))
-				M->Cells[j][i] = CORNER;
-			}
-				
-		}
-
+	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;
 }
 
-
-void ShowMap (const struct Map *M)
-{
-	struct Map Temp;
-	int i,j;
-
-	CopyMap(&Temp, M);
-
-	Temp.Cells[Temp.Man.y][Temp.Man.x] = MAN;
-
-	for (i = 0; i < Temp.NumBoxes; i++)
-	{
-		if (Temp.Cells[Temp.Box[i].y][Temp.Box[i].x] == PLATFORM)
-			Temp.Cells[Temp.Box[i].y][Temp.Box[i].x] =BOXINPLATFORM;
-		else
-			Temp.Cells[Temp.Box[i].y][Temp.Box[i].x] = BOX;
-	}
-
-	for (j = 0; j<Temp.SizeY; j++)
-	{
-		for (i=0; i<Temp.SizeX; i++)
-			fprintf(stderr,"%c", Temp.Cells[j][i]);
-		fprintf(stderr,"\n");
-	}
-
-#if 0
-	// Print Where the man can move
-	for (j = 0; j<Temp.SizeY; j++)
-	{
-		for (i=0; i<Temp.SizeX; i++)
-			printf("%c", Temp.ManMoves[j][i]);
-		printf("\n");
-	}
-#endif
-
-	printf("Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
-	printf("Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
-			Temp.NumBoxesInPlatform);
-
-}