Alpha/beta: can beta ever equal alpha?
Moderator: Ras
-
- Posts: 28353
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Alpha/beta: can beta ever equal alpha?
Well, he must call AlphaBeta with alpha >= beta somewhere if the call properly passes those (i.e. swaps and negates for negamax) and finds alpha >= beta. Which means either alpha should have been increased, or beta decrased between entering the node and making the recursive call.
-
- Posts: 5693
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Alpha/beta: can beta ever equal alpha?
The problem seems to have been caused by one, two or all of:hgm wrote: ↑Tue Jun 10, 2025 8:15 am Well, he must call AlphaBeta with alpha >= beta somewhere if the call properly passes those (i.e. swaps and negates for negamax) and finds alpha >= beta. Which means either alpha should have been increased, or beta decrased between entering the node and making the recursive call.
- using double for evaluation scores
- not adjusting mate values by distance to the root.
- setting MATE to std::numeric_limits<double>::min()
At first I thought the last point meant that -MATE = MATE (similar to how -(-32768) = -32768 for 16-bits ints, ignoring the fact that this is undefined behaviour). However, it turns out that numeric_limits<double>::min() is the minimal positive value that fits in a double (2.22507e-308). Certainly that is not what the OP can have intended, but it is not immediately clear to me how that contributed to alpha >= beta.
-
- Posts: 28353
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Alpha/beta: can beta ever equal alpha?
Not possible. If a > b, it will remain so when neither a nor b change. That remains true whether a and b are ints, floats or doubles, whether they have the maximum or minumum value for their types, whether you imagine those values to represent heuristic or mate evaluations or completely random non-sensical numbers. Only messing with signed/unsigned could change the result of a comparison between the same bit patterns..
-
- Posts: 5693
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Alpha/beta: can beta ever equal alpha?
if a < b, then we can have -a < -b and thus -b > -a.hgm wrote: ↑Wed Jun 11, 2025 8:31 am Not possible. If a > b, it will remain so when neither a nor b change. That remains true whether a and b are ints, floats or doubles, whether they have the maximum or minumum value for their types, whether you imagine those values to represent heuristic or mate evaluations or completely random non-sensical numbers. Only messing with signed/unsigned could change the result of a comparison between the same bit patterns..
In other words, even if assert(a < b) holds, in the call search(-b, -a) the assert(a < b) in the first line of search() can fail.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
void smaller(short a, short b)
{
if (a < b) printf("yes\n");
else printf("no\n");
}
int main(int argc, char **argv)
{
if (argc < 3) exit(1);
short a = atoi(argv[1]);
short b = atoi(argv[2]);
smaller(a, b);
smaller(-a, -b);
return 0;
}
Code: Select all
$ gcc -o tst tst.c
$ ./tst 2 3
yes
no
$ ./tst -32768 0
yes
yes