Compare commits

..

12 Commits

3 changed files with 7 additions and 70 deletions

View File

@@ -1,12 +1,9 @@
#ifndef Chessboard_H
#define Chessboard_H
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <random>
#include <regex>
#include <string>
#include <utility>
#include <vector>
@@ -14,20 +11,16 @@
#include <memory>
#include "../Player/Player.hpp"
#include "../ChessPieces/ChessPieceColor.hpp"
#include "../ChessPieces/ChessPieceMove.hpp"
#include "../ChessPieces/ChessPiecePosition.hpp"
class ChessPiece;
class Chessboard {
private:
std::vector<ChessPieceMove> _historyMoves;
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> _historyPositions;
std::map<ChessPiecePosition, ChessPiece*> chessboard;
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> history;
std::pair<Player*, Player*> players;
std::pair<bool, bool> draw;
Player* currentPlayer;
void RemoveChessPiece(ChessPiecePosition position);
public:
struct Board_ChessPiece {
@@ -83,26 +76,20 @@ class Chessboard {
{1, 'R', {'H', 1}}
};
~Chessboard();
std::vector<ChessPieceMove> GetHistoryMoves();
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> GetHistoryPositions();
void InitializeStartBoard();
void InitializeBoard(std::set<Board_ChessPiece> board);
//void SetChessPiece(std::unique_ptr<ChessPiece> piece);
void SetChessPiece(ChessPiece* chesspiece);
bool IsDraw();
bool IsEmptyField(ChessPiecePosition* position);
ChessPiece* GetChessPiece(ChessPiecePosition* position);
std::vector<ChessPiece*> GetChessPieces();
void UpdateChessPieces();
void MoveChessPiece(std::string move);
bool MoveCastling(ChessPieceColor color, bool shortCastling);
void SetToHistory(ChessPieceMove move);
void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition);
int GetCountMoves();
bool HasMoves();
std::pair<ChessPiecePosition, ChessPiecePosition> GetLastMovePositions();
std::pair<ChessPiecePosition, ChessPiecePosition> GetLastMove();
bool IsCheckmate();
bool IsInCheck();
bool IsCheck();
bool IsStalemate();
bool IsPositionUnderAttack(ChessPiecePosition position, ChessPieceColor color);
Player* GetCurrentPlayer();
@@ -111,8 +98,6 @@ class Chessboard {
void SwitchCurrentPlayer();
Player* GetPlayer(ChessPieceColor color);
ChessPiece* GetChessPieceKing(ChessPieceColor color);
bool ImportFilePGN(std::string filePath);
bool ExportFilePGN(std::string filePath);
};
#endif

View File

@@ -107,27 +107,13 @@
- Startmenü
- Spielmenü mit Historie, Kommand
- Plattformunabhängiges CMD clearing vor dem Zeichnen
- Spezialbewegung (Rochade, Umwandlung, En passant)
## Kompilieren und Ausführen
Um TurboSchach kompilieren zu können wird mindestens C++ 17 benötigt.
### Windows
## Build
```
g++ -std=c++17 -o chess.exe main.cpp ChessPieces/*.cpp Chessboard/*.cpp Player/*.cpp
./chess.exe
```
### Linux und MacOS
g++ -o chess.exe main.cpp ChessPieces/*.cpp Chessboard/*.cpp Player/*.cpp Visualizer/*.cpp
```
# compile the project
make
# run the project
make run
## Voraussetzungen
# remove all output files
make clean
```
- C++ 17

View File

@@ -1,7 +1,4 @@
#ifdef _WIN32
#include <windows.h>
#endif
#include <fstream>
#include "Player/Player.hpp"
#include "ChessPieces/ChessPiece.hpp"
#include "Chessboard/Chessboard.hpp"
@@ -68,8 +65,6 @@ void HandleFirstOption() {
playView.DisplayElement();
int main(int argc, char* argv[]) {
#ifdef _WIN32
std::cout << "\x1B[u";
std::cin >> input;
@@ -94,7 +89,6 @@ void HandleSecondOption() {}
int main() {
SetConsoleOutputCP(CP_UTF8);
#endif
BaseVisualizer::ClearTerminal();
@@ -156,34 +150,6 @@ int main() {
return 0;
}
// Jetzt kann man Moves machen. Nach jedem Move müssen die ChessPieces aktualisiert werden.
chessboard.UpdateChessPieces();
//ChessboardVisualizerText* visualizer = new ChessboardVisualizerText();
ChessboardVisualizerGraphic* visualizer = new ChessboardVisualizerGraphic();
visualizer->Draw(&chessboard);
// Import chessboard from PGN file.
// https://www.chessgames.com/perl/chessgame?gid=1799484
// 1588906 - Checkmate
// 1482551 - Checkmate
// 1348060 - Checkmate
// 1799484 - Checkmate
// 1284086 - Stalemate
// 1258478 - Stalemate
// 1229276 - En Passant (black fxg3)
// 1775611 - En Passant (white axb6)
// 1427255 - En Passant (white bxc6+ and dxe6)
// chessboard.ImportFilePGN("./chessgames/1258478.pgn");
// visualizer->Draw(&chessboard);
while (chessboard.IsCheckmate() == false && chessboard.IsStalemate() == false && chessboard.IsDraw() == false) {
std::string move;
std::cout << "Move [" << ((chessboard.GetCurrentPlayer()->GetColor() == ChessPieceColor::White) ? "White" : "Black") << "] : ";
std::cin >> move;
chessboard.MoveChessPiece(move);
visualizer->Draw(&chessboard);
}
/**
std::vector<std::vector<ChessPiece>> chessmatrix;