-4
私はコンピュータのためにpythonスクリプトを変換して、tic tac toeをC++に再生し、すべての関数は私の再帰関数を除いて今まで働いています。私はそれを数回チェックしたが、意図した通りにはまだ動作しません。他のすべての関数は動作し、正しい結果を生成するので、この関数の問題でなければなりません。なぜなら、私は最後にこの1つの場所で何かを叫ぶと、それは再帰関数の結果を変え、なぜ私はわからないのです。それが何かを意味するなら、私は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