ChesSkelet: micro chess program - 363 Bytes

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

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

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
			
				; read target square (3B)
				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. :?
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

arkannoyed wrote: Thu Jun 06, 2019 11: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
			
				; read target square (3B)
				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
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

Do you have any projection yet as to what sort of size its going to be down to now? Sub 350 bytes?
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

arkannoyed wrote: Thu Jun 06, 2019 3: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.
User avatar
hitm4n
Manic Miner
Posts: 604
Joined: Fri Nov 17, 2017 12:56 pm

Re: ChesSkelet: micro chess program - 363 Bytes

Post by hitm4n »

Do it gently and it'll slide in...
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
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

reeagbo wrote: Thu Jun 06, 2019 2:59 pm
arkannoyed wrote: Thu Jun 06, 2019 11: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
			
				; read target square (3B)
				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
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

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.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

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

:lol: :lol: :lol: :lol:
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

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! ;)

Really good read.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

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

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

Have a good weekend.
Alex
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

Hi all,

I know it's kind of unorthodox, but I need to contact Arkannoyed and he's not responding private messages or tweets. Anybody who know any other way to contact him?

Thank you!
Alex
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Ast A. Moore »

Life’s complicated. We’ve had plenty of people in the community going off the grid for a while. I don’t have any of his contacts, but it won’t hurt tagging him in a post like so: [mention]arkannoyed[/mention].

Who knows what his forum settings are; maybe he doesn’t receive notifications for private messages but does when he’s mentioned directly.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

Ello?!

Sorry, seems I’ve been very uncommunicative of late. Been busy with new job and don’t get time to do what I love with speccy things any more. I’m at your service Sir! :)
Alone Coder
Manic Miner
Posts: 401
Joined: Fri Jan 03, 2020 10:00 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Alone Coder »

Any chance to port this to Spectrum? https://habr.com/ru/post/478240/
https://github.com/leanchess/leanchess/ ... ter/LC.ASM
It searches moves in depth.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

Hi Alone Coder,

Arriving like 4 months late. Sorry, I´ve been away for a while. Ok, I know about Leanchess, and it did not occur to me the idea of porting it to Spectrum. That would be a super piece of work. Leanchess is made for 8086 and that is really a great advantage vs. Spectrum program. THe guy who did it really took the best of both worlds.It´s 8 bits, which is perfect for microchess, but the instruction set is way bigger than the Z80's. Imagine, there is one instruction to push all registers to the stack. How many instructions takes to do that in Z80? 8 minimum.

Part of the porting may not be so difficult, but I´m sure that some segments need many more instructions than in the 8086. Also,I don´t feel like getting into the guts of this other program. If you know someone who takes this, let me know.

Alex
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

Aonther thing,

I moved my site to

http://chesskelet.epizy.com/

in case someone feels like having a look. No changes or new contents for now.

Alex
User avatar
Lethargeek
Manic Miner
Posts: 734
Joined: Wed Dec 11, 2019 6:47 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Lethargeek »

reeagbo wrote: Thu Apr 16, 2020 7:19 pm Imagine, there is one instruction to push all registers to the stack. How many instructions takes to do that in Z80? 8 minimum.
OTOH the Z80 has more 8-bit registers and an instruction to swap 3 pairs with alternatives so it won't probably need to push that much
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by reeagbo »

Right! You could have helped me with my program! Anyway, I meant bytes.

With chesskelet it happened to me that I had all regular registers occupied, so I had no chance but pushing some, so the work, and popping then later,so this kind of thing would have saved mute from some headaches.
Supamax
Drutt
Posts: 23
Joined: Mon Oct 03, 2022 3:18 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Supamax »

The main links are not reachable anymore:

http://chesskelet.x10host.com/
http://chesskelet.epizy.com/

The last release I have is v0.811.
Is there a newer one?
Is it possible to have a .tap file of it, instead of a .sna? :)
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Wall_Axe »

So the a.i. only compares one move. Considering you have about 42,000 bytes left you could implement min max algorithm :) to make it really hard - lol

Out of interest how long does it take to load 350 bytes from tape?

I suppose you could put code in the screen memory as most of the screen is unused, therefore not using any more actual ram :) lol
User avatar
ParadigmShifter
Manic Miner
Posts: 596
Joined: Sat Sep 09, 2023 4:55 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by ParadigmShifter »

Was about 11 seconds or so for me to save a 363 byte block of random data. Most of that was the 2 lead ins and the header. Attribs are 768 bytes so less than half the time for that probably. (0s take longer to load than 1s which is weird since the 1s - being more pointy - must get stuck in the wires more when loading, the 0s being round can just roll down them?).

You don't need to use a lot of memory for minimax many 80s chess computers only had 4 or 8K of RAM. You can backtrack moves instead of storing them and if you know the order moves are generated in you can just use an index for the best move so far.

Negamax uses even less code memory

function negamax(node, depth, color) is
if depth = 0 or node is a terminal node then
return color × the heuristic value of node
value := −∞
for each child of node do
value := max(value, −negamax(child, depth − 1, −color))
return value

I think the idea is to make a chess game using as few bytes as possible in the machine code payload though so you just do the least thing to get it working. Nothing stopping them from using all the available RAM though - probably not needed for the above reasons. So implementing a proper search for decent moves is probably too large for their liking. I think the aim is to outdo the 1K ZX81 chess program for nerdiness ;)

Modern chess engines use megabytes of memory on hash tables of course to make searches quicker.
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: ChesSkelet: micro chess program - 363 Bytes

Post by Wall_Axe »

That's cool, the attributes take about three seconds to load so it must load so quickly :)

The 0's might have to push themselves down the wires
User avatar
ParadigmShifter
Manic Miner
Posts: 596
Joined: Sat Sep 09, 2023 4:55 am

Re: ChesSkelet: micro chess program - 363 Bytes

Post by ParadigmShifter »

Surely they make the wire wide enough for a 0 not to get jammed. It's bends and kinks in the wire that makes the 1s get stuck. That's like electronics 101
User avatar
uglifruit
Manic Miner
Posts: 700
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: ChesSkelet: micro chess program - 363 Bytes

Post by uglifruit »

ParadigmShifter wrote: Wed Feb 28, 2024 3:04 am That's like electronics 101
A.k.a. Electronics 5.
CLEAR 23855
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: ChesSkelet: micro chess program - 363 Bytes

Post by arkannoyed »

Wall_Axe wrote: Wed Feb 28, 2024 2:21 am I suppose you could put code in the screen memory as most of the screen is unused, therefore not using any more actual ram :) lol
I did exactly that in an experimental version of c2k19.
I’ll see if I can find it, though I think it’s probably here on an old thread.
It ran from the screen with ATTRs just concealing its location around the boards surroundings.
Post Reply