Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Correction: List and ElChinito as Crafty clones, ... etc

Author: Paul H

Date: 17:23:10 08/21/04

Go up one level in this thread


Dann, what do you think of this then...

Below is function EvaluateMate() in Crafty and the section of Evaluate() that
calls it. Below is also the disassembly of ElChinito.

Wow. Exactly the same. But wait, that is not the evidence yet. You see,
EvaluateMate() will never return a value of 99999. This is a Crafty coding bug.
Evaluate() checks for the return value of 99999 (hex, 01869Fh in the assembly
code) from EvaluateMate() even though that function will never return such a
value.

EvaluateMate() get its result from the signed byte arrays b_n_mate_dark_squares,
b_n_mate_light_squares and mate. Their values will never exceed 128. You can add
the value of "(Distance(WhiteKingSQ, BlackKingSQ) - 3) * KING_KING_TROPISM"
which is at most 4 * 15 = 60, and the maximum return value of this function can
be 188. 188 max vs 99999?

Copying code, some might argue, is "smart" thing to do, because you benefit from
the sweat of someone else, and still get credit. Society calls it plagiarism.
However, to copy the bug, is "stupid".

// from Evaluate() in Crafty
// -------------------------
	score = EvaluateMaterial(tree);
	tree->all_pawns = BlackPawns | WhitePawns;
	if ((TotalWhitePawns + TotalBlackPawns) == 0)
		do {
			int             ms = EvaluateMate(tree);
			if (ms == 99999)
				break;
			score += ms;
			if (score > DrawScore(1) && !(can_win & 1))
				score = score >> 2;
			if (score < DrawScore(1) && !(can_win & 2))
				score = score >> 2;
			return ((wtm) ? score : -score);
		} while (0);

// EvaluateMate() in Crafty()
// --------------------------
int EvaluateMate(TREE * RESTRICT tree)
{
	register int    mate_score = DrawScore(1);
	if ((TotalBlackPieces == 0) && (TotalWhitePieces == 6) &&
          (!WhitePawns) && (!BlackPawns) && WhiteBishops && WhiteKnights) {
		if (dark_squares & WhiteBishops)
			mate_score = b_n_mate_dark_squares[BlackKingSQ];
		else
			mate_score = b_n_mate_light_squares[BlackKingSQ];
	}
	if ((TotalBlackPieces == 6) && (TotalWhitePieces == 0) &&
          (!WhitePawns) && (!BlackPawns) && BlackBishops && BlackKnights) {
		if (dark_squares & BlackBishops)
			mate_score = -b_n_mate_dark_squares[WhiteKingSQ];
		else
			mate_score = -b_n_mate_light_squares[WhiteKingSQ];
	}
	if (!mate_score) {
		if (Material > 0) {
			mate_score = mate[BlackKingSQ];
			mate_score -= (Distance(WhiteKingSQ, BlackKingSQ) - 3)
                                * KING_KING_TROPISM;
		} else if (Material < 0) {
			mate_score = -mate[WhiteKingSQ];
			mate_score += (Distance(WhiteKingSQ, BlackKingSQ) - 3)
                                * KING_KING_TROPISM;
		}
	}
	return (mate_score);
}

// --------------------------------------------------------------------------
// section of Evaluate() that calls EvaluateMate() in ElChinito 3.25
// --------------------------------------------------------------------------

...
	mov  edx , dword ptr [ Data4b3520 ]
	mov eax ,  dword ptr [ Data4b34f8 ]
	mov  ecx , dword ptr [ Data4b3524 ]
	or eax , edx
	movsx edx ,byte ptr [ Data4b35a1 ]
	mov dword ptr [ Data4b42f0 ] ,  eax
	mov eax ,  dword ptr [ Data4b34fc ]
	or eax , ecx
	movsx ecx ,byte ptr [ Data4b35a5 ]
	add ecx , edx
	mov dword ptr [ Data4b42f4 ] ,  eax
	jne Label425038
	call Fun42a380
	cmp eax , 01869Fh
	je Label425038
	add ebx , eax
	mov eax ,  dword ptr [ Data441be4 ]
	cmp ebx , eax
	jle Label42500e
	cmp esi , 0FFFFFFFFh
	jne Label42500c
...

