Compare commits

..

2 Commits

14 changed files with 350 additions and 61 deletions

View File

@@ -161,3 +161,11 @@ bool ChessPieceMove::IsLongCastling() {
bool ChessPieceMove::IsShortCastling() { bool ChessPieceMove::IsShortCastling() {
return this->_castling == "0-0"; return this->_castling == "0-0";
} }
/**
* Gets the move of the chess piece as string value.
* @return The move of the chess piece as string value.
*/
std::string ChessPieceMove::ToString() {
return (this->IsValidShortNotation()) ? this->_move : "";
}

View File

@@ -36,6 +36,7 @@ class ChessPieceMove {
bool IsCheck(); bool IsCheck();
bool IsCheckmate(); bool IsCheckmate();
bool IsEnPassant(); bool IsEnPassant();
std::string ToString();
}; };
#endif #endif

View File

@@ -3,7 +3,6 @@
#include "../ChessPieces/Queen.hpp" #include "../ChessPieces/Queen.hpp"
#include "../ChessPieces/Bishop.hpp" #include "../ChessPieces/Bishop.hpp"
#include "../ChessPieces/Knight.hpp" #include "../ChessPieces/Knight.hpp"
#include "../ChessPieces/ChessPieceMove.hpp"
#include "../ChessPieces/ChessPiece.hpp" #include "../ChessPieces/ChessPiece.hpp"
/** /**
@@ -18,7 +17,7 @@ Player* Chessboard::GetCurrentPlayer() {
* Gets the history of all moves. * Gets the history of all moves.
* @return The history of all moves. * @return The history of all moves.
*/ */
std::vector<std::string> Chessboard::GetHistoryMoves() { std::vector<ChessPieceMove> Chessboard::GetHistoryMoves() {
return this->_historyMoves; return this->_historyMoves;
} }
@@ -62,6 +61,64 @@ bool Chessboard::HasMoves() {
return this->_historyMoves.size() > 0; return this->_historyMoves.size() > 0;
} }
/**
* Load the chessboard from a PGN file.
* @param filePath The file path of the PGN file to load.
* @return The status whether the PGN file was loaded successfully.
*/
bool Chessboard::ImportFilePGN(std::string filePath) {
std::ifstream pgnFile(filePath);
std::regex rgxMetaInfo = std::regex("^[\\[]([A-Za-z]+) [\"](.*)[\"][\\]]$");
std::regex rgxMoveInfo = std::regex("(?:([RNBQKP]?)([a-h]?)([1-8]?)(x?)([a-h])([1-8])((?:[=])?[QRBN])?|(O-O(?:-O)?)|(\\(=\\)))([+#!?]| e.p.)*");
if (pgnFile.is_open()) {
Player* playerWhite;
Player* playerBlack;
int expectedNumberOfMoves = 0;
std::vector<std::string> moves;
for(std::string line; getline(pgnFile, line);) {
std::smatch parts;
if (std::regex_search(line, parts, rgxMetaInfo)) {
std::string metaName = parts[1].str();
std::string metaValue = parts[2].str();
if (metaName == "White") {
playerWhite = new Player(metaValue);
playerWhite->SetColor(ChessPieceColor::White);
} else if (metaName == "Black") {
playerBlack = new Player(metaValue);
playerBlack->SetColor(ChessPieceColor::Black);
} else if (metaName == "PlyCount") {
expectedNumberOfMoves = std::stoi(metaValue);
}
} else {
for (std::sregex_iterator rgxIterator = std::sregex_iterator(line.begin(), line.end(), rgxMoveInfo); rgxIterator != std::sregex_iterator(); ++rgxIterator) {
parts = *rgxIterator;
moves.push_back(parts[0].str());
}
}
}
pgnFile.close();
if (expectedNumberOfMoves != moves.size()) {
return false;
}
this->players = {playerBlack, playerWhite};
for (std::string move : moves) {
this->MoveChessPiece(move);
}
return true;
} else {
return false;
}
}
/** /**
* Status whether the king of the current player is in checkmate. * Status whether the king of the current player is in checkmate.
* @return Status whether the king of the current player is in checkmate. * @return Status whether the king of the current player is in checkmate.
@@ -211,7 +268,7 @@ void Chessboard::SetChessPiece(ChessPiece* chesspiece) {
* Sets the move to the history. * Sets the move to the history.
* @param move The move to be added to the history. * @param move The move to be added to the history.
*/ */
void Chessboard::SetToHistory(std::string move) { void Chessboard::SetToHistory(ChessPieceMove move) {
this->_historyMoves.push_back(move); this->_historyMoves.push_back(move);
} }
@@ -449,7 +506,7 @@ void Chessboard::MoveChessPiece(std::string move) {
} }
} }
this->SetToHistory(move); this->SetToHistory(chessPieceMove);
this->UpdateChessPieces(); this->UpdateChessPieces();
this->SwitchCurrentPlayer(); this->SwitchCurrentPlayer();
} }
@@ -565,3 +622,44 @@ ChessPiece* Chessboard::GetChessPieceKing(ChessPieceColor color) {
return chessPieceKing; return chessPieceKing;
} }
bool Chessboard::ExportFilePGN(std::string filePath) {
std::string moveList;
std::vector<ChessPieceMove> moves = this->GetHistoryMoves();
time_t timestamp = time(NULL);
struct tm datetime = *localtime(&timestamp);
char output[50];
strftime(output, 50, "%Y.%m.%d", &datetime);
/**
[Result "1/2-1/2"]
[ECO "A29"]
[WhiteElo "2750"]
[BlackElo "2595"]
[PlyCount "155"]
*/
moveList.append("[Date \"").append(output).append("\"]").append("\n");
moveList.append("[White \"").append(this->GetPlayer(ChessPieceColor::White)->GetName()).append("\"]").append("\n");
moveList.append("[Black \"").append(this->GetPlayer(ChessPieceColor::Black)->GetName()).append("\"]").append("\n");
for (int moveIndex = 0; moveIndex < moves.size() - 1; moveIndex++) {
if (moveIndex % 6 == 0) {
moveList.append("\n");
}
if (moveIndex % 2 == 0) {
moveList.append(std::to_string((moveIndex / 2) + 1)).append(".");
}
moveList.append(" ").append(moves[moveIndex].ToString()).append(" ");
}
std::cout << moveList;
return true;
}

