Change board defintion from vector<vector<int>> to vector<vector<char>> for better compatibility with chesspiece.cpp

This commit is contained in:
Fabian Hamacher 2024-12-19 14:18:50 +01:00
parent 390ebb597e
commit b90a60e877
4 changed files with 37 additions and 85 deletions

View File

@ -2,7 +2,6 @@
// Created by hamac on 18.12.2024.
//
#include "Chessboard.h"
#include "Utils.cpp"
#include <iostream>
#include <queue>
@ -28,47 +27,48 @@ class Chessboard {
const std::string middleIntersection = "";
// White pieces
const std::string whiteSquare = "\u25A1";
const std::string whiteKing = "\u2654";
const std::string whiteQueen = "\u2655";
const std::string whiteRook = "\u2656";
const std::string whiteBischop = "\u2657";
const std::string whiteKnight = "\u2658";
const std::string whitePawn = "\u2659";
const std::string whiteSquare = "";
const std::string whiteKing = "";
const std::string whiteQueen = "";
const std::string whiteRook = "";
const std::string whiteBischop = "";
const std::string whiteKnight = "";
const std::string whitePawn = "";
// Black pieces
const std::string blackSquare = "\u25A0";
const std::string blackKing = "\u265A";
const std::string blackQueen = "\u265B";
const std::string blackRook = "\u265C";
const std::string blackBischop = "\u265D";
const std::string blackKnight = "\u265E";
const std::string blackPawn = "\u265F";
const std::string blackSquare = "";
const std::string blackKing = "";
const std::string blackQueen = "";
const std::string blackRook = "";
const std::string blackBischop = "";
const std::string blackKnight = "";
const std::string blackPawn = "";
/* class fields */
std::vector<std::vector<char>> currentBoard;
// Starting formatting
std::vector<std::vector<char>> startBoard = {
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'},
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'},
};
// ToDo: Mathematisch sicherlich weg rationalisierbar
std::vector<std::vector<char>> emptyBoard = {
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'}
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'},
{'w', 'x', 'w', 'x' ,'w', 'x', 'w', 'x'},
{'x', 'w', 'x', 'w', 'x', 'w', 'x', 'w'}
};
// Saves turn order; true = white and false = black
@ -206,24 +206,10 @@ class Chessboard {
// Angabe mit Menü Optionen als Zahlen
// Figuren wählen mit Schachnotation
int getCorrectPiece(char pieceIdentifier) {
char getCorrectPiece(char pieceIdentifier) {
bool isWhite = getTurnOrder();
static const std::unordered_map<char, int> pieceMap = {
{'P', 200},
{'K', 205},
{'Q', 204},
{'N', 202},
{'R', 201},
{'B', 203}
};
int piece = pieceMap.find(pieceIdentifier)->second;
if (isWhite) {
return piece - 100;
}
return piece;
if (!isWhite) return pieceIdentifier + 32;
return pieceIdentifier;
}
std::pair<int, int> convertPosition(const std::string &pos) {
@ -271,8 +257,6 @@ class Chessboard {
std::vector<std::vector<char>> board = getBoard();
getCorrectPiece(board[oldCoords.first][oldCoords.second]);
board[oldCoords.first][oldCoords.second] = getEmptyBoard()[oldCoords.first][oldCoords.second];
board[newCoords.first][newCoords.second] = getCorrectPiece(splitMove[0][0]);

View File

@ -1,8 +0,0 @@
//
// Created by hamac on 18.12.2024.
//
#ifndef CHESSBOARD_H
#define CHESSBOARD_H
#endif //CHESSBOARD_H

View File

@ -1,27 +0,0 @@
//
// Created by hamac on 18.12.2024.
//
#include <string>
#include <vector>
#ifndef CHESSPIECES_H
#define CHESSPIECES_H
#endif //CHESSPIECES_H
class Chesspiece {
private:
char color;
std::string position;
virtual std::vector<std::string> calcAvaibleMoves() {}
public:
std::string getPosition();
void setPosition(std::string position);
char getColor();
void setColor(char color);
std::vector<std::string> getPositions();
};

3
Pawn.cpp Normal file
View File

@ -0,0 +1,3 @@
//
// Created by hamac on 19.12.2024.
//