## ChesSkelet: micro chess program - 363 Bytes

The place for codemasters or beginners to talk about programming any language for the Spectrum.
arkannoyed
Manic Miner
Posts: 374
Joined: Mon Feb 05, 2018 9:56 am

### Re: ChesSkelet: micro chess program - 363 Bytes

Just wondering if it needs to be the case in this routine that you don't apply the result into L directly as opposed to C then L. Does it need to be saved into C for use elsewhere, as I can't find it.

Code: Select all

``````celloo				; prepare x88 check (7B)
ld a, d		; delta loaded
add a, c	; current target (sq. + delta)
ld c, a		; current target [does the result need to go into C?]
and \$88		; 0x88, famous OOB trick
jr nz, vecnex	; ---v exit: OOB, next vector

inc h		; H(L)= \$80 = boasth ++
ld l, c		; point at target square [could the result of ld a,d, add a,c go straight into L?]
ld a, (hl)	; read target square content

; mark attacked ### str. pawn marked attacked
inc h		; H(L)= \$81 = boaath ++
ld (hl), h	; mark attacked (\$81)
dec h		; H(L)= \$80 = boasth ++

dec h		; H(L)= \$79= movlih ++``````
Might be missing something though, as is often the case.
0 x

reeagbo
Berk
Posts: 39
Joined: Mon Apr 29, 2019 8:11 am

### Re: ChesSkelet: micro chess program - 363 Bytes

arkannoyed wrote:
Thu Jun 06, 2019 10:26 am
Just wondering if it needs to be the case in this routine that you don't apply the result into L directly as opposed to C then L. Does it need to be saved into C for use elsewhere, as I can't find it.

Code: Select all

``````celloo				; prepare x88 check (7B)
ld a, d		; delta loaded
add a, c	; current target (sq. + delta)
ld c, a		; current target [does the result need to go into C?]
and \$88		; 0x88, famous OOB trick
jr nz, vecnex	; ---v exit: OOB, next vector

inc h		; H(L)= \$80 = boasth ++
ld l, c		; point at target square [could the result of ld a,d, add a,c go straight into L?]
ld a, (hl)	; read target square content

; mark attacked ### str. pawn marked attacked
inc h		; H(L)= \$81 = boaath ++
ld (hl), h	; mark attacked (\$81)
dec h		; H(L)= \$80 = boasth ++

dec h		; H(L)= \$79= movlih ++``````
Might be missing something though, as is often the case.
Very good one. I had a quick glance and it seems like we could save a byte there. As you say we could (in theory) use L directly instead of C. Let me test it and I´ll get back early next week. We would need to start changing thing ever before, from celloo tag and on.

Alex
1 x

arkannoyed
Manic Miner
Posts: 374
Joined: Mon Feb 05, 2018 9:56 am

### Re: ChesSkelet: micro chess program - 363 Bytes

Do you have any projection yet as to what sort of size its going to be down to now? Sub 350 bytes?
0 x

reeagbo
Berk
Posts: 39
Joined: Mon Apr 29, 2019 8:11 am

### Re: ChesSkelet: micro chess program - 363 Bytes

arkannoyed wrote:
Thu Jun 06, 2019 2:20 pm
Do you have any projection yet as to what sort of size its going to be down to now? Sub 350 bytes?
Best case would be 351,but I need to verify this last change. "genmov" is very sensitive to changes. It took me ages to make it work.
0 x

hitm4n
Microbot
Posts: 116
Joined: Fri Nov 17, 2017 12:56 pm

### Re: ChesSkelet: micro chess program - 363 Bytes

Do it gently and it'll slide in...
0 x
I don't have anything cool to put here, so i'll just be off now to see a priest with yeast stuck between his teeth and his friend called Keith who's a hairpiece thief...

reeagbo
Berk
Posts: 39
Joined: Mon Apr 29, 2019 8:11 am

### Re: ChesSkelet: micro chess program - 363 Bytes

reeagbo wrote:
Thu Jun 06, 2019 1:59 pm
arkannoyed wrote:
Thu Jun 06, 2019 10:26 am
Just wondering if it needs to be the case in this routine that you don't apply the result into L directly as opposed to C then L. Does it need to be saved into C for use elsewhere, as I can't find it.

Code: Select all

``````celloo				; prepare x88 check (7B)
ld a, d		; delta loaded
add a, c	; current target (sq. + delta)
ld c, a		; current target [does the result need to go into C?]
and \$88		; 0x88, famous OOB trick
jr nz, vecnex	; ---v exit: OOB, next vector

inc h		; H(L)= \$80 = boasth ++
ld l, c		; point at target square [could the result of ld a,d, add a,c go straight into L?]
ld a, (hl)	; read target square content

; mark attacked ### str. pawn marked attacked
inc h		; H(L)= \$81 = boaath ++
ld (hl), h	; mark attacked (\$81)
dec h		; H(L)= \$80 = boasth ++

dec h		; H(L)= \$79= movlih ++``````
Might be missing something though, as is often the case.
Very good one. I had a quick glance and it seems like we could save a byte there. As you say we could (in theory) use L directly instead of C. Let me test it and I´ll get back early next week. We would need to start changing thing ever before, from celloo tag and on.

Alex
Hi,

I was looking into your proposition, and unfortunately it won't fly. C is used to store the target square and it's used later:

Code: Select all

``````				; add candidate (B: current square, C: target square) (9B)
push hl
ld hl, canlis	; HL: start of candidate list. No H reuse ++
inc (hl)	; +2 to candidate counter to move to next
inc (hl)	; first free position in list
ld l, (hl)	; point at free position

ld (hl), b	; 1) save origin square
inc hl		; move to next byte
ld (hl), c	; 2) save dest square
legend					pop hl		; recover HL=pointer to vector list
``````
As you can see it's not possible to use L instead, as L is already used down here. I thought of using DE, but DE is not an option to replace HL, since some of the instructions do not exist. Thanks for trying anyway. It looked very good.

Alex
1 x

arkannoyed
Manic Miner
Posts: 374
Joined: Mon Feb 05, 2018 9:56 am

### Re: ChesSkelet: micro chess program - 363 Bytes

Back to the Drawing Board eh? Never mind. When everything is so tightly stressed, you have to explore even the most abstract concepts to try and achieve a smaller size. Obsessing over saving even one byte becomes the norm.
0 x

reeagbo
Berk
Posts: 39
Joined: Mon Apr 29, 2019 8:11 am

### Re: ChesSkelet: micro chess program - 363 Bytes

After some lazy days, I've managed to put together all the dissection entries and create a single article with the whole thing, revised and cleaned up a bit. Those who need to get depressed, look here:
http://chesskelet.x10host.com/dissection.html

It's like a 50 page word document for a bunch of bytes. It can't get more ridiculous.

I was watching this documentary on how AlphaGo was developed and managed to beat the World Champion. It reminds me so much of what we do here that thought "I have to post this":
https://www.netflix.com/title/80190844

2 x

arkannoyed
Manic Miner
Posts: 374
Joined: Mon Feb 05, 2018 9:56 am

### Re: ChesSkelet: micro chess program - 363 Bytes

The lengthy write up is actually much easier to read than what you posted on here, mostly I think because the code snippets are clearer to read. Having it all in one go is much nicer to read. Thanks for the mention too!

1 x

reeagbo
Berk
Posts: 39
Joined: Mon Apr 29, 2019 8:11 am

### Re: ChesSkelet: micro chess program - 363 Bytes

ChesSkelet v0.811 released. 352 bytes for the smallest version!

All details in http://chesskelet.x10host.com/

Have a good weekend.
Alex
2 x