-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.cc
141 lines (121 loc) · 4.31 KB
/
message.cc
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* message.cc
* This file is part of chess, a console chess engine.
* Copyright (C) 2023 Cyprien Lacassagne
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <fstream>
#include <sstream>
#ifdef _WIN32
#include <Windows.h>
#endif
#include "message.h"
#include "view.h"
void message::open_moves_win() {
#ifdef _WIN32
system("start pwsh -nop -nol "
"-c \"[console]::windowwidth=40; "
"[console]::windowheight=10; "
"[console]::bufferwidth=[console]::windowwidth; "
"[console]::title='Move History'; "
"gc moves_history.txt -Wait\"");
HWND handle = FindWindow(NULL, "Move History");
SetWindowPos(handle, NULL, 40, 50, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
#elif __linux__
system("chmod u+x mv_hist && "
"gnome-terminal --geometry=60x10+500+400 -- ./mv_hist");
#endif
}
void message::write_to_history(Move move, bool w_ply, int num, bool cap, bool chk,
bool chkmt) {
std::ofstream log;
log.open(moves_history_file, std::ios_base::app);
if (w_ply)
log << num << ". ";
if (move.piece != 'P' && move.piece != 'p')
log << move.piece;
else if (cap)
log << move.start.file;
if (cap)
log << 'x';
log << move.target.file << move.target.rank;
if (move.prom != blank)
log << '=' << move.prom;
if (chkmt)
log << '#';
else if (chk)
log << '+';
log << " ";
if (num % 4 == 0 && !w_ply)
log << "\n";
}
void message::erase_history_data() {
std::ofstream log;
log.open(moves_history_file);
log << "";
}
void message::illegal_move(std::wstring move) {
std::wcout << msg_color << "Illegal move : " << reset_sgr << move << "\n";
}
void message::illegal_move(char file, int rank, char piece) {
std::wcout << msg_color << "Illegal move : " << reset_sgr;
if (piece != 'P' && piece != 'p')
std::wcout << piece;
std::wcout << file << rank << "\n";
}
void message::ambigueous_move(char file, int rank, char piece) {
std::wcout << msg_color << "Ambigueous move : " << reset_sgr;
if (piece != 'P' && piece != 'p')
std::wcout << piece;
std::wcout << file << rank << "\n";
}
void message::white_resigns() {
std::wcout << msg_color << "White resigns" << reset_sgr << "\t0-1" << "\n";
}
void message::black_resigns() {
std::wcout << msg_color << "Black resigns" << reset_sgr << "\t1-0" << "\n";
}
void message::checkmate(bool w_ply) {
std::wcout << msg_color << "Checkmate" << reset_sgr;
std::wcout << "\t" << (w_ply ? "1-0" : "0-1") << "\n";
}
void message::stalemate() {
std::wcout << msg_color << "Stalemate" << reset_sgr << L"\t\u00BD-\u00BD\n";
}
void message::draw() {
std::wcout << msg_color << "Draw" << reset_sgr << L"\t\t\u00BD-\u00BD\n";
}
void message::capture_error(char file, int rank) {
std::wcout << msg_color << "There is nothing to capture on " << reset_sgr
<< file << rank << "\n";
}
void message::invalid_san(std::wstring bad_SAN) {
std::wcout << "Incorrect command\n";
}
void message::fen_parsing_error() {
std::wcout << "Error: failed parsing the FEN file: wrong format.\n";
}
void message::fen_file_not_found(std::string filename) {
#ifdef _WIN32
std::wcout << "Error: failed opening the file.\n";
#else
std::cout << "Error: failed opening the file \"" << filename << "\".\n";
#endif
}
void message::bad_extension(std::string filename) {
#ifdef _WIN32
std::wcout << "Error: the specified file is not in FEN format.\n";
#else
std::cout << "Error: \"" << filename << "\" is not an FEN file.\n";
#endif
}