From d73b463f796d2d3717b06013c68e9144d127290b Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 7 Jun 2023 22:49:46 +0200 Subject: [PATCH] We did nothing because github also fenimport works for black and white turn now --- include/game.hpp | 2 +- include/util.hpp | 2 +- src/Game.cpp | 22 ---------------------- src/util.cpp | 22 ++++++++++++++++++++-- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/game.hpp b/include/game.hpp index a3b2eaf..5cfe66e 100644 --- a/include/game.hpp +++ b/include/game.hpp @@ -26,7 +26,7 @@ class Game int counter = 0; // Pieces - std::vector> Pieces = FenImport("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"); + std::vector> Pieces = FenImport("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", whiteTurn); std::shared_ptr selectedPiece; diff --git a/include/util.hpp b/include/util.hpp index d9563a5..49d805b 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -6,6 +6,6 @@ // Inputs //std::vector> FenImport(std::string); -std::vector> FenImport(std::string FenString); +std::vector> FenImport(std::string FenString, bool& whiteTurn); std::shared_ptr getMatchingPiece(glm::vec2 field, std::vector>& Pieces); glm::vec2 getMousePosition(bool whiteDown, int squareSize); diff --git a/src/Game.cpp b/src/Game.cpp index 0e14d9f..cc49d39 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -70,23 +70,14 @@ void Game::placePiece() { glm::ivec2 MousePosition = getMousePosition(whiteDown,window.squareSize); - /* if (!lastPieces.empty()) { - if (lastPieces[lastPieces.size()-1]->white) { - whiteTurn = false; - } else { - whiteTurn = true; - } - } */ if (selectedPiece->move(MousePosition, lastPositions[0], Pieces, whiteTurn)) { if (rotate_board) { whiteDown=!whiteDown; } whiteTurn = !whiteTurn; handleCheckmate(); - lastPieces.push_back(selectedPiece); lastPositions.push_back(selectedPiece->getPos()); } - //lastPositions.push_back(selectedPiece->getPos()); isPieceSelected = false; } void Game::handleCheckmate() { @@ -105,7 +96,6 @@ void Game::handleCheckmate() { gameRunning = false; } } -//prolly hashmaps of all pieces' moves im too stupid for this void Game::handleEvents() { if (counter < 0) { counter = 0; @@ -129,18 +119,6 @@ void Game::handleEvents() { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_q: gameRunning = false; break; - case SDLK_LEFT: if ( (lastPieces.size()-1) >= counter && (lastPositions.size()-1) >= 2*counter){ - lastPieces[(lastPieces.size() - 1) - counter]->setPos(lastPositions[(lastPositions.size() - 1)-(2*counter)-1]); - whiteTurn = !whiteTurn; - counter++; - } - break; - case SDLK_RIGHT: if ( (lastPieces.size()-1) >= 1*counter-1 && lastPositions.size() >= 1*counter-1){ - lastPieces[(lastPieces.size() - 1) - (counter-1)]->setPos(lastPositions[(lastPositions.size() - 1) - (2*(counter-1)) ]); - whiteTurn = !whiteTurn; - counter--; - } - break; } } } diff --git a/src/util.cpp b/src/util.cpp index ae6a898..a20fda5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -13,17 +13,22 @@ #include "knight.hpp" #include "piece.hpp" -std::vector> FenImport(std::string FenString) { +std::vector> FenImport(std::string FenString, bool& whiteTurn) { + bool nextPart = true; std::vector> Pieces; int countx = 0; int county = 0; + + std::string FenString2 = FenString.substr(FenString.find(' ') + 1); for (char c : FenString) { if (std::isdigit(c)) { countx += atoi(&c); } else if (c == '/') { county += 1; countx = 0; - } else if (std::isalpha(c)) { + } else if (c == ' ') { + nextPart = false; + } else if (std::isalpha(c) and nextPart) { switch (tolower(c)) { case 'k': Pieces.push_back(std::make_shared(glm::vec2{countx, county}, isupper(c))); @@ -49,7 +54,20 @@ std::vector> FenImport(std::string FenString) { Pieces.push_back(std::make_shared(glm::vec2{countx, county}, isupper(c))); countx += 1; break; + case ' ': + break; + } + + } else if (std::isalpha(c) and !nextPart) { + switch (tolower(c)) { + case 'w': + whiteTurn = true; + break; + case 'b': + whiteTurn = false; + break; } + } } return Pieces;