n2cube.asm
For the cube: Gnubby's chances (of winning, and of gammons won and lost) and equity, by the network and a move deeper. Download · All the source
; --------------------------------------------------------------- n2cube; For the cube: the side on roll's equity by the main net at 0-ply (eq0); and a ply deeper (ply1), 8192 a point, with the outcomes' weights in VW,; into RES (24 bits), and its chances (of winning, and the extra points; of gammons won and lost, 8192 for 1) into SPW. The reference is; n2ref.ax's `stats0`, `stats1` (`equity0`, `equity1`).; eq0: HL -> a board (the side on roll first): RES and HL = its equity,; SPW its chances. The board is left in ROOT2 (encode.asm's PA, PB).eq0: di ld de,ROOT2 ld bc,64 ldir ld hl,ROOT2 call offs ld hl,ROOT2 xor a call accscan xor a ld (GTARGET),a ld hl,ACC2 call evrec ld hl,ROOT2 ld de,ROOT2+OPPOFF call evalhd push hl call stats pop hl; setres: RES = HL, sign-extended.setres: ld (RES),hl ld a,h rla sbc a,a ld (RES+2),a ret; ply1: RES = the equity of the side on roll in ROOT a ply deeper: over its; 21 rolls (non-doubles twice), the net's equity after the play it would; make (the filter's best 2 scored by the net, as `decide` scores plays,; the better taken; exact for a play bearing off its last checker; with; no play, the other side's equity on roll negated); the mean, rounded; toward 0. SPW: the same means of the chances. Calls TICK before each; roll.P1KEEP equ 4 ; plays scored a roll (in P1LIST)ply1: di ld hl,ROOT call offs ld hl,ROOT call fbase ld hl,ROOT ld a,1 call accscan ; ACC2: ROOT's, from the other side ld a,10 ld (LSZ),a ld a,P1KEEP ld (P1LIST+1),a ld hl,PSUM ; PSUM and TOTAL (VARS+48 to +63) ld b,16.z: ld (hl),0 inc hl djnz .z ld hl,$0101.roll: ld (DHI),hl call proll call addall ld a,(DHI) ld b,a ld a,(DLO) cp b call nz,addall ld hl,(DHI) ld a,h cp l inc h jr c,.roll ld h,1 inc l ld a,l cp 7 jr c,.roll ; RES = TOTAL / 36 (TOTAL is within 24 bits) ld hl,(TOTAL) ld a,(TOTAL+2) ld c,a ld a,(TOTAL+3) or a push af call m,neg24 ; |TOTAL| call d36 pop af call m,neg24 ld (RES),hl ld a,c ld (RES+2),a ; the chances' means ld hl,PSUM ld de,SPW call mean call mean; mean: (DE) = the 24-bit sum at HL / 36 (16 bits); HL, DE past them.mean: push de ld e,(hl) inc hl ld d,(hl) inc hl ld c,(hl) inc hl push hl ex de,hl call d36 ex de,hl pop hl ex (sp),hl ld (hl),e inc hl ld (hl),d inc hl ex de,hl pop hl ret; neg24: CHL = -CHL.neg24: xor a sub l ld l,a ld a,0 sbc a,h ld h,a ld a,0 sbc a,c ld c,a ret; proll: HL = the value to the side on roll at ROOT of its roll DHI, DLO.proll: call TICK ; the caller's, each roll (any registers) xor a ld (WIN),a ld (P1LIST),a ld hl,hply1 call genroot ld hl,(GCOUNT) ld a,h or l jr nz,.some ; no play: the other side on roll as it is xor a ld (GTARGET),a ld hl,ACC2 call evrec ld hl,ROOT+OPPOFF ld de,ROOT call evalhd push hl call stats call flipb pop hl jp neghl.some: ld hl,ROOT ld (GROOT),hl ld a,(WIN) or a jr z,.pick ; its last checker borne off: a single, gammon or backgammon ld hl,WINSTEPS call replay ld a,(W+OPPOFF+25) or a ld b,0 ld a,(VW+0) jr nz,.v ld hl,W+OPPOFF+18 ld b,7 xor a.bk: or (hl) inc hl djnz .bk ld b,64 ld a,(VW+2) jr nz,.v ld b,32 ld a,(VW+1).v: ld hl,8192 ; won: SBEST = 1, the gammons' points, 0 ld (SBEST),hl ld l,0 ld h,b ld (SBEST+2),hl ld h,l ld (SBEST+4),hl ld h,a ret.pick: ; the filter's best: the greatest of our equities after them ld hl,0 ld (RWORST),hl ld a,1 ld (GREC),a ld a,(P1LIST) ld (RCNT),a ld hl,P1LIST+4.r: push hl call replay ld hl,ACC2 call evalw call neghl ld a,h xor $80 ld d,a ld e,l ld hl,(RWORST) or a sbc hl,de jr nc,.k ld (RWORST),de call stats call flipb.k: pop hl ld de,10 add hl,de ld a,(RCNT) dec a ld (RCNT),a jr nz,.r xor a ld (GREC),a ld hl,(RWORST) ld a,h xor $80 ld h,a ret; neghl: HL = -HL.neghl: xor a sub l ld l,a sbc a,a sub h ld h,a ret; hply1: a play of the side on roll: taken if it bears off its last; checker, else into P1LIST by its filter's score.hply1: ld a,(WIN) or a ret nz ld a,(W+25) cp 15 jp z,hwin call fscore ld a,(P1LIST) cp P1KEEP jr c,.in ld a,(P1LIST+2+10*(P1KEEP-1)) ; a full list: better than its last only cp d jr c,.in ret nz ld a,(P1LIST+3+10*(P1KEEP-1)) cp e ret nc.in: push de call mksteps pop de ld hl,P1LIST jp linsert; d36: CHL = CHL / 36 (unsigned).d36: xor a ld b,24.d: add hl,hl rl c rla cp 36 jr c,.n sub 36 inc l.n: djnz .d ret; addall: TOTAL += HL (signed), PSUM += SBEST. Keeps HL.addall: call addtot push hl ld hl,SBEST ld de,PSUM ld b,3.a: ld a,(de) add a,(hl) ld (de),a inc hl inc de ld a,(de) adc a,(hl) ld (de),a inc hl inc de ld a,(de) adc a,0 ld (de),a inc de djnz .a pop hl ret; flipb: SBEST = the chances in SPW, of the other side: 1 less its; winning, its gammons lost and won.flipb: ld hl,8192 ld de,(SPW) or a sbc hl,de ld (SBEST),hl ld hl,(SPW+4) ld (SBEST+2),hl ld hl,(SPW+2) ld (SBEST+4),hl ret