-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (66 loc) · 1.79 KB
/
main.cpp
File metadata and controls
79 lines (66 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <cstdint>
#include <sstream>
#include <string>
#include <array>
#include <stdexcept>
#include "Board.h"
#include "Move.h"
#include "MoveType.h"
#include "Engine.h"
std::string squareToString(int square) {
char file = static_cast<char>('a' + (square % 8));
char rank = static_cast<char>('1' + (square / 8));
std::string result;
result += file;
result += rank;
return result;
}
char promotionPieceToChar(int promotionPiece) {
switch (static_cast<Piece>(promotionPiece)) {
case Piece::WQ:
case Piece::BQ:
return 'q';
case Piece::WR:
case Piece::BR:
return 'r';
case Piece::WB:
case Piece::BB:
return 'b';
case Piece::WN:
case Piece::BN:
return 'n';
default:
return '\0';
}
}
std::string moveToString(const Move& move) {
std::string result = squareToString(move.from) + squareToString(move.to);
if (move.type == MoveType::Promotion ||
move.type == MoveType::PromotionCapture) {
char promo = promotionPieceToChar(move.promotion_piece);
if (promo != '\0') {
result += promo;
}
}
return result;
}
int main(int argc, char* argv[]) {
Board board;
std::string startFen =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
try {
board.parse_fen(startFen);
std::cout << "Starting position:\n";
board.print_board();
std::vector<Move> legalMoves = board.generateLegalMoves();
std::cout << "\nLegal move count: " << legalMoves.size() << "\n\n";
for (const Move& move : legalMoves) {
std::cout << moveToString(move) << '\n';
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
return 1;
}
return 0;
}