View File

@@ -1,6 +1,8 @@
#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>
@@ -10,13 +12,14 @@
#include <vector> #include <vector>
#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<std::string> _historyMoves; std::vector<ChessPieceMove> _historyMoves;
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> _historyPositions; std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> _historyPositions;
std::map<ChessPiecePosition, ChessPiece*> chessboard; std::map<ChessPiecePosition, ChessPiece*> chessboard;
std::pair<Player*, Player*> players; std::pair<Player*, Player*> players;
@@ -25,7 +28,7 @@ class Chessboard {
public: public:
~Chessboard(); ~Chessboard();
std::vector<std::string> GetHistoryMoves(); std::vector<ChessPieceMove> GetHistoryMoves();
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> GetHistoryPositions(); std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> GetHistoryPositions();
void SetChessPiece(ChessPiece* chesspiece); void SetChessPiece(ChessPiece* chesspiece);
bool IsEmptyField(ChessPiecePosition* position); bool IsEmptyField(ChessPiecePosition* position);
@@ -34,7 +37,7 @@ class Chessboard {
void UpdateChessPieces(); void UpdateChessPieces();
void MoveChessPiece(std::string move); void MoveChessPiece(std::string move);
bool MoveCastling(ChessPieceColor color, bool shortCastling); bool MoveCastling(ChessPieceColor color, bool shortCastling);
void SetToHistory(std::string move); void SetToHistory(ChessPieceMove move);
void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition); void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition);
int GetCountMoves(); int GetCountMoves();
bool HasMoves(); bool HasMoves();
@@ -49,6 +52,8 @@ 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

27
chessgames/1229276.pgn Normal file
View File

