Skip to content

Commit

Permalink
We did nothing because github also fenimport works for black and whit…
Browse files Browse the repository at this point in the history
…e turn now
  • Loading branch information
Frank-py committed Jun 7, 2023
1 parent 29cf2ad commit d73b463
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Game
int counter = 0;

// Pieces
std::vector<std::shared_ptr<Piece>> Pieces = FenImport("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR");
std::vector<std::shared_ptr<Piece>> Pieces = FenImport("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", whiteTurn);
std::shared_ptr<Piece> selectedPiece;


Expand Down
2 changes: 1 addition & 1 deletion include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
// Inputs

//std::vector<std::shared_ptr<Piece>> FenImport(std::string);
std::vector<std::shared_ptr<Piece>> FenImport(std::string FenString);
std::vector<std::shared_ptr<Piece>> FenImport(std::string FenString, bool& whiteTurn);
std::shared_ptr<Piece> getMatchingPiece(glm::vec2 field, std::vector<std::shared_ptr<Piece>>& Pieces);
glm::vec2 getMousePosition(bool whiteDown, int squareSize);
22 changes: 0 additions & 22 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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;
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@
#include "knight.hpp"
#include "piece.hpp"

std::vector<std::shared_ptr<Piece>> FenImport(std::string FenString) {
std::vector<std::shared_ptr<Piece>> FenImport(std::string FenString, bool& whiteTurn) {
bool nextPart = true;
std::vector<std::shared_ptr<Piece>> 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<King>(glm::vec2{countx, county}, isupper(c)));
Expand All @@ -49,7 +54,20 @@ std::vector<std::shared_ptr<Piece>> FenImport(std::string FenString) {
Pieces.push_back(std::make_shared<Queen>(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;
Expand Down

0 comments on commit d73b463

Please sign in to comment.