I checked the POINTS routine for Chess88 (evaluation function).
Code: Select all
;****************************************************************
; POINT EVALUATION ROUTINE
;****************************************************************
; FUNCTION: -- To perform a static board evaluation and
; derive a score for a given board position
;
; CALLED BY: -- FNDMOV
; EVAL
;
; CALLS: -- ATTACK
; XCHNG
; LIMIT
;
; ARGUMENTS: -- None
;****************************************************************
POINTS: XRA A ; Zero out variables | 0EA8 proc sub_EA8 near
STA MTRL | 0EA8 B0 00 mov al, 0
STA BRDC | 0EAA A2 DE 09 mov [ds:byte_9DE], al
STA PTSL | 0EAD A2 DA 09 mov [ds:byte_9DA], al
STA PTSWI | 0EB0 A2 DB 09 mov [ds:byte_9DB], al
STA PTSW2 | 0EB3 A2 DC 09 mov [ds:byte_9DC], al
STA PTSCK | 0EB6 A2 DD 09 mov [ds:byte_9DD], al
LXI H,T1 ; Set attacker flag | 0EB9 A2 E1 09 mov [ds:byte_9E1], al
MVI M,7 | 0EBC C6 06 BA 09 07 mov [byte ptr ds:loc_9BA], 7
MVI A,21 ; Init to first square on board | 0EC1 BB 15 00 mov bx, 15h
PT5: STA M3 ; Save as board index | 0EC4 loc_EC4:
LIXD M3 ; Load board index | 0EC4 89 1E B6 09 mov [word ptr ds:loc_9B6], bx
LDA A,BOARD(X) ; Get piece from board | 0EC8 8A 87 D1 00 mov al, [bx+0D1h]
CPI -1 ,Off board edge ? | 0ECC 3C FF cmp al, 0FFh
JZ PT25 ; Yes - jump | 0ECE 75 03 jnz short loc_ED3
LXI H,P1 ; Save piece, if any | 0ED0 E9 BD 00 jmp loc_F90
LDA M,A | 0ED3 loc_ED3:
ANI 7 ; Save piece type, if any | 0ED3 8A C8 mov cl, al
STA T3 | 0ED5 A2 D0 09 mov [ds:byte_9D0], al
CPI KNIGHT ; Less than a Knight (Pawn) ? | 0ED8 24 07 and al, 7
JRC PT6X ; Yes - Jump | 0EDA A2 BE 09 mov [byte ptr ds:loc_9BE], al
CPI ROOK ; Rook, Queen or King ? | 0EDD 3C 01 cmp al, 1 ; KNIGHT
JRC PT6.B ; No - jump | 0EDF 76 3B jbe short loc_F1C
CPI KING ; Is it a King ? | 0EE1 3C 04 cmp al, 4 ; ROOK
JRZ PT6AA ; Yes - jump | 0EE3 72 25 jb short loc_F0A
LDA MOVENO ; Get move number | 0EE5 3C 06 cmp al, 6 ; KING
CPI 7 ; Less than 7 ? | 0EE7 74 09 jz short loc_EF2
JRC PT6A ; Yes - Jump | 0EE9 80 3E D4 09 07 cmp [ds:byte_9D4], 7
JMP PT6X ; Jump | 0EEE 72 13 jb short loc_F03
PT6AA: BIT 4,M ; Castled yet ? | 0EF0 73 11 jnb short loc_F03
JRZ PT6A ; No - jump | 0EF2 loc_EF2:
MVI A,+6 ; Bonus for castling | 0EF2 F6 C1 10 test cl, 10h ; Castled yet ?
BIT 7,M ; Check piece color | 0EF5 74 0C jz short loc_F03
JRZ PT6D ; Jump if white | 0EF7 B0 06 mov al, 6 ; Bonus for castling
MVI A,-6 ; Bonus for black castling | 0EF9 F6 C1 80 test cl, 80h
JMP PT6D ; Jump | 0EFC 74 1A jz short loc_F18
PT6A: BIT 3,M ; Has piece moved yet ? | 0EFE F6 D8 neg al
JRZ PT6X ; No - jump | 0F00 EB 16 jmp short loc_F18
JMP PT6C ; Jump | 0F02 90 db 90h
PT6B: BIT 3,M ; Has piece moved yet ? | 0F03 loc_F03:
JRNZ PT6X ; Yes - jump | 0F03 F6 C1 08 test cl, 8
PT6C: MVI A,-2 ; Two point penalty for white | 0F06 74 14 jz short loc_F1C
BIT 7,M ; Check piece color | 0F08 75 05 jnz short loc_F0F
JRZ .+4 ; Jump if white | 0F0A loc_F0A:
MVI A,+2 ; Two point penalty for black | 0F0A F6 C1 08 test cl, 8
PT6D: LXI H,BRDC ; Get address of board control | 0F0D 75 0D jnz short loc_F1C
ADD M ; Add on penalty/bonus points | 0F0F loc_F0F:
LDA M,A ; Save | 0F0F B0 02 mov al, 2 ; Two point penalty for white
PT6X: XRA A ; Zero out attack list | 0F11 F6 C1 80 test cl, 80h ; Check piece color
MVI B,14 | 0F14 75 02 jnz short loc_F18 ; Jump if white
LXI H,ATKLST | 0F16 F6 D8 neg al ; Two point penalty for black
LDA M,A | 0F18 loc_F18:
INX H | 0F18 00 06 DA 09 add [ds:byte_9DA], al
DJNZ .-2 | 0F1C loc_F1C:
CALL ATTACK ; Build attack list for square | 0F1C B0 00 mov al, 0
LXI H,BACT ; Get black attacker count addr | 0F1E B9 0E 00 mov cx, 0Eh
LDA WACT ; Get white attacker count | 0F21 8D 3E 49 01 lea di, [byte_149]
SUB M ; Compute count difference | 0F25 FC cld
LXI H,BRDC ; Address of board control | 0F26 F3 AB rep stosw
ADD M ; Accum board control score | 0F28 E8 CD F3 call sub_2F8
LDA M,A ; Save | 0F2B A0 49 01 mov al, [ds:byte_149]
LDA P1 ; Get piece on current square | 0F2E 2A 06 57 01 sub al, [ds:byte_157]
ANA A ; Is it empty ? | 0F32 00 06 DA 09 add [ds:byte_9DA], al
JZ PT25 ; Yes - jump | 0F36 80 3E D0 09 00 cmp [ds:byte_9D0], 0
CALL XCHNG ; Evaluate exchange, if any | 0F3B 74 53 jz short loc_F90
XRA A ; Check for a loss | 0F3D E8 5E 02 call sub_119E
CMP E ; Points lost ? | 0F40 80 FA 00 cmp dl, 0
JRZ PT23 ; No - Jump | 0F43 74 3C jz short loc_F81
DCR D ; Deduct half a Pawn value | 0F45 FE CE dec dh
LDA P1 ; Get piece under attack | 0F47 A0 D0 09 mov al, [ds:byte_9D0]
LXI H,COLOR ; Color of side just moved | 0F4A 32 06 CF 09 xor al, [ds:byte_9CF]
XRA M ; Compare with piece | 0F4E 78 1C js short loc_F6C
BIT 7,A ; Do colors match ? | 0F50 3A 16 DB 09 cmp dl, [ds:byte_9DB]
LDA A,E ; Points lost | 0F54 72 2B jb short loc_F81
JRNZ PT20 ; Jump if no match | 0F56 88 16 DB 09 mov [ds:byte_9DB], dl
LXI H,PTSL ; Previous max points lost | 0F5A 8B 1E C4 09 mov bx, [ds:word_9C4]
CMP M ; Compare to current value | 0F5E A0 B6 09 mov al, [byte ptr ds:loc_9B6]
JRC PT23 ; Jump if greater than | 0F61 3A 47 03 cmp al, [bx+3]
LDA M,E ; Store new value as max lost | 0F64 75 1B jnz short loc_F81
LIXD MLPTRJ ; Load pointer to this move | 0F66 A2 E1 09 mov [ds:byte_9E1], al
LDA M3 ; Get position of lost piece | 0F69 EB 16 jmp short loc_F81
CMP MLTOP(X) ; Is it the one moving ? | 0F6B 90 db 90h
JRNZ PT23 ; No - jump | 0F6C loc_F6C:
STA PTSCK ; Save position as a flag | 0F6C 8A C2 mov al, dl
JMP PT23 ; Jump | 0F6E 3A 06 DC 09 cmp al, [ds:byte_9DC]
PT20: LXI H,PTSW1 ; Previous maximum points won | 0F72 72 04 jb short loc_F78
CMP M ; Compare to current value | 0F74 86 06 DC 09 xchg al, [ds:byte_9DC]
JRC .+4 ; Jump if greater than | 0F78 loc_F78:
LDA A,M ; Load previous max value | 0F78 3A 06 DD 09 cmp al, [ds:byte_9DD]
LDA M,E ; Store new value as max won | 0F7C 72 03 jb short loc_F81
LXI H,PTSW2 ; Previous 2nd max points won | 0F7E A2 DD 09 mov [ds:byte_9DD], al
CMP M ; Compare to current value | 0F81 loc_F81:
JRC PT23 ; Jump if greater than | 0F81 8A C6 mov al, dh
LDA M,A ; Store as new 2nd max lost | 0F83 F6 06 D0 09 80 test [ds:byte_9D0], 80h
PT23: LXI H,Pl ; Get piece | 0F88 74 02 jz short loc_F8C
BIT 7,M ; Test color | 0F8A F6 D8 neg al
LDA A,D ; Value of piece | 0F8C loc_F8C:
JRZ .+4 ; Jump if white | 0F8C 00 06 DE 09 add [ds:byte_9DE], al
NEG ; Negate for black | 0F90 loc_F90:
LXI H,MTRL ; Get addrs of material total | 0F90 8B 1E B6 09 mov bx, [word ptr ds:loc_9B6]
ADD M ; Add new value | 0F94 43 inc bx
LDA M,A ; Store | 0F95 83 FB 63 cmp bx, 63h ; ; At end of board ?
PT25: LDA M3 ; Get current board position | 0F98 73 03 jnb short loc_F9D
INR A ; Increment | 0F9A E9 27 FF jmp loc_EC4
CPI 99 ; At end of board ? | 0F9D loc_F9D:
JNZ PT5 ; No - jump | 0F9D 80 3E E1 09 00 cmp [ds:byte_9E1], 0
LDA PTSCK ; Moving piece lost flag | 0FA2 74 0B jz short loc_FAF
ANA A ; Was it lost ? | 0FA4 A0 DD 09 mov al, [ds:byte_9DD]
JRZ PT25A ; No - jump | 0FA7 A2 DC 09 mov [ds:byte_9DC], al
LDA PTSW2 ; 2nd max points won | 0FAA C6 06 DD 09 00 mov [ds:byte_9DD], 0
STA PTSW1 ; Store as max points won | 0FAF loc_FAF:
XRA A ; Zero out 2nd max points won | 0FAF A0 DB 09 mov al, [ds:byte_9DB]
STA PTSW2 | 0FB2 3C 00 cmp al, 0
PT25A: LDA PTSL ; Get max points lost | 0FB4 74 02 jz short loc_FB8
ANA A ; Is it zero ? | 0FB6 FE C8 dec al
JRZ .+3 ; Yes - jump | 0FB8 loc_FB8:
DCR A ; Decrement it | 0FB8 8A E8 mov ch, al
LDA B,A ; Save it | 0FBA A0 DC 09 mov al, [ds:byte_9DC]
LDA PTSW1 ; Max,points won | 0FBD 3C 00 cmp al, 0
ANA A ; Is it zero ? | 0FBF 74 0B jz short loc_FCC
JRZ .+11. ; Yes - jump | 0FC1 A0 DD 09 mov al, [ds:byte_9DD]
LDA PTSW2 ; 2nd max points won | 0FC4 3C 00 cmp al, 0
ANA A ; Is it zero ? | 0FC6 74 04 jz short loc_FCC
JRZ .+5 ; Yes - jump | 0FC8 FE C8 dec al
DCR A ; Decrement it | 0FCA D0 E8 shr al, 1
SRLR A ; Divide it by 2 | 0FCC loc_FCC:
SUB B ; Subtract points lost | 0FCC 2A C5 sub al, ch
LXT 9,COLOR ; Color of side just moved | 0FCE F6 06 CF 09 80 test [ds:byte_9CF], 80h ; Is it white ?
BIT 7,M ; Is it white ? | 0FD3 74 02 jz short loc_FD7
JRZ .+4 ; Yes - jump | 0FD5 F6 D8 neg al
NEG ; Negate for black | 0FD7 loc_FD7:
LXI H,MTRL ; Net material on board | 0FD7 02 06 DE 09 add al, [ds:byte_9DE]
ADD M ; Add exchange adjustments | 0FDB 2A 06 E0 09 sub al, [ds:byte_9E0]
SUB M ; Subtract from current | 0FDF B5 1E mov ch, 1Eh ; Load material limit
LDA B,A ; Save | 0FE1 E8 BC FB call near ptr loc_B9F+1 ; Limit to plus or minus value
MVI A,30 ; Load material limit | 0FE4 8A D0 mov dl, al
CALL LIMIT ; Limit to plus or minus value | 0FE6 A0 DA 09 mov al, [ds:byte_9DA]
LDA E,A ; Save limited value | 0FE9 2A 06 DF 09 sub al, [ds:byte_9DF]
LDA BRDC ; Get board control points | 0FED loc_FED:
LXI H,BCO ; Board control at ply zero | 0FED 80 3E E1 09 00 cmp [ds:byte_9E1], 0
SUB M ; Get difference | 0FF2 74 02 jz short loc_FF6
LDA B,A ; Save | 0FF4 B0 00 mov al, 0
LDA PTSCK ; Moving piece lost flag | 0FF6 loc_FF6:
ANA A ; Is it zero ? | 0FF6 B5 06 mov ch, 6 ; Load board control limit
JRZ .+4 ; Yes - jump | 0FF8 E8 A5 FB call near ptr loc_B9F+1 ; Limit to plus or minus value
MVI B,0 ; Zero board control points | 0FFB D0 E2 shl dl, 1
MVI A,6 ; Load board control limit | 0FFD D0 E2 shl dl, 1 ; Multiply by 4
CALL LIMIT ; Limit to plus or minus value | 0FFF 02 C2 add al, dl
LDA D,A ; Save limited value | 1001 F6 06 CF 09 80 test [ds:byte_9CF], 80h ; Is it white ?
LDA A,E ; Get material points | 1006 75 02 jnz short loc_100A ; No - jump
ADD A ; Multiply by 4 | 1008 F6 D8 neg al ; Negate for white
ADD A | 100A loc_100A:
ADD D ; Add board control | 100A 04 80 add al, 80h ; Rescale score (neutral = 80H
LXI H,COLOR ; Color of side just moved | 100C A2 D9 09 mov [ds:byte_9D9], al
BIT 7,M ; Is it white ? | 100F 8B 1E C4 09 mov bx, [ds:word_9C4]
JRNZ .+4 ; No - jump | 1013 88 47 05 mov [bx+5], al
NEG ; Negate for white | 1016 C3 retn
ADI 80H ; Rescale score (neutral = 80H | 1016 endp sub_EA8
STA VALM ; Save score
LIXD MLPTRJ ; Load move list pointer
LDA MLVAL(X),A ; Save score in move list
RET ; Return
Cordially.