@@ -0,0 +1,27 @@
[Event "Bosna 21st"]
[Site "Sarajevo YUG"]
[Date "1982.??.??"]
[EventDate "1983.03.00"]
[Round "?"]
[Result "0-1"]
[White "Vitomir Arapovic"]
[Black "Alexander Beliavsky"]
[ECO "C26"]
[WhiteElo "?"]
[BlackElo "?"]
[PlyCount "150"]
1.e4 e5 2.Nc3 Nf6 3.Bc4 Bc5 4.d3 O-O 5.Nf3 Re8 6.Ng5 Re7 7.O-O
h6 8.Nf3 c6 9.d4 exd4 10.e5 Ne8 11.Nxd4 d5 12.exd6 Nxd6 13.Bb3
Na6 14.Be3 Qe8 15.Qf3 Bxd4 16.Bxd4 Nf5 17.Rad1 Bd7 18.Qh5 b6
19.Qg6 Nxd4 20.Rxd4 Nc5 21.Bc4 Be6 22.Qg3 Bxc4 23.Rxc4 Rd8
24.Rg4 f5 25.Rg6 Rd4 26.Rd6 f4 27.Qg6 Qxg6 28.Rxg6 Ne6 29.h4
h5 30.g4 fxg3 31.Rxg3 Rf7 32.Re1 Nc5 33.Re8+ Kh7 34.Rg5 Rxh4
35.b4 Nd7 36.Ne4 Nf6 37.Nxf6+ Rxf6 38.Re7 Rg6 39.Rxg6 Kxg6
40.Re6+ Kh7 41.a3 Rc4 42.Re7 Rxc2 43.Rxa7 Rc4 44.Kg2 b5 45.Ra6
g6 46.Ra8 Kh6 47.Rh8+ Kg5 48.Rg8 Kf5 49.Rf8+ Kg4 50.Rf6 g5
51.Rf8 Rc3 52.Ra8 h4 53.a4 h3+ 54.Kh2 Rc2 55.Kg1 Rb2 56.axb5
cxb5 57.Ra3 Kh4 58.Rd3 Rxb4 59.Kh2 g4 60.Rd5 Rb2 61.Kg1 Rb1+
62.Kh2 Rf1 63.Rxb5 Rxf2+ 64.Kg1 Rc2 65.Rb4 Re2 66.Ra4 Kg3
67.Ra1 Re3 68.Kh1 Kf3 69.Rf1+ Ke2 70.Rf8 g3 71.Kg1 Re4 72.Rh8
Kf3 73.Rf8+ Rf4 74.Rg8 Rf7 75.Rh8 h2+ 0-1

29
chessgames/1258478.pgn Normal file
View File

@@ -0,0 +1,29 @@
[Event "Wch-blitz"]
[Site "Saint John CAN"]
[Date "1988.02.20"]
[EventDate "1988.02.19"]
[Round "3"]
[Result "1/2-1/2"]
[White "Garry Kasparov"]
[Black "Kiril Dimitrov Georgiev"]
[ECO "A29"]
[WhiteElo "2750"]
[BlackElo "2595"]
[PlyCount "155"]
1. c4 e5 2. Nc3 Nf6 3. Nf3 Nc6 4. g3 d5 5. cxd5 Nxd5 6. Bg2
Nb6 7. O-O Be7 8. a3 a5 9. d3 O-O 10. Be3 Be6 11. Na4 Nd5
12. Bc5 Bd6 13. Rc1 h6 14. Nd2 Rc8 15. Ne4 b6 16. Nxd6 cxd6
17. Bxb6 Nxb6 18. Rxc6 Rb8 19. Nxb6 Rxb6 20. Qc2 Qb8 21. Rxb6
Qxb6 22. Rb1 Bb3 23. Qd2 Rb8 24. Rc1 Be6 25. Rc2 d5 26. h4 a4
27. Bf3 Qd4 28. e3 Qb6 29. d4 e4 30. Be2 Qb3 31. Kg2 g6
32. Bd1 Kg7 33. Qc1 Qb6 34. Rd2 Bd7 35. Qc5 Qxc5 36. dxc5 Bc6
37. Kf1 Kf6 38. Ke1 Ke5 39. Rc2 Rb5 40. Kd2 d4 41. exd4+ Kxd4
42. Be2 Rxc5 43. Rxc5 Kxc5 44. Ke3 f5 45. g4 Kd5 46. gxf5 gxf5
47.Kf4 Ke6 48. Bc4+ Kf6 49. b4 axb3 50. Bxb3 Bb5 51.a4 Ba6
52.Bd5 Bc8 53.Bc6 Ke6 54.Bb5 Kd6 55. Bf1 Kc5 56.Bh3 Kb4
57.Bxf5 Ba6 58.Bxe4 Kxa4 59.Ke5 Kb4 60. f4 Kc5 61.f5 Bc4 62.f6
Bf7 63.Bf5 Kc6 64.Be6 Bg6 65.f7 Bxf7 66. Bxf7 Kd7 67.Kf6 Kd6
68.h5 Kd7 69.Kg6 Ke7 70.Ba2 Ke8 71. Kxh6 Kf8 72.Kg6 Ke7 73.h6
Kd6 74.h7 Kc5 75.h8=Q Kb4 76. Qd4+ Kb5 77.Bd5 Ka6 78.Qc5
1/2-1/2

