<commit_before>#include "GUI.h"
#include "Queen.h"
#include "Rook.h"
#include "Bishop.h"
#include "Knight.h"


using namespace sf;
using namespace Chess;

namespace GUI {
	GUI::GUI(int width, int height, Board& board) : board(board) {
		this->width = width;
		this->height = height;

		window = new RenderWindow(VideoMode(width, height), "Ninja Chess");
		window->setVerticalSyncEnabled(true);

		font.loadFromFile("Resources/stchess.ttf");

		text.setFont(font);
		text.setCharacterSize(height / 8);
		text.setColor(Color::Black);

		notationMap['P'] = "A";
		notationMap['p'] = "a";
		notationMap['R'] = "D";
		notationMap['r'] = "d";
		notationMap['N'] = "B";
		notationMap['n'] = "b";
		notationMap['B'] = "C";
		notationMap['b'] = "c";
		notationMap['Q'] = "E";
		notationMap['q'] = "e";
		notationMap['K'] = "F";
		notationMap['k'] = "f";
	}

	GUI::~GUI() {
		delete window;
	}

	bool GUI::isOpen() const {
		return window->isOpen();
	}

	void GUI::update() {
		if (showPromoteWindow == false){
			updateGame();
		}
		else{
			updatePromote();
		}
	}

	void GUI::updateGame(){
		Event event;
		while (window->pollEvent(event)) {
			if (event.type == Event::Closed)
				window->close();
		}

		bool pressed = Mouse::isButtonPressed(Mouse::Left);
		if (pressed && !mousePressed) {
			Vector2i mousePos = Mouse::getPosition(*window);
			Position tempPos(mousePos.x * 8 / width, mousePos.y * 8 / height);
			tempPos.y = 7 - tempPos.y;
			if (tempPos.valid()) {
				Piece* tempPiece = board.getPiece(tempPos);
				if (selected) {
					Piece* selectedPiece = board.getPiece(selection);
					if (selectedPiece->isLegal(board, tempPos)) {
						board.move(selection, tempPos);
						lastMovedPiece = tempPiece;
						selected = false;
					}
					else if (tempPiece != nullptr) {
						if (tempPiece->isWhite() && (board.getState() == GameState::BLACKPLAYS))
							return;
						else if (!tempPiece->isWhite() && (board.getState() == GameState::WHITEPLAYS))
							return;
						selection = tempPos;
						selected = true;
						highlights = tempPiece->legalMoves(board);
					}
				}
				else if (tempPiece != nullptr) {
					if (tempPiece->isWhite() && (board.getState() == GameState::BLACKPLAYS))
						return;
					else if (!tempPiece->isWhite() && (board.getState() == GameState::WHITEPLAYS))
						return;
					selection = tempPos;
					selected = true;
					highlights = tempPiece->legalMoves(board);
				}
			}
		}
		if (board.signalPromote() == true)
			showPromoteWindow = true;
		mousePressed = pressed;
	}

