Ejemplo n.º 1
0
ErrorCode CheckFoodAndMove(Matrix *matrix, Player player, Point p)
{
	static int white_counter = K;
	static int black_counter = K;
	/* if the player did come to the place where there is food */
	if ((*matrix)[p.y][p.x] == FOOD)
	{
		if (player == BLACK) black_counter = K;
		if (player == WHITE) white_counter = K;

		IncSizePlayer(matrix, player, p);

		if (RandFoodLocation(matrix) != ERR_OK)
			return ERR_BOARD_FULL;
	}
	else /* check hunger */
	{
		if (player == BLACK && --black_counter == 0)
			return ERR_SNAKE_IS_TOO_HUNGRY;
		if (player == WHITE && --white_counter == 0)
			return ERR_SNAKE_IS_TOO_HUNGRY;

		AdvancePlayer(matrix, player, p);
	}
	return ERR_OK;
}
Ejemplo n.º 2
0
// Anna's add end
bool Init(Matrix *matrix) {
	int i;
	/* initialize the snakes location */
	for (i = 0; i < M; ++i) {
		(*matrix)[0][i] = WHITE * (i + 1);
		(*matrix)[N - 1][i] = BLACK * (i + 1);
	}
	/* initialize the food location */
	/*Rebecca's change - srand*/
	if (RandFoodLocation(matrix) != ERR_OK)
		return FALSE;
	printf(
			"instructions: white player is represented by positive numbers, \nblack player is represented by negative numbers\n");
	Print(matrix);

	return TRUE;
}
Ejemplo n.º 3
0
bool Init(Matrix *matrix)
{
	int i;
	/* initialize the snakes location */
	for (i = 0; i < M; ++i)
	{
		(*matrix)[0][i] =   WHITE * (i + 1);
		(*matrix)[N - 1][i] = BLACK * (i + 1);
	}
	/* initialize the food location */
	//CHANGE not needed srand(time(0));
	if (RandFoodLocation(matrix) != ERR_OK)
		return FALSE;
	//TODO: handle printf("instructions: white player is represented by positive numbers, \nblack player is represented by negative numbers\n");
	//Print(matrix); //we dont print without "read"

	return TRUE;
}