22
chessgames/1284086.pgn Normal file
View File

@@ -0,0 +1,22 @@
[Event "Alicante"]
[Site "Spain"]
[Date "1992.??.??"]
[EventDate "?"]
[Round "7"]
[Result "1/2-1/2"]
[White "Stephen Boyd"]
[Black "Torbjorn Glimbrant"]
[ECO "C49"]
[WhiteElo "2265"]
[BlackElo "2235"]
[PlyCount "91"]
1.e4 e5 2.Nf3 Nc6 3.Nc3 Nf6 4.Bb5 Bb4 5.O-O O-O 6.d3 d6 7.Bg5
Bxc3 8.bxc3 Qe7 9.Re1 Nd8 10.d4 h6 11.Bc1 a6 12.Bd3 Bg4 13.h3
Bd7 14.a4 a5 15.Nh4 Nc6 16.Nf5 Bxf5 17.exf5 Qd7 18.g4 exd4
19.cxd4 Nxd4 20.Bb2 c5 21.Bxd4 cxd4 22.Bb5 Qc7 23.Qxd4 d5
24.Re2 Rad8 25.Rae1 Rd6 26.Re7 Qxc2 27.Rxb7 Ne4 28.Re2 Qc1+
29.Kg2 Qc8 30.Re7 Qd8 31.Qa7 Nf6 32.Rc7 d4 33.Ree7 d3 34.Rxf7
Rxf7 35.Rxf7 d2 36.Rxg7+ Kh8 37.Be2 d1=Q 38.Bxd1 Rxd1 39.Rg6
Qd5+ 40.Kg3 Rd3+ 41.Kh4 Rxh3+ 42.Kxh3 Qh1+ 43.Kg3 Nh5+ 44.gxh5
Qf3+ 45.Kh2 Qg2+ 46.Kxg2 1/2-1/2

21
chessgames/1348060.pgn Normal file
View File

@@ -0,0 +1,21 @@
[Event "Norwegian Championship"]
[Site "Sandnes NOR"]
[Date "2005.07.05"]
[EventDate "2005.07.??"]
[Round "5"]
[Result "1-0"]
[White "Magnus Carlsen"]
[Black "Geir Sune Tallaksen Ostmoe"]
[ECO "E15"]
[WhiteElo "2528"]
[BlackElo "2349"]
[PlyCount "73"]
1. Nf3 Nf6 2. c4 e6 3. d4 b6 4. g3 Ba6 5. b3 b5 6. cxb5 Bxb5
7. Bg2 d5 8. O-O Nbd7 9. Nc3 Ba6 10. Re1 Bd6 11. Bb2 O-O
12. e4 Nxe4 13. Nxe4 dxe4 14. Rxe4 Bb7 15. Rh4 Be7 16. Rh3 Nf6
17. Qe2 Bd5 18. Re1 Qb8 19. Ne5 Qb7 20. Bxd5 Qxd5 21. Qc2 c5
22. Ng4 h6 23. Re5 Qf3 24. Nxh6+ gxh6 25. Rxh6 Kg7 26. Rg5+
Kxh6 27. Bc1 cxd4 28. Rg4+ Qe3 29. Rh4+ Nh5 30. Rxh5+ Kxh5
31. Qh7+ Kg4 32. fxe3 Rac8 33. Kg2 Rxc1 34. h3+ Kg5 35. Qg7+
Kf5 36. g4+ Ke4 37. Qxd4# 1-0

31
chessgames/1427255.pgn Normal file
View File

