Unused value

Help needed, getting this error when trying to compile:

In function 'int negamax(board, unsigned int, unsigned int)':

main.cpp:222:22: warning: second operand of conditional expression has no effect [-Wunused-value]

side==NOUGHTS ? 1: -1;

^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#define NOUGHTS 1
#define CROSSES -1
  
int negamax( board b, unsigned int depth, unsigned int side)

{

side==NOUGHTS ? 1: -1;	

if (depth==0)

{

  int score=eval(b);
  return side * score;

}

int bestScore = -1000;      
for (int x = 0; x < 9; ++x) {
 for (int y = 0; y < 9; ++y) {
while (!occupied(x,y));
make_move(x,y);              
int val = -negamax(b, depth -1, -side);
unMake(b);
bestScore = std::max(bestScore, val);

 
   }
}


return bestScore;

}




Is this normal?
1. The compiler says "warning", not "error". The syntax is legal, but compiler suspects a logic error.

2. Lets look at your line 9. This is what you do there:
1
2
3
4
5
6
7
8
if ( side == NOUGHTS )
{
  1;
}
else
{
 -1;
}

Doesn't that look a bit odd to you too?
side = b->turn ? 1 : -1;


Does this seem logical?
In itself, yes; within that function, no.

The function has been called with some value as "side". You ignore the value and overwrite it based on what b->turn contains. Why have the "side" as a parameter as all then?
I can comment the arithmetic if-expression out of my function. It can be used when I call negamax.


Any ideas how to implement b->turn ?
Last edited on
Topic archived. No new replies allowed.