	void GUI::updatePromote()
	{
		Event event;
		while (window->pollEvent(event)) {
			if (event.type == Event::Closed)
				window->close();
		}
		bool pressed = Mouse::isButtonPressed(Mouse::Left);
		if (pressed && !mousePressed){
			Vector2i mousePos = Mouse::getPosition(*window);
			Position tempPosition;
			tempPosition.x = lastMovedPiece->getPosition().x;
			tempPosition.y = lastMovedPiece->getPosition().y;
			bool tempIsWhite = lastMovedPiece->isWhite();
			if ((mousePos.x < width / 2.f) && (mousePos.y < height / 2.f)){
				printf("QUEEN");
				text.setCharacterSize(height / 8);
				delete lastMovedPiece;
				lastMovedPiece = new Queen(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x > width / 2.f) && (mousePos.y < height / 2.f)){
				printf("ROOK");
				text.setCharacterSize(height / 8);
				delete lastMovedPiece;
				lastMovedPiece = new Rook(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x < width / 2.f) && (mousePos.y > height / 2.f)){
				text.setCharacterSize(height / 8);
				printf("BISHOP");
				delete lastMovedPiece;
				lastMovedPiece = new Bishop(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x > width / 2.f) && (mousePos.y > height / 2.f)){
				text.setCharacterSize(height / 8);
				printf("KNIGHT");
				delete lastMovedPiece;
				lastMovedPiece = new Knight(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}<commit_msg>Promotion fixed.<commit_after>#include "GUI.h"
#include "Queen.h"
#include "Rook.h"
#include "Bishop.h"
#include "Knight.h"


using namespace sf;
using namespace Chess;

namespace GUI {
	GUI::GUI(int width, int height, Board& board) : board(board) {
		this->width = width;
		this->height = height;

		window = new RenderWindow(VideoMode(width, height), "Ninja Chess");
		window->setVerticalSyncEnabled(true);

		font.loadFromFile("Resources/stchess.ttf");

		text.setFont(font);
		text.setCharacterSize(height / 8);
		text.setColor(Color::Black);

		notationMap['P'] = "A";
		notationMap['p'] = "a";
		notationMap['R'] = "D";
		notationMap['r'] = "d";
		notationMap['N'] = "B";
		notationMap['n'] = "b";
		notationMap['B'] = "C";
		notationMap['b'] = "c";
		notationMap['Q'] = "E";
		notationMap['q'] = "e";
		notationMap['K'] = "F";
		notationMap['k'] = "f";
	}

	GUI::~GUI() {
		delete window;
	}

	bool GUI::isOpen() const {
		return window->isOpen();
	}

	void GUI::update() {
		if (showPromoteWindow == false){
			updateGame();
		}
		else{
			updatePromote();
		}
	}

	void GUI::updateGame(){
		Event event;
		while (window->pollEvent(event)) {
			if (event.type == Event::Closed)
				window->close();
		}

		bool pressed = Mouse::isButtonPressed(Mouse::Left);
		if (pressed && !mousePressed) {
			Vector2i mousePos = Mouse::getPosition(*window);
			Position tempPos(mousePos.x * 8 / width, mousePos.y * 8 / height);
			tempPos.y = 7 - tempPos.y;
			if (tempPos.valid()) {
				Piece* tempPiece = board.getPiece(tempPos);
				if (selected) {
					Piece* selectedPiece = board.getPiece(selection);
					if (selectedPiece->isLegal(board, tempPos)) {
						board.move(selection, tempPos);
						lastMovedPiece = selectedPiece;
						selected = false;
					}
					else if (tempPiece != nullptr) {
						if (tempPiece->isWhite() && (board.getState() == GameState::BLACKPLAYS))
							return;
						else if (!tempPiece->isWhite() && (board.getState() == GameState::WHITEPLAYS))
							return;
						selection = tempPos;
						selected = true;
						highlights = tempPiece->legalMoves(board);
					}
				}
				else if (tempPiece != nullptr) {
					if (tempPiece->isWhite() && (board.getState() == GameState::BLACKPLAYS))
						return;
					else if (!tempPiece->isWhite() && (board.getState() == GameState::WHITEPLAYS))
						return;
					selection = tempPos;
					selected = true;
					highlights = tempPiece->legalMoves(board);
				}
			}
		}
		if (board.signalPromote() == true)
			showPromoteWindow = true;
		mousePressed = pressed;
	}

	void GUI::updatePromote()
	{
		Event event;
		while (window->pollEvent(event)) {
			if (event.type == Event::Closed)
				window->close();
		}
		bool pressed = Mouse::isButtonPressed(Mouse::Left);
		if (pressed && !mousePressed){
			Vector2i mousePos = Mouse::getPosition(*window);
			Position tempPosition = lastMovedPiece->getPosition();
			bool tempIsWhite = lastMovedPiece->isWhite();
			if ((mousePos.x < width / 2.f) && (mousePos.y < height / 2.f)){
				printf("QUEEN");
				text.setCharacterSize(height / 8);
				delete lastMovedPiece;
				lastMovedPiece = new Queen(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x > width / 2.f) && (mousePos.y < height / 2.f)){
				printf("ROOK");
				text.setCharacterSize(height / 8);
				delete lastMovedPiece;
				lastMovedPiece = new Rook(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x < width / 2.f) && (mousePos.y > height / 2.f)){
				text.setCharacterSize(height / 8);
				printf("BISHOP");
				delete lastMovedPiece;
				lastMovedPiece = new Bishop(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
			else if ((mousePos.x > width / 2.f) && (mousePos.y > height / 2.f)){
				text.setCharacterSize(height / 8);
				printf("KNIGHT");
				delete lastMovedPiece;
				lastMovedPiece = new Knight(tempPosition, tempIsWhite);
				showPromoteWindow = false;
			}
{'fraction_non_alphanumeric': 0.16366612111292964, 'fraction_numerical': 0.004532292584665743, 'mean_word_length': 3.488135593220339, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, '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': '557662', 'n_tokens_mistral': 3346, 'n_tokens_neox': 2740, 'n_words': 560}