@@ -0,0 +1,31 @@
[Event "Youth - Experience"]
[Site "Amsterdam NED"]
[Date "2006.08.27"]
[EventDate "2006.08.19"]
[Round "8"]
[Result "1/2-1/2"]
[White "Ulf Andersson"]
[Black "Daniel Stellwagen"]
[ECO "A04"]
[WhiteElo "2542"]
[BlackElo "2575"]
[PlyCount "175"]
1. Nf3 f5 2. d4 g6 3. g3 Bg7 4. Bg2 Nf6 5. O-O O-O 6. c4 d6
7. Nc3 Qe8 8. d5 a5 9. Nd4 Na6 10. e4 fxe4 11. Nxe4 Nxe4
12. Bxe4 Bh3 13. Re1 Nc5 14. Bh1 Qf7 15. Be3 Rae8 16. Qd2 b6
17. b3 Kh8 18. Rad1 e5 19. dxe6 Nxe6 20. Bd5 Nxd4 21. Bxd4 Qd7
22. a3 Bxd4 23. Qxd4+ Qg7 24. Qxg7+ Kxg7 25. Bc6 Rxe1+
26. Rxe1 g5 27. f3 Bf5 28. Kf2 Kf6 29. b4 axb4 30. axb4 Be6
31. Re4 Bf5 32. Rd4 Rf7 33. b5 Re7 34. Bd5 Be6 35. f4 Bxd5
36. fxg5+ Kxg5 37. Rxd5+ Kg6 38. Kf3 Re1 39. h4 h5 40. Rg5+
Kh6 41. g4 hxg4+ 42. Rxg4 Re5 43. Rd4 Rc5 44. Ke4 Kg6 45. Kd3
Rh5 46. Rg4+ Kf6 47. Kd4 Ke6 48. Re4+ Kf6 49. Rg4 Ke6 50. Rf4
Ke7 51. Ke4 Re5+ 52. Kf3 d5 53. Rd4 Re1 54. Rxd5 Rc1 55. Rd4
Kf6 56. Ke4 Ke6 57. Kd3 Rd1+ 58. Kc3 Rc1+ 59. Kd2 Rh1 60. Re4+
Kf6 61. Ke3 Rc1 62. Rg4 Kf5 63. Rg5+ Kf6 64. Kd4 Rh1 65. Rg4
Ke6 66. Ke4 Re1+ 67. Kf3 Rc1 68. Ke3 Kf5 69. Rd4 Ke5 70. Rd5+
Ke6 71. Kd3 Rd1+ 72. Ke4 Rh1 73. h5 Rh4+ 74. Kd3 Rh3+ 75. Kd4
Rh4+ 76. Kc3 Rh3+ 77. Kb4 Rg3 78. Rd8 Rh3 79. Rh8 Kd7 80. h6
c5+ 81. bxc6+ Kxc6 82. Rh7 Rh4 83. Kb3 Kc5 84. Rc7+ Kd6
85. Rh7 Kc5 86. Rc7+ Kd6 87. Rb7 Kc6 88. Rh7 1/2-1/2

29
chessgames/1482551.pgn Normal file
View File

@@ -0,0 +1,29 @@
[Event "Gibraltar Chess Festival"]
[Site "Gibraltar ENG"]
[Date "2008.01.23"]
[EventDate "2008.01.22"]
[Round "2"]
[Result "1-0"]
[White "Tim Jaksland"]
[Black "Line Jin Jorgensen"]
[ECO "C01"]
[WhiteElo "2294"]
[BlackElo "1867"]
[PlyCount "149"]
1. e4 e6 2. d4 d5 3. exd5 exd5 4. Nf3 Nf6 5. Bd3 Bd6 6. O-O
O-O 7. c4 c6 8. Nc3 Bg4 9. h3 Bh5 10. Re1 dxc4 11. Bxc4 Qc7
12. g4 Bg6 13. Ne5 Nfd7 14. f4 Nxe5 15. dxe5 Bc5+ 16. Kg2 h6
17. f5 Bh7 18. Qf3 Kh8 19. Bf4 b5 20. Bb3 Qb6 21. Rad1 a5
22. a4 Ra7 23. Re2 b4 24. Ne4 Bd4 25. Rxd4 Qxd4 26. Rd2 Qb6
27. Be3 Qc7 28. Bc5 Nd7 29. Rxd7 Qxd7 30. Bxf8 Qd4 31. Bc5
Qxb2+ 32. Qf2 Qxf2+ 33. Kxf2 Rd7 34. Nd6 Bg8 35. Ke3 Re7
36. Kf4 Rxe5 37. Kxe5 f6+ 38. Kd4 Bxb3 39. Bb6 Bxa4 40. Bxa5
h5 41. gxh5 Bd1 42. h6 b3 43. hxg7+ Kxg7 44. Bc3 Kh6 45. Ke4
Kh5 46. Bxf6 b2 47. Bxb2 Kh4 48. f6 Bb3 49. Ke5 Kxh3 50. f7
Bxf7 51. Nxf7 c5 52. Nd6 c4 53. Kf4 c3 54. Bxc3 Kg2 55. Ne4
Kh2 56. Kf3 Kg1 57. Nf2 Kh2 58. Be5+ Kg1 59. Bd6 Kf1 60. Bh2
Ke1 61. Ne4 Kf1 62. Nd2+ Ke1 63. Ke3 Kd1 64. Kd3 Ke1 65. Bg3+
Kd1 66. Bf2 Kc1 67. Nc4 Kd1 68. Nb2+ Kc1 69. Kc3 Kb1 70. Kb3
Ka1 71. Be3 Kb1 72. Bf4 Ka1 73. Nc4 Kb1 74. Na3+ Ka1 75. Be5+
1-0

