Change board defintion from vector<vector<int>> to vector<vector<char>> for better compatibility with chesspiece.cpp
This commit is contained in:
parent
390ebb597e
commit
b90a60e877
@ -2,7 +2,6 @@
|
|||||||
// Created by hamac on 18.12.2024.
|
// Created by hamac on 18.12.2024.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Chessboard.h"
|
|
||||||
#include "Utils.cpp"
|
#include "Utils.cpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@ -28,47 +27,48 @@ class Chessboard {
|
|||||||
const std::string middleIntersection = "┼";
|
const std::string middleIntersection = "┼";
|
||||||
|
|
||||||
// White pieces
|
// White pieces
|
||||||
const std::string whiteSquare = "\u25A1";
|
const std::string whiteSquare = "□";
|
||||||
const std::string whiteKing = "\u2654";
|
const std::string whiteKing = "♔";
|
||||||
const std::string whiteQueen = "\u2655";
|
const std::string whiteQueen = "♕";
|
||||||
const std::string whiteRook = "\u2656";
|
const std::string whiteRook = "♖";
|
||||||
const std::string whiteBischop = "\u2657";
|
const std::string whiteBischop = "♗";
|
||||||
const std::string whiteKnight = "\u2658";
|
const std::string whiteKnight = "♘";
|
||||||
const std::string whitePawn = "\u2659";
|
const std::string whitePawn = "♙";
|
||||||
|
|
||||||
// Black pieces
|
// Black pieces
|
||||||
const std::string blackSquare = "\u25A0";
|
const std::string blackSquare = "■";
|
||||||
const std::string blackKing = "\u265A";
|
const std::string blackKing = "♚";
|
||||||
const std::string blackQueen = "\u265B";
|
const std::string blackQueen = "♛";
|
||||||
const std::string blackRook = "\u265C";
|
const std::string blackRook = "♜";
|
||||||
const std::string blackBischop = "\u265D";
|
const std::string blackBischop = "♝";
|
||||||
const std::string blackKnight = "\u265E";
|
const std::string blackKnight = "♞";
|
||||||
const std::string blackPawn = "\u265F";
|
const std::string blackPawn = "♟";
|
||||||
|
|
||||||
/* class fields */
|
/* class fields */
|
||||||
std::vector<std::vector<char>> currentBoard;
|
std::vector<std::vector<char>> currentBoard;
|
||||||
|
|
||||||
// Starting formatting
|
// Starting formatting
|
||||||
std::vector<std::vector<char>> startBoard = {
|
std::vector<std::vector<char>> startBoard = {
|
||||||
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'},
|
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
|
||||||
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
|
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
|
||||||
{'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'},
|
||||||
{'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'},
|
||||||
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
|
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
|
||||||
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
|
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ToDo: Mathematisch sicherlich weg rationalisierbar
|
||||||
std::vector<std::vector<char>> emptyBoard = {
|
std::vector<std::vector<char>> emptyBoard = {
|
||||||
{'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'},
|
||||||
{'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'},
|
||||||
{'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'},
|
||||||
{'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'}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Saves turn order; true = white and false = black
|
// Saves turn order; true = white and false = black
|
||||||
@ -206,24 +206,10 @@ class Chessboard {
|
|||||||
// Angabe mit Menü Optionen als Zahlen
|
// Angabe mit Menü Optionen als Zahlen
|
||||||
// Figuren wählen mit Schachnotation
|
// Figuren wählen mit Schachnotation
|
||||||
|
|
||||||
int getCorrectPiece(char pieceIdentifier) {
|
char getCorrectPiece(char pieceIdentifier) {
|
||||||
bool isWhite = getTurnOrder();
|
bool isWhite = getTurnOrder();
|
||||||
|
if (!isWhite) return pieceIdentifier + 32;
|
||||||
static const std::unordered_map<char, int> pieceMap = {
|
return pieceIdentifier;
|
||||||
{'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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, int> convertPosition(const std::string &pos) {
|
std::pair<int, int> convertPosition(const std::string &pos) {
|
||||||
@ -271,8 +257,6 @@ class Chessboard {
|
|||||||
|
|
||||||
std::vector<std::vector<char>> board = getBoard();
|
std::vector<std::vector<char>> board = getBoard();
|
||||||
|
|
||||||
getCorrectPiece(board[oldCoords.first][oldCoords.second]);
|
|
||||||
|
|
||||||
board[oldCoords.first][oldCoords.second] = getEmptyBoard()[oldCoords.first][oldCoords.second];
|
board[oldCoords.first][oldCoords.second] = getEmptyBoard()[oldCoords.first][oldCoords.second];
|
||||||
board[newCoords.first][newCoords.second] = getCorrectPiece(splitMove[0][0]);
|
board[newCoords.first][newCoords.second] = getCorrectPiece(splitMove[0][0]);
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by hamac on 18.12.2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef CHESSBOARD_H
|
|
||||||
#define CHESSBOARD_H
|
|
||||||
|
|
||||||
#endif //CHESSBOARD_H
|
|
@ -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();
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user