// --------------------------------------------------------------------------
// EvaluateMate() in ElChinito 3.25
// --------------------------------------------------------------------------
Fun42a380 :: ; proc near // EvaluateMate()
	mov  cl , byte ptr [ Data4b35a2 ]
	test cl , cl
	mov eax ,  dword ptr [ Data441be4 ]
	mov  dl , byte ptr [ Data4b355d ]
	push ebx
	push esi
	push edi
	jne Label42a426
	cmp  byte ptr [ Data4b359e ] , 06h
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b34f8 ]
	or  ecx , dword ptr [ Data4b34fc ]
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b3520 ]
	or  ecx , dword ptr [ Data4b3524 ]
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b3508 ]
	mov  esi , dword ptr [ Data4b350c ]
	mov edi , ecx
	or edi , esi
	je Label42a4a7
	mov  edi , dword ptr [ Data4b3500 ]
	or  edi , dword ptr [ Data4b3504 ]
	je Label42a4a7
	mov eax ,  dword ptr [ Data46ad40 ]
	and eax , ecx
	mov  ecx , dword ptr [ Data46ad44 ]
	and ecx , esi
	or eax , ecx
	je Label42a417
	movsx eax , dl
	movsx eax ,byte ptr [ eax + 043C738h ]
	jmp Label42a4a7

Label42a417 ::
	movsx ecx , dl
	movsx eax ,byte ptr [ ecx + 043C6B8h ]
	jmp Label42a4a7

Label42a426 ::
	cmp cl , 06h
	jne Label42a4a7
	mov  cl , byte ptr [ Data4b359e ]
	test cl , cl
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b34f8 ]
	or  ecx , dword ptr [ Data4b34fc ]
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b3520 ]
	or  ecx , dword ptr [ Data4b3524 ]
	jne Label42a4a7
	mov  ecx , dword ptr [ Data4b3530 ]
	mov  esi , dword ptr [ Data4b3534 ]
	mov edi , ecx
	or edi , esi
	je Label42a4a7
	mov  edi , dword ptr [ Data4b3528 ]
	or  edi , dword ptr [ Data4b352c ]
	je Label42a4a7
	mov  ebx , dword ptr [ Data46ad40 ]
	mov  edi , dword ptr [ Data46ad44 ]
	and ecx , ebx
	and esi , edi
	mov eax , ecx
	or eax , esi
	je Label42a497
	movsx eax ,byte ptr [ Data4b355c ]
	movsx eax ,byte ptr [ eax + 043C738h ]
	jmp Label42a4a5

Label42a497 ::
	movsx ecx ,byte ptr [ Data4b355c ]
	movsx eax ,byte ptr [ ecx + 043C6B8h ]

Label42a4a5 ::
	neg eax

Label42a4a7 ::
	test eax , eax
	jne Label42a54d
	mov  ecx , dword ptr [ Data4b3558 ]
	test ecx , ecx
	jle Label42a506
	movsx edi ,byte ptr [ Data4b355c ]
	movsx ecx , dl
	movsx ebx ,byte ptr [ ecx + 043C6F8h ]
	mov edx , ecx
	and edx , 07h
	mov eax , edi
	and eax , 07h
	sub eax , edx
	cdq
	mov esi , eax
	xor esi , edx
	mov eax , edi
	sar eax , 03h
	sar ecx , 03h
	sub eax , ecx
	sub esi , edx
	cdq
	xor eax , edx
	sub eax , edx
	cmp esi , eax
	jle Label42a4f2
	mov eax , esi

Label42a4f2 ::
	mov ecx , 03h
	sub ecx , eax
	lea eax ,  dword ptr [ ecx + 2 * ecx ]
	pop edi
	lea ecx ,  dword ptr [ eax + ebx ]
	pop esi
	lea eax ,  dword ptr [ ecx + 4 * eax ]
	pop ebx
	ret

Label42a506 ::
	jnl Label42a54d
	movsx edi ,byte ptr [ Data4b355c ]
	movsx ebx ,byte ptr [ edi + 043C6F8h ]
	movsx esi , dl
	mov edx , esi
	and edx , 07h
	mov eax , edi
	and eax , 07h
	sub eax , edx
	cdq
	mov ecx , eax
	xor ecx , edx
	mov eax , edi
	sar eax , 03h
	sar esi , 03h
	sub eax , esi
	sub ecx , edx
	cdq
	xor eax , edx
	sub eax , edx
	neg ebx
	cmp ecx , eax
	jle Label42a543
	mov eax , ecx

Label42a543 ::
	lea eax ,  dword ptr [ eax + 2 * eax - 9 ]
	lea ecx ,  dword ptr [ eax + ebx ]
	lea eax ,  dword ptr [ ecx + 4 * eax ]

Label42a54d ::
	pop edi
	pop esi
	pop ebx
	ret



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.