18
chessgames/1588906.pgn Normal file
View File

@@ -0,0 +1,18 @@
[Event "BCF-ch 87th"]
[Site "Street ENG"]
[Date "2000.08.09"]
[EventDate "2000.07.31"]
[Round "9"]
[Result "0-1"]
[White "Jack Rudd"]
[Black "Martin Simons"]
[ECO "B01"]
[WhiteElo "2176"]
[BlackElo "2226"]
[PlyCount "40"]
1. e4 d5 2. exd5 Nf6 3. c4 e6 4. dxe6 Bxe6 5. d4 Bb4+ 6. Bd2
Bxd2+ 7. Qxd2 Qe7 8. Qe2 Nc6 9. Nf3 O-O-O 10. d5 Rhe8 11. Kd1
Nxd5 12. cxd5 Bxd5 13. Nfd2 Qf6 14. Qd3 Bxg2 15. Qg3 Bxh1
16. Nc3 Bf3+ 17. Kc1 Re1+ 18. Kc2 Nd4+ 19. Kd3 Nb3+ 20. Kc2
Nxa1# 0-1

21
chessgames/1775611.pgn Normal file
View File

@@ -0,0 +1,21 @@
[Event "Isle of Man Masters"]
[Site "Douglas IMN"]
[Date "2014.10.11"]
[EventDate "2014.10.04"]
[Round "8.2"]
[Result "0-1"]
[White "Gabriel Sargissian"]
[Black "Nigel Short"]
[ECO "A70"]
[WhiteElo "2690"]
[BlackElo "2646"]
[PlyCount "78"]
1. d4 Nf6 2. c4 e6 3. Nf3 c5 4. d5 exd5 5. cxd5 d6 6. Nc3 g6
7. Bf4 a6 8. a4 Bg7 9. h3 O-O 10. e3 Ne8 11. Be2 Nd7 12. O-O
Rb8 13. Nd2 Ne5 14. a5 f5 15. Bg3 Bd7 16. Qb3 b5 17. axb6 Rxb6
18. Qc2 Bb5 19. Nxb5 axb5 20. Nb3 g5 21. Na5 f4 22. Bh2 Nc7
23. Rfd1 Kh8 24. Qe4 Qf6 25. exf4 gxf4 26. Nb3 Na6 27. Nd2 c4
28. Qb1 Nc5 29. Ne4 Nxe4 30. Qxe4 Rb7 31. Ra5 Nd7 32. b4 cxb3
33. Bd3 Qh6 34. Qb4 Nc5 35. Bb1 Be5 36. Rxb5 Rg7 37. Be4 Nxe4
38. Qxe4 Qxh3 39. Kh1 Qh5 0-1

19
chessgames/1799484.pgn Normal file
View File

