-4
그래서 저는 컴퓨터에 python 스크립트를 변환하여 C++에 대한 tic tac toe를 실행하고 모든 함수는 지금까지 재귀 함수를 제외하고는 작동했습니다. 나는 그것을 여러 번 점검했지만 여전히 의도 한대로 작동하지 않습니다. 다른 모든 함수는 작동하고 올바른 결과를 산출하므로이 함수에 문제가 있어야합니다. 낯선 사람은 결국이 한 지점에서 무엇인가를 치고, 재귀 함수의 결과를 변경하며, 나는 왜 그런지 모르겠습니다. 그것이 의미하는 것이면 코드 작성에 c9를 사용하고 있습니다.뭔가를 인쇄하면 재귀 함수 결과가 변경됩니다.
int* AI::get_ratio(string player, Board board_copy, int piece){
board_copy.place_piece(piece, player);
static int rwin[4]={1,0,0, true};
static int rloss[4]={0,1,0,false};
static int rtie[4]={0,0,1, false};
string symbol=get_symbol();
string winner=board_copy.check_game_over();
if(winner==symbol)
return rwin;
else if(winner==othersymbol)
return rloss;
else if(winner=="TIE")
return rtie;
int win, loss, tie;
win=0;
loss=0;
tie=0;
vector<int> moves;
bool p_win=false;
vector<int> pmoves=board_copy.get_pmoves();
for(int i=0; i<pmoves.size(); i++){
int *temp;
if(player==othersymbol)
temp=get_ratio(symbol, board_copy, pmoves[i]);
else
temp=get_ratio(othersymbol, board_copy, pmoves[i]);
if(equal(temp, rloss)){
if(player==symbol)
return rloss;
else
continue;
}
else if(equal(temp,rwin)){
p_win=true;
if(player==othersymbol)
return rwin;
else
continue;
}
moves.push_back(pmoves[i]);
win+=temp[0];
loss+=temp[1];
tie+=temp[2];
}
if(moves.size()==0 && player==othersymbol)
//cout << "loss\n"; this line changes the output for some reason
return rloss;
if(moves.size()==0 && player==symbol)
return rwin;
static int result[4]={win, loss, tie, p_win};
return result;
}
[mcve] –
을 입력하십시오. 먼저 기능이 달성하고자하는 것을 설명하십시오. – lamandy
'if'에 중괄호가 없으므로'cout'을 추가하면 항상 잘못된 위치에 반환된다는 것을 의미합니다. 실제 문제, 언뜻보기에 단서 없음. – user4581301