<s>
Negamax	B-Algorithm
search	O
is	O
a	O
variant	O
form	O
of	O
minimax	B-Algorithm
search	O
that	O
relies	O
on	O
the	O
zero-sum	O
property	O
of	O
a	O
two-player	O
game	O
.	O
</s>
<s>
This	O
algorithm	O
relies	O
on	O
the	O
fact	O
that	O
to	O
simplify	O
the	O
implementation	O
of	O
the	O
minimax	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
This	O
is	O
a	O
coding	O
simplification	O
over	O
minimax	B-Algorithm
,	O
which	O
requires	O
that	O
A	O
selects	O
the	O
move	O
with	O
the	O
maximum-valued	O
successor	O
while	O
B	O
selects	O
the	O
move	O
with	O
the	O
minimum-valued	O
successor	O
.	O
</s>
<s>
It	O
should	O
not	O
be	O
confused	O
with	O
negascout	B-General_Concept
,	O
an	O
algorithm	O
to	O
compute	O
the	O
minimax	B-Algorithm
or	O
negamax	B-Algorithm
value	O
quickly	O
by	O
clever	O
use	O
of	O
alpha-beta	B-Algorithm
pruning	I-Algorithm
discovered	O
in	O
the	O
1980s	O
.	O
</s>
<s>
Note	O
that	O
alpha-beta	B-Algorithm
pruning	I-Algorithm
is	O
itself	O
a	O
way	O
to	O
compute	O
the	O
minimax	B-Algorithm
or	O
negamax	B-Algorithm
value	O
of	O
a	O
position	O
quickly	O
by	O
avoiding	O
the	O
search	O
of	O
certain	O
uninteresting	O
positions	O
.	O
</s>
<s>
Most	O
adversarial	O
search	O
engines	O
are	O
coded	O
using	O
some	O
form	O
of	O
negamax	B-Algorithm
search	O
.	O
</s>
<s>
NegaMax	B-Algorithm
operates	O
on	O
the	O
same	O
game	O
trees	O
as	O
those	O
used	O
with	O
the	O
minimax	B-Algorithm
search	O
algorithm	O
.	O
</s>
<s>
The	O
negamax	B-Algorithm
search	O
objective	O
is	O
to	O
find	O
the	O
node	O
score	O
value	O
for	O
the	O
player	O
who	O
is	O
playing	O
at	O
the	O
root	O
node	O
.	O
</s>
<s>
The	O
pseudocode	B-Language
below	O
shows	O
the	O
negamax	B-Algorithm
base	O
algorithm	O
,	O
with	O
a	O
configurable	O
limit	O
for	O
the	O
maximum	O
search	O
depth	O
:	O
</s>
<s>
Although	O
the	O
negamax	B-Algorithm
function	O
shown	O
only	O
returns	O
the	O
node	O
's	O
best	O
score	O
,	O
practical	O
negamax	B-Algorithm
implementations	O
will	O
retain	O
and	O
return	O
both	O
best	O
move	O
and	O
best	O
score	O
for	O
the	O
root	O
node	O
.	O
</s>
<s>
This	O
is	O
the	O
same	O
behavior	O
as	O
the	O
normal	O
minimax	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
heuristic	O
value	O
is	O
not	O
necessarily	O
the	O
same	O
as	O
a	O
node	O
's	O
return	O
value	O
due	O
to	O
value	O
negation	O
by	O
negamax	B-Algorithm
and	O
the	O
color	O
parameter	O
.	O
</s>
<s>
The	O
negamax	B-Algorithm
node	O
's	O
return	O
value	O
is	O
a	O
heuristic	O
score	O
from	O
the	O
point	O
of	O
view	O
of	O
the	O
node	O
's	O
current	O
player	O
.	O
</s>
<s>
Negamax	B-Algorithm
scores	O
match	O
minimax	B-Algorithm
scores	O
for	O
nodes	O
where	O
player	O
A	O
is	O
about	O
to	O
play	O
,	O
and	O
where	O
player	O
A	O
is	O
the	O
maximizing	O
player	O
in	O
the	O
minimax	B-Algorithm
equivalent	O
.	O
</s>
<s>
Negamax	B-Algorithm
always	O
searches	O
for	O
the	O
maximum	O
value	O
for	O
all	O
its	O
nodes	O
.	O
</s>
<s>
Hence	O
for	O
player	O
B	O
nodes	O
,	O
the	O
minimax	B-Algorithm
score	O
is	O
a	O
negation	O
of	O
its	O
negamax	B-Algorithm
score	O
.	O
</s>
<s>
Player	O
B	O
is	O
the	O
minimizing	O
player	O
in	O
the	O
minimax	B-Algorithm
equivalent	O
.	O
</s>
<s>
Variations	O
in	O
negamax	B-Algorithm
implementations	O
may	O
omit	O
the	O
color	O
parameter	O
.	O
</s>
<s>
Algorithm	O
optimizations	O
for	O
minimax	B-Algorithm
are	O
also	O
equally	O
applicable	O
for	O
Negamax	B-Algorithm
.	O
</s>
<s>
Alpha-beta	B-Algorithm
pruning	I-Algorithm
can	O
decrease	O
the	O
number	O
of	O
nodes	O
the	O
negamax	B-Algorithm
algorithm	O
evaluates	O
in	O
a	O
search	O
tree	O
in	O
a	O
manner	O
similar	O
with	O
its	O
use	O
with	O
the	O
minimax	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
pseudocode	B-Language
for	O
depth-limited	O
negamax	B-Algorithm
search	O
with	O
alpha-beta	B-Algorithm
pruning	I-Algorithm
follows	O
:	O
</s>
<s>
Negamax	B-Algorithm
sets	O
the	O
arguments	O
α	O
and	O
β	O
for	O
the	O
root	O
node	O
to	O
the	O
lowest	O
and	O
highest	O
values	O
possible	O
.	O
</s>
<s>
Other	O
search	O
algorithms	O
,	O
such	O
as	O
negascout	B-General_Concept
and	O
MTD(f )	O
,	O
may	O
initialize	O
α	O
and	O
β	O
with	O
alternate	O
values	O
to	O
further	O
improve	O
tree	O
search	O
performance	O
.	O
</s>
<s>
When	O
negamax	B-Algorithm
encounters	O
a	O
child	O
node	O
value	O
outside	O
an	O
alpha/beta	O
range	O
,	O
the	O
negamax	B-Algorithm
search	O
cuts	O
off	O
thereby	O
pruning	O
portions	O
of	O
the	O
game	O
tree	O
from	O
exploration	O
.	O
</s>
<s>
This	O
value	O
is	O
identical	O
to	O
the	O
result	O
the	O
negamax	B-Algorithm
base	O
algorithm	O
would	O
return	O
,	O
without	O
cut	O
offs	O
and	O
without	O
any	O
α	O
and	O
β	O
bounds	O
.	O
</s>
<s>
Alpha-beta	B-Algorithm
pruning	I-Algorithm
eventually	O
discards	O
any	O
value	O
bound	O
results	O
.	O
</s>
<s>
Such	O
values	O
do	O
not	O
contribute	O
nor	O
affect	O
the	O
negamax	B-Algorithm
value	O
at	O
its	O
root	O
node	O
.	O
</s>
<s>
This	O
pseudocode	B-Language
shows	O
the	O
fail-soft	O
variation	O
of	O
alpha-beta	B-Algorithm
pruning	I-Algorithm
.	O
</s>
<s>
Thus	O
,	O
a	O
node	O
value	O
may	O
be	O
outside	O
the	O
initial	O
α	O
and	O
β	O
range	O
bounds	O
set	O
with	O
a	O
negamax	B-Algorithm
function	O
call	O
.	O
</s>
<s>
In	O
contrast	O
,	O
fail-hard	O
alpha-beta	B-Algorithm
pruning	I-Algorithm
always	O
limits	O
a	O
node	O
value	O
in	O
the	O
range	O
of	O
α	O
and	O
β	O
.	O
</s>
<s>
Move	O
ordering	O
is	O
an	O
optimization	O
for	O
alpha	B-Algorithm
beta	I-Algorithm
pruning	I-Algorithm
that	O
attempts	O
to	O
guess	O
the	O
most	O
probable	O
child	O
nodes	O
that	O
yield	O
the	O
node	O
's	O
score	O
.	O
</s>
<s>
Transposition	B-General_Concept
tables	I-General_Concept
selectively	O
memoize	O
the	O
values	O
of	O
nodes	O
in	O
the	O
game	O
tree	O
.	O
</s>
<s>
When	O
negamax	B-Algorithm
searches	O
the	O
game	O
tree	O
,	O
and	O
encounters	O
the	O
same	O
node	O
multiple	O
times	O
,	O
a	O
transposition	B-General_Concept
table	I-General_Concept
can	O
return	O
a	O
previously	O
computed	O
value	O
of	O
the	O
node	O
,	O
skipping	O
potentially	O
lengthy	O
and	O
duplicate	O
re-computation	O
of	O
the	O
node	O
's	O
value	O
.	O
</s>
<s>
Negamax	B-Algorithm
performance	O
improves	O
particularly	O
for	O
game	O
trees	O
with	O
many	O
paths	O
that	O
lead	O
to	O
a	O
given	O
node	O
in	O
common	O
.	O
</s>
<s>
The	O
pseudo	B-Language
code	I-Language
that	O
adds	O
transposition	B-General_Concept
table	I-General_Concept
functions	O
to	O
negamax	B-Algorithm
with	O
alpha/beta	O
pruning	O
is	O
given	O
as	O
follows	O
:	O
</s>
<s>
Alpha/beta	O
pruning	O
and	O
maximum	O
search	O
depth	O
constraints	O
in	O
negamax	B-Algorithm
can	O
result	O
in	O
partial	O
,	O
inexact	O
,	O
and	O
entirely	O
skipped	O
evaluation	O
of	O
nodes	O
in	O
a	O
game	O
tree	O
.	O
</s>
<s>
This	O
complicates	O
adding	O
transposition	B-General_Concept
table	I-General_Concept
optimizations	O
for	O
negamax	B-Algorithm
.	O
</s>
<s>
The	O
code	O
therefore	O
must	O
preserve	O
and	O
restore	O
the	O
relationship	O
of	O
value	O
with	O
alpha/beta	O
parameters	O
and	O
the	O
search	O
depth	O
for	O
each	O
transposition	B-General_Concept
table	I-General_Concept
entry	O
.	O
</s>
<s>
Transposition	B-General_Concept
tables	I-General_Concept
are	O
typically	O
lossy	O
and	O
will	O
omit	O
or	O
overwrite	O
previous	O
values	O
of	O
certain	O
game	O
tree	O
nodes	O
in	O
its	O
tables	O
.	O
</s>
<s>
This	O
is	O
necessary	O
since	O
the	O
number	O
of	O
nodes	O
negamax	B-Algorithm
visits	O
often	O
far	O
exceeds	O
the	O
transposition	B-General_Concept
table	I-General_Concept
size	O
.	O
</s>
<s>
Lost	O
or	O
omitted	O
table	O
entries	O
are	O
non-critical	O
and	O
will	O
not	O
affect	O
the	O
negamax	B-Algorithm
result	O
.	O
</s>
<s>
However	O
,	O
lost	O
entries	O
may	O
require	O
negamax	B-Algorithm
to	O
re-compute	O
certain	O
game	O
tree	O
node	O
values	O
more	O
frequently	O
,	O
thus	O
affecting	O
performance	O
.	O
</s>
