Advertisement

Wrong Alpha-Beta?

Started by October 27, 2004 09:31 AM
-1 comments, last by Hermes 20 years, 1 month ago
What's wrong with this alpha-beta function?

1.allGMoves is a bitboard that keeps all the position currently occupied by the genius pieces
2.allMMoves the same thing but with the MINIME moves(human player)
3.I haven't done the Evaluate() function,it just returns 0
4.INFINITY 100


[SOURCE]



int CGameTree::AlphaBeta(int depth, int alpha, int beta,int turn)
{

unsigned __int64 lastMove;	
int val=0;
if(depth==0) return Evaluate();



GenerateLegalMoves(turn);/*this fills the stack with all the possible moves*/

if(turn==GENIUS)
{

   for(int i=0;i<16;i++)
   {
   
      for(int j=0;j<stack.size();j++)
	  {
	    lastMove=pList;//save current move
        pList.at(i)->move=stack[j];//Do move 
		allGMoves^=lastMove;//erase current position occupied by this piece on the global genius board
		allGMoves^=stack[j];//write new occupied position
	    


		val=-AlphaBeta(depth-1,-beta,-alpha,(turn+1)%2);



		if(val>=beta)return beta;//cutoff
		if(val>alpha)alpha=val;
         
		if((val<alpha && depth==MAX_LEVEL)||depth!=MAX_LEVEL)
		{
		   	allGMoves^=stack[j];//undo move
			allGMoves^=lastMove;
			pList.at(i)->move=lastMove;
		


		}

	    
	  }
   

    
   
   }

return alpha;

}else if(turn==MINIME)
       {

   for(int i=16;i<31;i++)
   {
   
      for(int j=0;j<stack.size();j++)
	  {
	    lastMove=pList;//save current move
        pList.at(i)->move=stack[j];//Do move 
		allGMoves^=lastMove;//erase position occupied by this move
		allGMoves^=stack[j];//write new occupied position
	    


		val=-AlphaBeta(depth-1,-beta,-alpha,(turn+1)%2);
       	

		if(val>=beta)return beta;//cutoff
		if(val>alpha)alpha=val;
		

		
		
		   	allGMoves^=stack[j];//undo move
			allGMoves^=lastMove;
			pList.at(i)->move=lastMove;
		
			

	    
	  }
   

    
   
   }

return alpha;
}



}


[/SOURCE]
[/source][/source][/source] Thanks for the great effort of reading this long function! I guess the doing and undoing is wrong

Do you know a way of doing and undoing moves....PLeeeease!

[Edited by - Hermes on October 27, 2004 9:52:59 AM]

This topic is closed to new replies.

Advertisement