refactor: Rename gameRecords to moveHistory
This commit is contained in:
parent
6022591e99
commit
2d1ed84be4
|
@ -1312,7 +1312,7 @@ void Position::reset_bb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Position::mirror(vector <string> &moveRecords, bool cmdChange /*= true*/)
|
void Position::mirror(vector <string> &moveHistory, bool cmdChange /*= true*/)
|
||||||
{
|
{
|
||||||
Piece ch;
|
Piece ch;
|
||||||
int f, r;
|
int f, r;
|
||||||
|
@ -1397,7 +1397,7 @@ void Position::mirror(vector <string> &moveRecords, bool cmdChange /*= true*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &iter : moveRecords) {
|
for (auto &iter : moveHistory) {
|
||||||
args = sscanf(iter.c_str(), "(%1u,%1u)->(%1u,%1u)", &r1, &s1, &r2, &s2);
|
args = sscanf(iter.c_str(), "(%1u,%1u)->(%1u,%1u)", &r1, &s1, &r2, &s2);
|
||||||
if (args >= 4) {
|
if (args >= 4) {
|
||||||
s1 = (RANK_NB - s1 + 1) % RANK_NB;
|
s1 = (RANK_NB - s1 + 1) % RANK_NB;
|
||||||
|
@ -1421,7 +1421,7 @@ void Position::mirror(vector <string> &moveRecords, bool cmdChange /*= true*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Position::turn(vector <string> &gameRecords, bool cmdChange /*= true*/)
|
void Position::turn(vector <string> &moveHistory, bool cmdChange /*= true*/)
|
||||||
{
|
{
|
||||||
Piece ch;
|
Piece ch;
|
||||||
int f, r;
|
int f, r;
|
||||||
|
@ -1540,7 +1540,7 @@ void Position::turn(vector <string> &gameRecords, bool cmdChange /*= true*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &iter : gameRecords) {
|
for (auto &iter : moveHistory) {
|
||||||
args = sscanf(iter.c_str(),
|
args = sscanf(iter.c_str(),
|
||||||
"(%1u,%1u)->(%1u,%1u)",
|
"(%1u,%1u)->(%1u,%1u)",
|
||||||
&r1, &s1, &r2, &s2);
|
&r1, &s1, &r2, &s2);
|
||||||
|
@ -1583,7 +1583,7 @@ void Position::turn(vector <string> &gameRecords, bool cmdChange /*= true*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Position::rotate(vector <string> &gameRecords, int degrees, bool cmdChange /*= true*/)
|
void Position::rotate(vector <string> &moveHistory, int degrees, bool cmdChange /*= true*/)
|
||||||
{
|
{
|
||||||
degrees = degrees % 360;
|
degrees = degrees % 360;
|
||||||
|
|
||||||
|
@ -1707,7 +1707,7 @@ void Position::rotate(vector <string> &gameRecords, int degrees, bool cmdChange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &iter : gameRecords) {
|
for (auto &iter : moveHistory) {
|
||||||
args = sscanf(iter.c_str(), "(%1u,%1u)->(%1u,%1u)", &r1, &s1, &r2, &s2);
|
args = sscanf(iter.c_str(), "(%1u,%1u)->(%1u,%1u)", &r1, &s1, &r2, &s2);
|
||||||
|
|
||||||
if (args >= 4) {
|
if (args >= 4) {
|
||||||
|
|
|
@ -116,9 +116,9 @@ public:
|
||||||
Color get_winner() const;
|
Color get_winner() const;
|
||||||
void set_gameover(Color w, GameOverReason reason);
|
void set_gameover(Color w, GameOverReason reason);
|
||||||
|
|
||||||
void mirror(std::vector <std::string> &gameRecords, bool cmdChange = true);
|
void mirror(std::vector <std::string> &moveHistory, bool cmdChange = true);
|
||||||
void turn(std::vector <std::string> &gameRecords, bool cmdChange = true);
|
void turn(std::vector <std::string> &moveHistory, bool cmdChange = true);
|
||||||
void rotate(std::vector <std::string> &gameRecords, int degrees, bool cmdChange = true);
|
void rotate(std::vector <std::string> &moveHistory, int degrees, bool cmdChange = true);
|
||||||
|
|
||||||
void reset_bb();
|
void reset_bb();
|
||||||
|
|
||||||
|
@ -150,10 +150,10 @@ public:
|
||||||
|
|
||||||
void put_piece(Piece pc, Square s);
|
void put_piece(Piece pc, Square s);
|
||||||
bool put_piece(File f, Rank r);
|
bool put_piece(File f, Rank r);
|
||||||
bool put_piece(Square s, bool updategameRecords = false);
|
bool put_piece(Square s, bool updateRecord = false);
|
||||||
|
|
||||||
bool remove_piece(File f, Rank r);
|
bool remove_piece(File f, Rank r);
|
||||||
bool remove_piece(Square s, bool updategameRecords = false);
|
bool remove_piece(Square s, bool updateRecord = false);
|
||||||
|
|
||||||
bool move_piece(File f1, Rank r1, File f2, Rank r2);
|
bool move_piece(File f1, Rank r1, File f2, Rank r2);
|
||||||
bool move_piece(Square from, Square to);
|
bool move_piece(Square from, Square to);
|
||||||
|
|
|
@ -111,7 +111,7 @@ Game::Game(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gameRecords.reserve(256);
|
moveHistory.reserve(256);
|
||||||
|
|
||||||
// 安装事件过滤器监视scene的各个事件,
|
// 安装事件过滤器监视scene的各个事件,
|
||||||
// 由于我重载了QGraphicsScene,相关事件在重载函数中已设定,不必安装监视器。
|
// 由于我重载了QGraphicsScene,相关事件在重载函数中已设定,不必安装监视器。
|
||||||
|
@ -134,7 +134,7 @@ Game::~Game()
|
||||||
}
|
}
|
||||||
#endif /* ENDGAME_LEARNING */
|
#endif /* ENDGAME_LEARNING */
|
||||||
|
|
||||||
gameRecords.clear();
|
moveHistory.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
const map<int, QStringList> Game::getActions()
|
const map<int, QStringList> Game::getActions()
|
||||||
|
@ -163,7 +163,7 @@ extern deque<int> openingBookDequeBak;
|
||||||
|
|
||||||
void Game::gameStart()
|
void Game::gameStart()
|
||||||
{
|
{
|
||||||
//gameRecords.clear();
|
//moveHistory.clear();
|
||||||
position.start();
|
position.start();
|
||||||
startTime = time(nullptr);
|
startTime = time(nullptr);
|
||||||
|
|
||||||
|
@ -201,10 +201,10 @@ void Game::gameReset()
|
||||||
|
|
||||||
// 重置游戏
|
// 重置游戏
|
||||||
// WAR
|
// WAR
|
||||||
if (gameRecords.size() > 1) {
|
if (moveHistory.size() > 1) {
|
||||||
string bak = gameRecords[0];
|
string bak = moveHistory[0];
|
||||||
gameRecords.clear();
|
moveHistory.clear();
|
||||||
gameRecords.emplace_back(bak);
|
moveHistory.emplace_back(bak);
|
||||||
}
|
}
|
||||||
|
|
||||||
position.reset();
|
position.reset();
|
||||||
|
@ -363,8 +363,8 @@ void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
string cmd(record);
|
string cmd(record);
|
||||||
gameRecords.clear();
|
moveHistory.clear();
|
||||||
gameRecords.emplace_back(cmd);
|
moveHistory.emplace_back(cmd);
|
||||||
|
|
||||||
// 重置游戏
|
// 重置游戏
|
||||||
gameReset();
|
gameReset();
|
||||||
|
@ -587,12 +587,12 @@ void Game::flip()
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
stopAndWaitAiThreads();
|
stopAndWaitAiThreads();
|
||||||
|
|
||||||
position.mirror(gameRecords);
|
position.mirror(moveHistory);
|
||||||
position.rotate(gameRecords, 180);
|
position.rotate(moveHistory, 180);
|
||||||
|
|
||||||
// 更新棋谱
|
// 更新棋谱
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (const auto &str : *(game_records())) {
|
for (const auto &str : *(move_hostory())) {
|
||||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,12 +613,12 @@ void Game::mirror()
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
stopAndWaitAiThreads();
|
stopAndWaitAiThreads();
|
||||||
|
|
||||||
position.mirror(gameRecords);
|
position.mirror(moveHistory);
|
||||||
|
|
||||||
// 更新棋谱
|
// 更新棋谱
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
for (const auto &str : *(game_records())) {
|
for (const auto &str : *(move_hostory())) {
|
||||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,12 +641,12 @@ void Game::turnRight()
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
stopAndWaitAiThreads();
|
stopAndWaitAiThreads();
|
||||||
|
|
||||||
position.rotate(gameRecords, -90);
|
position.rotate(moveHistory, -90);
|
||||||
|
|
||||||
// 更新棋谱
|
// 更新棋谱
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
for (const auto &str : *(game_records())) {
|
for (const auto &str : *(move_hostory())) {
|
||||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,11 +667,11 @@ void Game::turnLeft()
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
stopAndWaitAiThreads();
|
stopAndWaitAiThreads();
|
||||||
|
|
||||||
position.rotate(gameRecords, 90);
|
position.rotate(moveHistory, 90);
|
||||||
|
|
||||||
// 更新棋谱
|
// 更新棋谱
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (const auto &str : *(game_records())) {
|
for (const auto &str : *(move_hostory())) {
|
||||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +819,7 @@ bool Game::actionPiece(QPointF p)
|
||||||
manualListModel.removeRows(currentRow + 1, rowCount - currentRow - 1);
|
manualListModel.removeRows(currentRow + 1, rowCount - currentRow - 1);
|
||||||
|
|
||||||
for (int i = 0; i < removeCount; i++) {
|
for (int i = 0; i < removeCount; i++) {
|
||||||
gameRecords.pop_back();
|
moveHistory.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果再决出胜负后悔棋,则重新启动计时
|
// 如果再决出胜负后悔棋,则重新启动计时
|
||||||
|
@ -897,7 +897,7 @@ bool Game::actionPiece(QPointF p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
gameRecords.emplace_back(position.record);
|
moveHistory.emplace_back(position.record);
|
||||||
|
|
||||||
// 发信号更新状态栏
|
// 发信号更新状态栏
|
||||||
updateScence();
|
updateScence();
|
||||||
|
@ -909,7 +909,7 @@ bool Game::actionPiece(QPointF p)
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
|
||||||
// 输出命令行
|
// 输出命令行
|
||||||
for (const auto & i : *(game_records())) {
|
for (const auto & i : *(move_hostory())) {
|
||||||
// 跳过已添加的,因标准list容器没有下标
|
// 跳过已添加的,因标准list容器没有下标
|
||||||
if (k++ <= currentRow)
|
if (k++ <= currentRow)
|
||||||
continue;
|
continue;
|
||||||
|
@ -960,7 +960,7 @@ bool Game::resign()
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
|
||||||
// 输出命令行
|
// 输出命令行
|
||||||
for (const auto & i : *(game_records())) {
|
for (const auto & i : *(move_hostory())) {
|
||||||
// 跳过已添加的,因标准list容器没有下标
|
// 跳过已添加的,因标准list容器没有下标
|
||||||
if (k++ <= currentRow)
|
if (k++ <= currentRow)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1019,7 +1019,7 @@ bool Game::command(const string &cmd, bool update /* = true */)
|
||||||
|
|
||||||
loggerDebug("Computer: %s\n\n", cmd.c_str());
|
loggerDebug("Computer: %s\n\n", cmd.c_str());
|
||||||
|
|
||||||
gameRecords.emplace_back(cmd);
|
moveHistory.emplace_back(cmd);
|
||||||
|
|
||||||
if (!position.command(cmd.c_str()))
|
if (!position.command(cmd.c_str()))
|
||||||
return false;
|
return false;
|
||||||
|
@ -1042,7 +1042,7 @@ bool Game::command(const string &cmd, bool update /* = true */)
|
||||||
emit statusBarChanged(message);
|
emit statusBarChanged(message);
|
||||||
|
|
||||||
// 对于新开局
|
// 对于新开局
|
||||||
if (game_records()->size() <= 1) {
|
if (move_hostory()->size() <= 1) {
|
||||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||||
manualListModel.insertRow(0);
|
manualListModel.insertRow(0);
|
||||||
manualListModel.setData(manualListModel.index(0), position.get_record());
|
manualListModel.setData(manualListModel.index(0), position.get_record());
|
||||||
|
@ -1052,13 +1052,13 @@ bool Game::command(const string &cmd, bool update /* = true */)
|
||||||
else {
|
else {
|
||||||
currentRow = manualListModel.rowCount() - 1;
|
currentRow = manualListModel.rowCount() - 1;
|
||||||
// 跳过已添加行,迭代器不支持+运算符,只能一个个++
|
// 跳过已添加行,迭代器不支持+运算符,只能一个个++
|
||||||
auto i = (game_records()->begin());
|
auto i = (move_hostory()->begin());
|
||||||
for (int r = 0; i != (game_records())->end(); i++) {
|
for (int r = 0; i != (move_hostory())->end(); i++) {
|
||||||
if (r++ > currentRow)
|
if (r++ > currentRow)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 将新增的棋谱行插入到ListModel
|
// 将新增的棋谱行插入到ListModel
|
||||||
while (i != game_records()->end()) {
|
while (i != move_hostory()->end()) {
|
||||||
manualListModel.insertRow(++currentRow);
|
manualListModel.insertRow(++currentRow);
|
||||||
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
|
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
|
||||||
}
|
}
|
||||||
|
@ -1479,7 +1479,7 @@ inline std::string Game::char_to_string(char ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::appendGameOverReasonTogameRecords()
|
void Game::appendGameOverReasonToMoveHistory()
|
||||||
{
|
{
|
||||||
if (position.phase != Phase::gameOver) {
|
if (position.phase != Phase::gameOver) {
|
||||||
return;
|
return;
|
||||||
|
@ -1517,7 +1517,7 @@ void Game::appendGameOverReasonTogameRecords()
|
||||||
}
|
}
|
||||||
|
|
||||||
loggerDebug("%s\n", record);
|
loggerDebug("%s\n", record);
|
||||||
gameRecords.emplace_back(record);
|
moveHistory.emplace_back(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setTips()
|
void Game::setTips()
|
||||||
|
@ -1557,7 +1557,7 @@ void Game::setTips()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::gameOver:
|
case Phase::gameOver:
|
||||||
appendGameOverReasonTogameRecords();
|
appendGameOverReasonToMoveHistory();
|
||||||
|
|
||||||
scoreStr = "比分 " + to_string(p.score[BLACK]) + " : " + to_string(p.score[WHITE]) + ", 和棋 " + to_string(p.score_draw);
|
scoreStr = "比分 " + to_string(p.score[BLACK]) + " : " + to_string(p.score[WHITE]) + ", 和棋 " + to_string(p.score_draw);
|
||||||
|
|
||||||
|
|
|
@ -138,12 +138,12 @@ public:
|
||||||
|
|
||||||
char color_to_char(Color color);
|
char color_to_char(Color color);
|
||||||
std::string char_to_string(char ch);
|
std::string char_to_string(char ch);
|
||||||
void appendGameOverReasonTogameRecords();
|
void appendGameOverReasonToMoveHistory();
|
||||||
void setTips();
|
void setTips();
|
||||||
|
|
||||||
inline const std::vector<std::string> *game_records() const
|
inline const std::vector<std::string> *move_hostory() const
|
||||||
{
|
{
|
||||||
return &gameRecords;
|
return &moveHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t get_elapsed_time(int us);
|
time_t get_elapsed_time(int us);
|
||||||
|
@ -485,7 +485,7 @@ private:
|
||||||
// 提示语
|
// 提示语
|
||||||
string tips;
|
string tips;
|
||||||
|
|
||||||
std::vector <std::string> gameRecords;
|
std::vector <std::string> moveHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline time_t Game::start_timeb() const
|
inline time_t Game::start_timeb() const
|
||||||
|
|
Loading…
Reference in New Issue