Author: Mats Forsén
Date: 13:20:52 04/08/98
Howdy folks, I seem to be having a lot of troubles with my chess AI.. *sigh*.. I don't know if it is because my minimax function is shot to hell so I'm asking you knowledgeable guys out there if there is anything obvious wrong with it.. I'm also seeking some friendly soul to test my program and/or check the code :) (It still sucks though) Win32 Console Text Interface. One problem I have is with the path (show expected path).. Am I doing it wrong? It sometimes (as below) sets a1a1 as a move, that is 0. The position (WAC1) is: 2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - At a depth of 5 I get the following: Time used: 21.239 s; Max depth: 5; Nodes generated: 1007501; Nodes visited: 387775; Ply: 0; Nodes Generated: 59; Nodes Visited: 1; Ply: 1; Nodes Generated: 2202; Nodes Visited: 59; Ply: 2; Nodes Generated: 6042; Nodes Visited: 106; Ply: 3; Nodes Generated: 177503; Nodes Visited: 4437; Ply: 4; Nodes Generated: 821695; Nodes Visited: 15291; Ply: 5; Nodes Generated: 0; Nodes Visited: 367881; Result: 200; Best path: g1h1 h6h5 e8d6 g7g6 a1a1 The computer suggests: 'g1h1'. Here is my function: int AI::negamax( Move * resulting_move, int playercolor, int depth, int alpha, int beta ) { MoveList moves; int result, curmove, cutoff = 0; Move next_move; nodes_visited[ depth ]++; if( depth == 0 ) return board->Evaluate(playercolor); board->GenerateMoves( playercolor, moves ); if( moves.num == 0 ) return board->Evaluate(playercolor); // No moves possible nodes_generated[ depth ] += moves.num; // sort_moves( moves ); curmove = moves.num; while( curmove-- && !cutoff ) { board->ApplyMove( moves.m[curmove] ); if( board->InCheck( playercolor ) ) { board->UndoMove( moves.m[curmove] ); continue; // No check moves please } // Recurse using nega-max variant of alpha-beta result = - negamax( &next_move, ( ~(playercolor & COLOR) & COLOR ), depth-1, -beta, -alpha ); board->UndoMove( moves.m[curmove] ); if( result > alpha ) { alpha = result; *resulting_move = moves.m[curmove]; } if( alpha > beta ) { cutoff = 1; historydata[ moves.m[curmove].where() ] += ( 1 << depth ); } } path.m[ depth ] = *resulting_move; return result; } / Mats Forsén garnax@texoma.net
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.