@@ -0,0 +1,19 @@
[Event "Russian Championship Superfinal"]
[Site "Chita RUS"]
[Date "2015.08.12"]
[EventDate "2015.08.09"]
[Round "4"]
[Result "0-1"]
[White "Peter Svidler"]
[Black "Denis Khismatullin"]
[ECO "B91"]
[WhiteElo "2739"]
[BlackElo "2642"]
[PlyCount "58"]
1. e4 c5 2. Nc3 a6 3. Nge2 d6 4. g3 g6 5. d4 cxd4 6. Nxd4 Bg7
7. Bg2 Nf6 8. b3 O-O 9. Bb2 Bd7 10. Qd2 Nc6 11. Nde2 b5
12. O-O-O Ng4 13. Rdf1 Qa5 14. h3 Nf6 15. Kb1 b4 16. Nd1 Qc7
17. Ne3 a5 18. f4 a4 19. e5 dxe5 20. fxe5 Nxe5 21. Bxa8 Rxa8
22. Rf4 axb3 23. axb3 Qa7 24. Nd4 Nh5 25. Nd5 Bc6 26. Nxc6
Qa2+ 27. Kc1 Qa1+ 28. Bxa1 Rxa1+ 29. Kb2 Nc4# 0-1

View File

@@ -76,61 +76,21 @@ int main(int argc, char* argv[]) {
ChessboardVisualizerGraphic* visualizer = new ChessboardVisualizerGraphic(); ChessboardVisualizerGraphic* visualizer = new ChessboardVisualizerGraphic();
visualizer->Draw(&chessboard); visualizer->Draw(&chessboard);
// chessgames.com/1649097 // Import chessboard from PGN file.
// https://www.chessgames.com/perl/chessgame?gid=1649097 // https://www.chessgames.com/perl/chessgame?gid=1799484
// // 1588906 - Checkmate
//1258478 - Stalemate // 1482551 - Checkmate
//std::ifstream input("C:\\Users\\Sebastian Brosch\\Desktop\\2767717.pgn"); // 1348060 - Checkmate
// std::ifstream input("C:\\Users\\Sebastian Brosch\\Desktop\\1258478.pgn"); // 1799484 - Checkmate
// //std::ifstream input("2767713.pgn"); // 1284086 - Stalemate
// //std::ifstream input("1482706.pgn"); // 1258478 - Stalemate
// //std::ifstream input("1693032.pgn"); // 1229276 - En Passant (black fxg3)
// //std::ifstream input("1272702.pgn"); // 1775611 - En Passant (white axb6)
// //std::ifstream input("2446807.pgn"); // 1427255 - En Passant (white bxc6+ and dxe6)
// //std::ifstream input("1884783.pgn"); chessboard.ImportFilePGN("./chessgames/1258478.pgn");
// std::regex moves_regex("([0-9]+.)(?:\n| )?([A-Za-z][A-Za-z0-9+#-=]+)(?:\n| )?([A-Za-z][A-Za-z0-9+#-]+)?"); visualizer->Draw(&chessboard);
// std::smatch moves_matches;
// std::string moves_content;
// for (std::string line; getline(input, line);) {
// if (line[0] == '[') {
// // Info
// } else {
// moves_content.append((moves_content == "") ? "" : " ").append(line);
// }
// }
// std::regex_search(moves_content, moves_matches, moves_regex);
// std::vector<std::string> moves;
// for(std::sregex_iterator i = std::sregex_iterator(moves_content.begin(), moves_content.end(), moves_regex); i != std::sregex_iterator(); ++i) { while (chessboard.IsCheckmate() == false && chessboard.IsStalemate() == false) {
// std::smatch m = *i;
// if (m[2].str() != "") {
// moves.push_back(m[2].str());
// }
// if (m[3].str() != "") {
// moves.push_back(m[3].str());
// }
// }
// int move_count = 0;
// while (chessboard.IsCheckmate() == false) {
// move_count++;
// std::string move = moves.front();
// moves.erase(moves.begin());
// chessboard.MoveChessPiece(move);
// visualizer->Draw(&chessboard);
// std::cout << "SPIELZUG: " << move << " | " << move_count << std::endl;
// if (moves.size() == 0) {
// break;
// }
// }
// std::cout << std::endl;
// std::cout << "Game is over! - " << ((chessboard.GetOpponentPlayer()->GetColor() == ChessPieceColor::White) ? "White" : "Black") << " has won the game!" << std::endl;
// return 0;
while (chessboard.IsCheckmate() == false) {
std::string move; std::string move;
std::cout << "Move [" << ((chessboard.GetCurrentPlayer()->GetColor() == ChessPieceColor::White) ? "White" : "Black") << "] : "; std::cout << "Move [" << ((chessboard.GetCurrentPlayer()->GetColor() == ChessPieceColor::White) ? "White" : "Black") << "] : ";
std::cin >> move; std::cin >> move;