Home > Mobile >  What would be the long form of the following statment?
What would be the long form of the following statment?

Time:11-15

I was looking at some code which came with the following short-hand statement

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

I think that I understand the first portion of the code,

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

but im confused to how the recursive_solver function is added to this, any help would be greatly appreciated :)

As stated above I tried to write out the statement in a longer from thats easier for me to read. My best guess is that the recursive solver function is then added to the score of the if-else statement?

CodePudding user response:

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);

Explanation:

A = (C ? B : D)   E;

If C is true: A = (B) E;
If C is false: A = (D) E;
In sum

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

CodePudding user response:

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

Equals to

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