Computer Chess Club Archives


Search

Terms

Messages

Subject: I need some simplified source code....

Author: Tiago Schawer

Date: 02:47:13 01/15/03

Go up one level in this thread


I fell like I'm lost here...
SOME SIMPLIFIED SOURCE CODE WOULD REALLY HELP. CAN YOU HELP ME ?

>Define "wrong results".  The trans/ref table _can_ change scores, and even
>change the best move the second time around.  It depends on how the score
>looks and the PV.  Can you post the output as an example???

I get a really bad move. I'm not using the values from the first search now,
only the suggested move, the problem disappeared. Once in a while the program
plays poorly, and with pure AB it plays well with the same Depth and
board configuration, so I'm blaming the transposition table

>What does your hash entry look like?
>Do you store depth and entry type (bound/exact...)?

Yes.

>Are you making an incremental hash?  If so, did you consider null move and ep?
Yes.
No Null move, it's a Brazilian Checkers program.
Don't know what ep is.


Thanks guys.


Here is my simplified, translated, probably buggy code

int ProbeTTable(unsigned __int64 key, int Alfa, int Beta, int Prof, unsigned
char &BestMov)
{
	ItemTTable* pItemTTable = &TTable[Chave & MASK_18_BITS];

	if (pItemTTable->ZobristKey == Chave)
	{
		if ( ((pItemTTable->Info & MASCARA_PROF) >= Prof)
		{
			if ((pItemTTable->Info & BITS_EXACT) == EXACT)
				return pItemTTable->Score;

			if ((pItemTTable->Info & BIT_GREATER)
                        && (pItemTTable->Nota >= Beta))
				return pItemTTable->Score;

			if ((pItemTTable->Info & BIT_LESS)
                        && (pItemTTable->Nota <= Alfa))
				return pItemTTable->Score;
		}
		BestMov = pItemTTable->BestMov;
	}

	return UNKNOWN_VAL;
}





int MinimaxABTT(Position &Pos, unsigned __int64 Key, int Depth, bool MyTurn, int
Alfa, int Beta)
{
	int AuxScore;
	unsigned char BestMov = 0;

	AuxScore = ProbeTTable(Key, Alfa, Beta, MaxDepth-Depth, BestMov);
	if (AuxNota != VAL_DESCONHECIDO)
		 return AuxNota;

	std::vector<TMove> Vetor; // slow

	// generates all moves up front
	if (!Deep_Enough(Depth))
		GenerateMovs(Pos, Key, Vetor, MyTurn);


	if (Vetor.empty())
	{
		int AuxScore = FEval(Pos, Depth, MyTurn);
		RecordTTable(Key, AuxScore, 0, EXACT, 0);
		return AuxNota;
	}

	Sort(Vetor);

	int BestScore, NewScore;
	int i;
	char SucBestPath[TAM_MELHOR_CAMINHO];
	BestMov = 0;

	// MAX....................................................
	if(MyTurn)
	{
		BestScore = -INFINITY;
		for(i=0; ( (i<Vetor.size()) && (BestScore < Beta) ) ; i++)
		{
			NewScore = MinimaxABTT(Pos, Vetor[i].Zobrist,
                        Depth+1, SucBestPath, !MyTurn, Alfa, Beta);
			if (NewScore > Alfa) 									 // se for melhor nota até aqui
			{
				MelhorMov   = i;
				MelhorNota  = NewScore;
				Alfa        = NewScore;
			}
		}

	     if ((BestScore < Beta) && (BestScore != MENOR_VALOR))
		  RecordTTable(Key, Alfa, MaxDepth-Depth, EXACT, BestMov);
	     else RecordTTable(Key, Alfa, MaxDepth-Depth,BIT_GREATER, BestMov);

		return Alfa;
	}


	// MIN....................................................
	else
	{
		BestScore = +INFINITY;
		for(i=0; ( (i<Vetor.size()) && (BestScore > Alfa) ) ; i++)
		{
			NewScore = MinimaxABTT(Pos, Vetor[i].Zobrist, Depth+1,  SucBestPath, !MyTurn,
Alfa, Beta);
			if (NewScore < Beta)
			{
				MelhorMov   = i;
				MelhorNota  = NewScore;								Beta        = NewScore;							}
		}

		if ((BestScore > Alfa) && (BestScore != +INFINITY))
		     RecordTTable(Key, Alfa, MaxDepth-Depth, EXACT, BestMov);
		else RecordTTable(Key, Alfa, MaxDepth-Depth, BIT_LESS, BestMov);

		return Alfa;
	}
}




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.