<commit_before>//header
#include"game.h"

//variables
int gridX, gridY; //grid lines
extern short sDir; //snake motion animation
extern bool sDirFlag; //snake direction keyboard flag
int snake_length;//snake length
int posX[60], posY[60]; //snake initial position
extern bool gameOver; //gameOver flag
extern bool gamePause; //gamePause flag
bool food; //place food or not
int foodX, foodY; // food position
extern int score; //score
char text[50]; //score string
extern int fps; //animations frame rate
extern bool hiddenFlag; //easter Egg flag

//init game variables
void initGame() {
	fps = MIN_FPS;
	score = 0;
	sDir = RIGHT;
	sDirFlag = true;
	snake_length = 5;
	for (int i = 0; i < snake_length; i++) {
		posX[i] = 20;
		posY[i] = 20 - i;
	}
	food = true;
}

//initalize the grid
void initGrid(int rows, int columns) {
	gridX = columns;
	gridY = rows;
}

//draw cell outline
void drawCell(int x, int y, float thickness,const float* color) {
	glColor3fv(color);
	glLineWidth(thickness);
	glBegin(GL_LINE_LOOP);
	glVertex2d(x, y);
	glVertex2d(x + 1, y);
	glVertex2d(x + 1, y + 1);
	glVertex2d(x, y + 1);
	glEnd();
}

//draw grid when easter egg flag is active
void drawGrid() {
	for (int x = 0; x < gridX; x++) {
		for (int y = 0; y < gridY; y++) {
			if (!gamePause && !gameOver && !(x == 0 || x == gridX - 1 || y == 0 || y == gridY - 1))
				drawCell(x, y, 1.0, GREY);
		}
	}
}

//draw wall
void drawWall() {
	for (int x = 0; x < gridX; x++) {
		for (int y = 0; y < gridY; y++) {
			if (x == 0 || x == gridX - 1 || y == 0 || y == gridY - 1)
				drawCell(x, y, 3.0, RED);
		}
	}
}

//draw food
void drawFood() {
	//get new location
	if (food) {
		random(foodX, foodY);
		//is food at same loc with snake body then redraw at new location
		for (int i = 0; i < snake_length; i++) {
			for (int j = 0; j < snake_length; j++) {
				if (foodX == posX[i] && foodY == posY[j])
					drawFood();
			}

		}
	}
	food = false;
	//food color
	glColor3fv(BLUE);
	//draw food rectangle
	glRectd(foodX, foodY, foodX + 1, foodY + 1);
	//easter egg
	if (hiddenFlag)
		autoPlay();
}

//2 random number generator
void random(int &x, int &y) {
	//range 
	int minX = 1;
	int maxX = gridX - 2;
	int minY = 1;
	int maxY = gridY - 2;
	x = minX + rand() % (maxX - minX);
	y = minY + rand() % (maxY - minY);
}

