c++ 以下陈述的长格式是什么?

wwwo4jvm  于 2022-11-19  发布在  其他
关注(0)|答案(2)|浏览(118)

我看了一些代码,其中附带了以下速记语句

score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);

我想我理解了代码的第一部分,

if(initialPlayer == player){
   score = CAPTURE_SCORE;
}
else
   score = -CAPTURE_SCORE;

但是我对+recursive_solver函数是如何添加到这个函数中的感到困惑,任何帮助都将非常感激:)
如上所述,我试着用一个更长的形式来写这个语句,这样我更容易阅读。我最好的猜测是,递归求解器函数然后被添加到if-else语句的得分中?

jchrr9hc

jchrr9hc1#

if(initialPlayer == player)
   score = CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
else
   score = -CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);

说明:

A = (C ? B : D) + E;

如果CtrueA = (B) + E;
如果CfalseA = (D) + E;
总而言之

if (C)
  A = B + E;
else // if (!C)
  A = D + E;
z8dt9xmd

z8dt9xmd2#

score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);

等于

if(initialPlayer == player) {
    score = CAPTURE_SCORE;
} else {
    score = -CAPTURE_SCORE;
}
score += recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);

相关问题