
I need sometime to analyze your detailed answer!

Moderator: Ras
Take your time. In the meantime I also have to fix a bug in my "iterative minimax-based alpha-beta" code, maybe someone else has found it as well: after making a new move, alpha and beta need to be initialized for the next ply, this was missing, see the two additional lines following the comment "traverse its subtree" below.Luis Babboni wrote:Thanks Sven for your time!!![]()
I need sometime to analyze your detailed answer!
Code: Select all
int AlphaBeta_Iterative_Minimax(Position pos, int maxDepth)
{
// ...
case MAKE:
{
if (moveIndex[ply] < numberOfMoves[ply]) {
// try next move from move list
MakeMove(pos, moveList[ply][moveIndex[ply]]);
// traverse its subtree
alpha[ply + 1] = alpha[ply];
beta [ply + 1] = beta [ply];
++ply;
--depth;
op = GENERATE;
} else {
// ...
}
break;
}
// ...
}
Generating moves is not the same as making them on the board. Generating means, you create (and usually store) information about possible moves in the current position, essentially the "from" and "to" square for each move (and possibly other information, like the promotion piece, castling type, maybe some flags, a move type, or whatever). It is not necessary to make a move on the board only to see whether it is possible, you can see that by looking onto the board. Take a knight, for instance. You know all possible directions to which a knight can move, and for each direction you calculate the corresponding "to" square, check whether it is valid, and if it is, check whether it is occupied by a friendly piece or not. If "to" does not contain a friendly piece then you have a pseudo-legal move "from" => "to" which is either a capture ("to" square occupied by enemy piece) or a quiet move. This pseudo-legal move may actually be legal or not, depending on other conditions, but there are efficient ways to avoid making and unmaking each pseudo-legal move only to test whether it is legal. (In fact the only pseudo-legal moves that can be illegal are check evasions, king moves including castling moves, moves of pinned pieces, and en passant captures, all others are legal.) Legality testing can be done in various ways:Luis Babboni wrote:In fact you seems to have two differents subroutines:
GenerateMoves(pos) and MakeMove(pos,move)
GenerateMoves(pos); // store moves in move list
for (all moves in move list) {
MakeMove(pos, move);
int score = -AlphaBeta(pos, -beta, -alpha, depth - 1);
UnmakeMove(pos, move);
Do this seems to me like do the same things twice, first to make the list and later to start the main search.
May be cause after the first time you did all moves, you could order it before start search, at last you win time.
But scared me the fact to do it twice.
Code: Select all
MakeMove(...);
if (LastMoveWasIllegal(...)) {
UnmakeMove(...);
} else {
int score = -AlphaBeta(...);
UnmakeMove(...);
if (score >= beta) ...
...
}
No, you don't need a second board, and I also think you shouldn't try, it just makes everything even more complex.Luis Babboni wrote:Mmmm..... I could see a difference now thinking in the need of move ordering... the no need of "unmove".
Actually I make/generate a move, check if it is valid (if no puts side to move in check) and start the search till depth desired making/generating and checking moves and then return by as many unmoves as necesary to the actual board and just then make/generate the next* move.
Now I think I could make/generate a move on a secundary board using the main board as a "starting point", check if it is valid (if no puts side to move in check), store it.
Copy main board in secundary board. Seems easier that unmove!
Make/generate the next* move in the secundary using again the main board as "starting point", check if it is valid (if no puts side to move in check), store it.
An so on!
*: I said "next" cause not with knights, pawns (except when advance 2 squares) or king but with rooks, bishops and queens I need first to "travel" by empty squares to know if some saquare is reachable.
It could be this the idea or I´m still wrong in the difference between make and move?
Re move generation: you will find the key if you simply know how you detect that a square is empty or contains some piece of some color, and how you reach the next square in a given direction.Luis Babboni wrote:May be this " looking onto the board "the right way". " is where is the key.
Let me know if I could find it.
Thanks Sven!
BTW: I still do not see why two bounds are necesary in "alpha beta"*!!
But giveme some more time.
*: I mean, I could see why doing alpha beta, but I still think my way without alpha and beta, even could being more complicated, is as good as alpha-beta.
I still think is too much time consumig if I do again as I did for make moves.Sven Schüle wrote:Re move generation: you will find the key if you simply know how you detect that a square is empty or contains some piece of some color, and how you reach the next square in a given direction.Luis Babboni wrote:May be this " looking onto the board "the right way". " is where is the key.
Let me know if I could find it.
Thanks Sven!
BTW: I still do not see why two bounds are necesary in "alpha beta"*!!
But giveme some more time.
*: I mean, I could see why doing alpha beta, but I still think my way without alpha and beta, even could being more complicated, is as good as alpha-beta.