//draw snake
void drawSnake() {
	if (!gamePause) {
		//body location without head
		for (int i = snake_length - 1; i > 0; i--) {
			posX[i] = posX[i - 1];
			posY[i] = posY[i - 1];
		}
		//snake direction change on key input and enable keyboard
		switch (sDir) {
		case UP:
			posY[0]++;
			sDirFlag = true;
			break;
		case DOWN:
			posY[0]--;
			sDirFlag = true;
			break;
		case RIGHT:
			posX[0]++;
			sDirFlag = true;
			break;
		case LEFT:
			posX[0]--;
			sDirFlag = true;
			break;
		}
	}

	//draw body segments
	for (int i = 0; i < snake_length; i++) {
		glColor3fv(GREEN);
		glRectd(posX[i], posY[i], posX[i] + 1, posY[i] + 1);
	}

	if (!gamePause) {
		//collision detection with border
		if (posX[0] == 0 || posX[0] == gridX - 1 || posY[0] == 0 || posY[0] == gridY - 1) {
			glColor3fv(RED);
			glRectd(posX[0], posY[0], posX[0] + 1, posY[0] + 1);
			makeGameOver();
		}
		//collison with own body
		for (int i = 1; i < snake_length; i++) {
			if (posY[0] == posY[i] && posX[0] == posX[i]) {
				glColor3fv(RED);
				glRectd(posX[i], posY[i], posX[i] + 1, posY[i] + 1);
				makeGameOver();
			}
		}
		//collision with food
		if (posX[0] == foodX && posY[0] == foodY) {
			snake_length++;
			if (snake_length >= 60)
				snake_length = MAX_LEN;
			food = true;
			score++;
			printf("food\n");
		}<commit_msg>detail logging<commit_after>//header
#include"game.h"

//variables
int gridX, gridY; //grid lines
extern short sDir; //snake motion animation
extern bool sDirFlag; //snake direction keyboard flag
int snake_length;//snake length
int posX[60], posY[60]; //snake initial position
extern bool gameOver; //gameOver flag
extern bool gamePause; //gamePause flag
bool food; //place food or not
int foodX, foodY; // food position
extern int score; //score
char text[50]; //score string
extern int fps; //animations frame rate
extern bool hiddenFlag; //easter Egg flag

//init game variables
void initGame() {
	fps = MIN_FPS;
	score = 0;
	sDir = RIGHT;
	sDirFlag = true;
	snake_length = 5;
	for (int i = 0; i < snake_length; i++) {
		posX[i] = 20;
		posY[i] = 20 - i;
	}
	food = true;
}

//initalize the grid
void initGrid(int rows, int columns) {
	gridX = columns;
	gridY = rows;
}

//draw cell outline
void drawCell(int x, int y, float thickness,const float* color) {
	glColor3fv(color);
	glLineWidth(thickness);
	glBegin(GL_LINE_LOOP);
	glVertex2d(x, y);
	glVertex2d(x + 1, y);
	glVertex2d(x + 1, y + 1);
	glVertex2d(x, y + 1);
	glEnd();
}

//draw grid when easter egg flag is active
void drawGrid() {
	for (int x = 0; x < gridX; x++) {
		for (int y = 0; y < gridY; y++) {
			if (!gamePause && !gameOver && !(x == 0 || x == gridX - 1 || y == 0 || y == gridY - 1))
				drawCell(x, y, 1.0, GREY);
		}
	}
}

//draw wall
void drawWall() {
	for (int x = 0; x < gridX; x++) {
		for (int y = 0; y < gridY; y++) {
			if (x == 0 || x == gridX - 1 || y == 0 || y == gridY - 1)
				drawCell(x, y, 3.0, RED);
		}
	}
}

//draw food
void drawFood() {
	//get new location
	if (food) {
		random(foodX, foodY);
		//is food at same loc with snake body then redraw at new location
		for (int i = 0; i < snake_length; i++) {
			for (int j = 0; j < snake_length; j++) {
				if (foodX == posX[i] && foodY == posY[j])
					drawFood();
			}

		}
	}
	food = false;
	//food color
	glColor3fv(BLUE);
	//draw food rectangle
	glRectd(foodX, foodY, foodX + 1, foodY + 1);
	//easter egg
	if (hiddenFlag)
		autoPlay();
}

//2 random number generator
void random(int &x, int &y) {
	//range 
	int minX = 1;
	int maxX = gridX - 2;
	int minY = 1;
	int maxY = gridY - 2;
	x = minX + rand() % (maxX - minX);
	y = minY + rand() % (maxY - minY);
}

//draw snake
void drawSnake() {
	if (!gamePause) {
		//body location without head
		for (int i = snake_length - 1; i > 0; i--) {
			posX[i] = posX[i - 1];
			posY[i] = posY[i - 1];
		}
		//snake direction change on key input and enable keyboard
		switch (sDir) {
		case UP:
			posY[0]++;
			sDirFlag = true;
			break;
		case DOWN:
			posY[0]--;
			sDirFlag = true;
			break;
		case RIGHT:
			posX[0]++;
			sDirFlag = true;
			break;
		case LEFT:
			posX[0]--;
			sDirFlag = true;
			break;
		}
	}

	//draw body segments
	for (int i = 0; i < snake_length; i++) {
		glColor3fv(GREEN);
		glRectd(posX[i], posY[i], posX[i] + 1, posY[i] + 1);
	}

	if (!gamePause) {
		//collision detection with border
		if (posX[0] == 0 || posX[0] == gridX - 1 || posY[0] == 0 || posY[0] == gridY - 1) {
			glColor3fv(RED);
			glRectd(posX[0], posY[0], posX[0] + 1, posY[0] + 1);
			makeGameOver();
		}
		//collison with own body
		for (int i = 1; i < snake_length; i++) {
			if (posY[0] == posY[i] && posX[0] == posX[i]) {
				glColor3fv(RED);
				glRectd(posX[i], posY[i], posX[i] + 1, posY[i] + 1);
				makeGameOver();
			}
		}
		//collision with food
		if (posX[0] == foodX && posY[0] == foodY) {
			snake_length++;
			if (snake_length >= 60)
				snake_length = MAX_LEN;
			food = true;
			score++;
			printf("food,score=%d\n",score);
		}
{'fraction_non_alphanumeric': 0.17482710926694328, 'fraction_numerical': 0.02351313969571231, 'mean_word_length': 2.8299788135593222, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5725567', 'n_tokens_mistral': 3366, 'n_tokens_neox': 2982, 'n_words': 909}