Compare commits
12 Commits
9821f78c87
...
373c186075
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
373c186075 | ||
|
|
9fb66b6755 | ||
| 6127e4cf37 | |||
|
|
8636bcfb0c | ||
|
|
b4c2f84ea0 | ||
|
|
c9f83c396f | ||
|
|
5a77578699 | ||
|
|
0fbe762391 | ||
|
|
85d22b4736 | ||
|
|
d1286469c3 | ||
|
|
de0cbf5a8b | ||
|
|
e24ebcfc0b |
@@ -1,12 +1,9 @@
|
|||||||
#ifndef Chessboard_H
|
#ifndef Chessboard_H
|
||||||
#define Chessboard_H
|
#define Chessboard_H
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <regex>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -14,20 +11,16 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../Player/Player.hpp"
|
#include "../Player/Player.hpp"
|
||||||
#include "../ChessPieces/ChessPieceColor.hpp"
|
#include "../ChessPieces/ChessPieceColor.hpp"
|
||||||
#include "../ChessPieces/ChessPieceMove.hpp"
|
|
||||||
#include "../ChessPieces/ChessPiecePosition.hpp"
|
#include "../ChessPieces/ChessPiecePosition.hpp"
|
||||||
|
|
||||||
class ChessPiece;
|
class ChessPiece;
|
||||||
|
|
||||||
class Chessboard {
|
class Chessboard {
|
||||||
private:
|
private:
|
||||||
std::vector<ChessPieceMove> _historyMoves;
|
|
||||||
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> _historyPositions;
|
|
||||||
std::map<ChessPiecePosition, ChessPiece*> chessboard;
|
std::map<ChessPiecePosition, ChessPiece*> chessboard;
|
||||||
|
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> history;
|
||||||
std::pair<Player*, Player*> players;
|
std::pair<Player*, Player*> players;
|
||||||
std::pair<bool, bool> draw;
|
|
||||||
Player* currentPlayer;
|
Player* currentPlayer;
|
||||||
void RemoveChessPiece(ChessPiecePosition position);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Board_ChessPiece {
|
struct Board_ChessPiece {
|
||||||
@@ -83,26 +76,20 @@ class Chessboard {
|
|||||||
{1, 'R', {'H', 1}}
|
{1, 'R', {'H', 1}}
|
||||||
};
|
};
|
||||||
~Chessboard();
|
~Chessboard();
|
||||||
std::vector<ChessPieceMove> GetHistoryMoves();
|
|
||||||
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> GetHistoryPositions();
|
|
||||||
void InitializeStartBoard();
|
void InitializeStartBoard();
|
||||||
void InitializeBoard(std::set<Board_ChessPiece> board);
|
void InitializeBoard(std::set<Board_ChessPiece> board);
|
||||||
//void SetChessPiece(std::unique_ptr<ChessPiece> piece);
|
//void SetChessPiece(std::unique_ptr<ChessPiece> piece);
|
||||||
void SetChessPiece(ChessPiece* chesspiece);
|
void SetChessPiece(ChessPiece* chesspiece);
|
||||||
bool IsDraw();
|
|
||||||
bool IsEmptyField(ChessPiecePosition* position);
|
bool IsEmptyField(ChessPiecePosition* position);
|
||||||
ChessPiece* GetChessPiece(ChessPiecePosition* position);
|
ChessPiece* GetChessPiece(ChessPiecePosition* position);
|
||||||
std::vector<ChessPiece*> GetChessPieces();
|
std::vector<ChessPiece*> GetChessPieces();
|
||||||
void UpdateChessPieces();
|
void UpdateChessPieces();
|
||||||
void MoveChessPiece(std::string move);
|
void MoveChessPiece(std::string move);
|
||||||
bool MoveCastling(ChessPieceColor color, bool shortCastling);
|
|
||||||
void SetToHistory(ChessPieceMove move);
|
|
||||||
void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition);
|
void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition);
|
||||||
int GetCountMoves();
|
int GetCountMoves();
|
||||||
bool HasMoves();
|
std::pair<ChessPiecePosition, ChessPiecePosition> GetLastMove();
|
||||||
std::pair<ChessPiecePosition, ChessPiecePosition> GetLastMovePositions();
|
|
||||||
bool IsCheckmate();
|
bool IsCheckmate();
|
||||||
bool IsInCheck();
|
bool IsCheck();
|
||||||
bool IsStalemate();
|
bool IsStalemate();
|
||||||
bool IsPositionUnderAttack(ChessPiecePosition position, ChessPieceColor color);
|
bool IsPositionUnderAttack(ChessPiecePosition position, ChessPieceColor color);
|
||||||
Player* GetCurrentPlayer();
|
Player* GetCurrentPlayer();
|
||||||
@@ -111,8 +98,6 @@ class Chessboard {
|
|||||||
void SwitchCurrentPlayer();
|
void SwitchCurrentPlayer();
|
||||||
Player* GetPlayer(ChessPieceColor color);
|
Player* GetPlayer(ChessPieceColor color);
|
||||||
ChessPiece* GetChessPieceKing(ChessPieceColor color);
|
ChessPiece* GetChessPieceKing(ChessPieceColor color);
|
||||||
bool ImportFilePGN(std::string filePath);
|
|
||||||
bool ExportFilePGN(std::string filePath);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
22
README.md
22
README.md
@@ -107,27 +107,13 @@
|
|||||||
- Startmenü
|
- Startmenü
|
||||||
- Spielmenü mit Historie, Kommand
|
- Spielmenü mit Historie, Kommand
|
||||||
- Plattformunabhängiges CMD clearing vor dem Zeichnen
|
- Plattformunabhängiges CMD clearing vor dem Zeichnen
|
||||||
|
- Spezialbewegung (Rochade, Umwandlung, En passant)
|
||||||
|
|
||||||
## Kompilieren und Ausführen
|
## Build
|
||||||
Um TurboSchach kompilieren zu können wird mindestens C++ 17 benötigt.
|
|
||||||
|
|
||||||
### Windows
|
|
||||||
|
|
||||||
```
|
```
|
||||||
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
|
g++ -o chess.exe main.cpp ChessPieces/*.cpp Chessboard/*.cpp Player/*.cpp Visualizer/*.cpp
|
||||||
```
|
```
|
||||||
# compile the project
|
|
||||||
make
|
|
||||||
|
|
||||||
# run the project
|
## Voraussetzungen
|
||||||
make run
|
|
||||||
|
|
||||||
# remove all output files
|
- C++ 17
|
||||||
make clean
|
|
||||||
```
|
|
||||||
34
main.cpp
34
main.cpp
@@ -1,7 +1,4 @@
|
|||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
|
||||||
#include <fstream>
|
|
||||||
#include "Player/Player.hpp"
|
#include "Player/Player.hpp"
|
||||||
#include "ChessPieces/ChessPiece.hpp"
|
#include "ChessPieces/ChessPiece.hpp"
|
||||||
#include "Chessboard/Chessboard.hpp"
|
#include "Chessboard/Chessboard.hpp"
|
||||||
@@ -68,8 +65,6 @@ void HandleFirstOption() {
|
|||||||
|
|
||||||
playView.DisplayElement();
|
playView.DisplayElement();
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::cout << "\x1B[u";
|
std::cout << "\x1B[u";
|
||||||
std::cin >> input;
|
std::cin >> input;
|
||||||
|
|
||||||
@@ -94,7 +89,6 @@ void HandleSecondOption() {}
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
#endif
|
|
||||||
|
|
||||||
BaseVisualizer::ClearTerminal();
|
BaseVisualizer::ClearTerminal();
|
||||||
|
|
||||||
@@ -156,34 +150,6 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
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;
|
std::vector<std::vector<ChessPiece>> chessmatrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user