c++换位5x5 tictactoe错误
c++ transposition 5x5 tictactoe error
我正在编程一个5x5 tictactoe游戏。我得到一个意外的运行时错误,它返回一个大于4的ROW/COL。
每个玩家的游戏次数:
玩家:3,3
计算机:0,0
玩家:1,3
计算机:0.3
玩家:3,1
计算机:0,1
玩家:0,2
计算机:1407352741721444204747<--在阻止了计算机的获胜机会后,我的换位表将此作为最佳移动生成。
我的代码:
void doCompMove(TicTacToe& t, bool firstMove) {
TicTacToe::row_index bestRow;
TicTacToe::column_index bestCol;
#ifndef ANALYSE
static int gameNum(0);
if (!(firstMove))
#else
Stopwatch sw;
sw.start();
#endif
t.clearTrans();
t.chooseMove(TicTacToe::COMPUTER, bestRow, bestCol);
#ifndef ANALYSE
else {
bestRow=gameNum%5;
bestCol=(gameNum/5)%5;
++gameNum;
}
#else
sw.stop();
//if(bestRow > 4) bestRow=rand()%5;
//if(bestCol > 4) bestCol=rand()%5;
cout<<"Tijdsduur: "<<sw<<endl;
cout<<"Transposition table size is: "<<t.getTransSize()<<endl;
cout<<"Moves considered: "<<t.getAndResetMovesConsidered()<<endl;
#endif
cout<<"Computer plays: ROW = "<<bestRow<<" COL = "<<bestCol<<endl;
t.playMove(TicTacToe::COMPUTER, bestRow, bestCol);
}
这是选择移动功能:
TicTacToe::PositionVal TicTacToe::chooseMove(Side s, row_index& bestRow, column_index& bestColumn,
PositionVal alpha, PositionVal beta, int depth) {
#ifdef ANALYSE
++movesConsidered;
#endif
static const int MAX_TABLE_DEPTH(5); //7
static const int MIN_TABLE_DEPTH(3); //5
if(depth>MAX_TABLE_DEPTH)
return UNCLEAR;
Position thisPosition(board);
if (depth>=MIN_TABLE_DEPTH && depth<=MAX_TABLE_DEPTH) {
MapItr itr(transpositions.find(thisPosition));
if (itr!=transpositions.end())
return (*itr).second;
}
Side opp(s==COMPUTER ? HUMAN : COMPUTER);
PositionVal simpleEval(positionValue());
if (simpleEval!=UNCLEAR)
return simpleEval;
PositionVal bestValue(s==COMPUTER ? alpha : beta);
for (row_index row(0); alpha<beta && row<board.numrows(); ++row)
for (column_index column(0); alpha<beta && column<board.numcols(); ++column)
if (squareIsEmpty(row, column)) {
place(row, column, s);
row_index dr;
column_index dc;
PositionVal reply(chooseMove(opp, dr, dc, alpha, beta, depth+1));
place(row, column, EMPTY);
if (s==COMPUTER && reply>bestValue || s==HUMAN && reply<bestValue) {
bestValue=reply;
if (s==COMPUTER)
alpha=bestValue;
else
beta=bestValue;
bestRow=row;
bestColumn=column;
}
}
if (depth>=MIN_TABLE_DEPTH && depth<=MAX_TABLE_DEPTH) {
transpositions[thisPosition]=bestValue;
}
return bestValue;
}
换位表是否可能已达到最大大小?
MapItr itr(transpositions.find(thisPosition));
if (itr!=transpositions.end())
return (*itr).second;
看起来您的代码有一个不选择任何移动的路径。从而得到垃圾结果。
它很容易识别,只需更改如下:
void doCompMove(TicTacToe& t, bool firstMove) {
TicTacToe::row_index bestRow = -1;
TicTacToe::column_index bestCol = -1;
看看你会有什么结果。在那之后,你需要在逻辑上找到一个漏洞。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- TicTacToe游戏中的逻辑错误
- C++ TicTacToe 错误类问题
- c++换位5x5 tictactoe错误