|
• Gomoku evaluation function
Hello everyone!
Firstly let me say that I am very impressed with your site and with your work. I liked the explanations about the min-max algorithm very much and I have a problem that you could probably help me in the same domain.
I've written a Gomoku (5-in-a-row tic-tic-toe) game using alfa-beta prunning and it seems that my evaluation function doesn't quite get it right.
Let me describe what I've done so far:
1. I have chosen to evaluate each square by measuring what exists in all 8 possible directions and up to 6 squares distance.
for example: *xxx-- where:
* = square to be evaluated
X = own marker (either computer's or human's)
- = empty square
O = enemy's marker
*xxx-- would have a value of 3
*XXXX- = 4-in-a-row
*xxxO- = 0 (a solution is no longer possible on that direction)
...
2. At each move the squares that are modified are re-evaluated and the result stored in a bi-dimensional table, ordered by a) the closeness to a solution, and b) by a combinatoric value that keeps count of the own markers around the evaluated square.
This helps to end search when a win situation is found at level smaller than MaxLevel;
ComputerVals[6][225] //225 = 15x15 squares gaming board
HumanVals[6][225] //identically but from human player perspective
ComputerVals[5] = [*XXXXX] (won)
ComputerVals[4] = [*XXXX-] (win)
ComputerVals[3] = [-*xxx-] (unbeatable)
ComputerVals[2] = ...
ComputerVals[0] = [*-----] (empty spaces all around)
each ComputerVal[][] contains both value and an index into the gaming table.
My minmax algorithm looks like:
int MaxFunc(int alfa, int beta, int level)
{
__for(i=5;i>0;i--)
__{
____for each j at ComputerVal[i][j] do
____{
______PutMove(ComputerVal[i][j].index);
______ReevaluateSquares();
______if(Evaluate() == WinSituation)
______{
_________DeleteSquare(ComputerVal[i][j].index);
_________ReevaluateSquares();
_________return WinSituation;
______}
______if(level < MaxLevel)
______{
_________alfa = max(alfa, MinFunc(alfa, beta, level+1));
_________if(alfa>=beta)return beta;
______}
______else
_________return Evaluation();
______DeleteMove(ComputerVal[i][j].index);
______ReevaluateSquares();
____}
__}
__return alfa;
}
The trouble is that on a Pentium 2 at 500 Mhz I can only go 5-6 levels deep in a reasonable amount of time, and the result is that after the game finds the first *xxxx- situation the alfa-beta prunning prevents it to look for a unbeatable situation and exits.
so it may lead to:
* = next move
-----x -----x ------
-*xxx0 -xxx*0 ------
-----0 -----0 -xx*-0
-----0 -----0 -x----
-----0 ------ ------
------ ------ ------
3. Finally:
QUESTION:
DO YOU KNOW OF ANY EVALUATION FUNCTION THAT MAY WORK OR A PLACE WHERE TO LOOK FOR IT?
(any suggestions are very welcome)
Thanks a lot!
|