-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.cpp
More file actions
114 lines (102 loc) · 3.67 KB
/
Copy pathHelper.cpp
File metadata and controls
114 lines (102 loc) · 3.67 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Created by Julius on 02/03/2024.
//
#include <map>
#include "Helper.h"
namespace Engine {
std::string toCoordinates(int index) {
int row = (index / 8); // Calculate row (rank) from index
int col = index % 8; // Calculate column (file) from index
// Convert row and column to chess coordinates (e.g ., a1, b2, ..., h8)
char file = 'a' + col;
char rank = '1' + row;
// Return the chess coordinate string
return std::string(1, file) + std::string(1, rank);
}
int toIndex(const std::string& square) {
int file = square[0] - 'a'; // Convert the file (letter) to a number (0-7)
int rank = square[1] - '1'; // Convert the rank (number) to a number (0-7)
return rank * 8 + file; // Calculate the board index
}
std::tuple<int, int, int> toMove(const std::string& moveString){
// if(moveString == "O-O"){
// return 6 | (4 << 6) |
// }
// if(moveString == "o-o"){
//
// }
// if(moveString == "O-O-O"){
//
// }
// if(moveString == "o-o-o"){
//
// }
int from = ((moveString[0] - 'a') + ((moveString[1] - '1') * 8));
int to = (moveString[2] - 'a') + ((moveString[3] - '1') * 8);
int promotion = 0;
if (moveString.length() == 5) {
switch (moveString[4]) {
case 'n':
promotion = 8; // Knight
break;
case 'b':
promotion = 9; // Bishop
break;
case 'r':
promotion = 10; // Rook
break;
case 'q':
promotion = 11; // Queen
break;
default:
break;
}
}
return std::make_tuple(from, to, promotion);
}
void drawBitboard(Bitboard bitboard) {
std::cout << "=======================" <<std::endl;
for (int i = 7; i >= 0; --i) {
for (int j = 0; j < 8; ++j) {
std::cout << " " + std::to_string(test(bitboard,i*8+j)) + " ";//?
}
std::cout << std::endl;
}
}
void printMove(Move move){
// static std::map<Piece, std::string> pieceNames = {
// {Piece::WHITE_KING, "White King"},
// {Piece::WHITE_QUEEN, "White Queen"},
// {Piece::WHITE_ROOK, "White Rook"},
// {Piece::WHITE_BISHOP, "White Bishop"},
// {Piece::WHITE_KNIGHT, "White Knight"},
// {Piece::WHITE_PAWN, "White Pawn"},
// {Piece::BLACK_KING, "Black King"},
// {Piece::BLACK_QUEEN, "Black Queen"},
// {Piece::BLACK_ROOK, "Black Rook"},
// {Piece::BLACK_BISHOP, "Black Bishop"},
// {Piece::BLACK_KNIGHT, "Black Knight"},
// {Piece::BLACK_PAWN, "Black Pawn"}
// };
if(move ==0){
std::cout <<"null move"<< std::endl;
}
else if(move & (1 <<14)) {
std::cout << "capture from " + toCoordinates((move >> 6) & 0x3f) + " to " + toCoordinates(move & 0x3f)<< std::endl;
}
else{
std::cout << "move from " + toCoordinates((move >> 6) & 0x3f) + " to " + toCoordinates(move & 0x3f)<< std::endl;
}
// for (int i = 32 - 1; i >= 0; --i) {
// // Check if the i-th bit is set
// if (move & (1 << i)) {
// std::cout << "1";
// } else {
// std::cout << "0";
// }
//
// // Add spacing for better readability
// }
std::cout << std::endl;
}
} // Helper