3D Chess 2K18

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
hitm4n
Manic Miner
Posts: 604
Joined: Fri Nov 17, 2017 12:56 pm

Re: 3D Chess 2K18

Post by hitm4n »

Hi there, i know you may sometimes post some stuff and then get a lack of replies, but if many are like me, we sit and lurk and keep tabs on things. I'm quite keenly following your progress, i check in daily to see whats new here, and i have to say its astounding what you have squeezed into under 500 teeny itty bitty bytes.

We all know of the age old 1k chess that exists, ascii gfx, poor rule set and slow. But without doubt a marvelous achievement.
Is your ultimate goal to create a 1k chess game but with a 3d board and full rule set? If so, then that would be an even wilder achievement.

Anyway, back to lurking :)
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...
User avatar
hitm4n
Manic Miner
Posts: 604
Joined: Fri Nov 17, 2017 12:56 pm

Re: 3D Chess 2K18

Post by hitm4n »

Sheesh, and your last message before mine states exactly that...

Well, good luck, i'm keeping tabs.
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...
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Yes, the ultimate goal is to create a chess game that’s as fully featured as will fit into the 1k limit. So although all this squeezing of the core display code might sometimes seem somewhat pointless, actually every byte saved allows more space to include more functionality. I already have the legal move checking etc pretty much done, and the method that the gui will adopt is between 2 options, both easy to implement within the structure of the display code.

As far as the code squeezing goes, I saved a further 2 bytes last night, both in key areas too, which is where it gives the biggest improvement results too.

The next line up routine is now a byte smaller, though perhaps a few clicks slower, but nothing significant.

Then I managed to save another byte with some nifty code recycling in the print the left part of the line routine. That came down from 24 to 22 bytes yesterday, which even I was astounded by.

Interestingly (well to me anyway!) the total size, which only a few months ago I thought would be impossible to get near 512 bytes, is now at just 516 bytes. I’ve managed to save 36 bytes in about 3 months.

I do STILL need to rewrite the board initialising routine, and attempts so far have not managed smaller than 41 bytes. I’m favouring a recursive approach where it’s created algorithmically. I have a version that dies that in 48 bytes, but that was an early attempt. I’m sure sub 40 is possible.

So far all this continual development has fortunately not made the code any harder to add the GUI functions into, which is lucky.
User avatar
uglifruit
Manic Miner
Posts: 700
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: 3D Chess 2K18

Post by uglifruit »

I'm going to chip in and also state I'm a (gobsmacked) lurker in here too, and massively appreciated the time and effort you're putting into this, not only to code it, but also to share the process with the forum. My meagre z80 assembly efforts make me aware of his monumental a task you are setting yourself here. So on behalf of the silent onlookers I just wanted to say thanks, and say I'd welcome any further up updates as they come.
CLEAR 23855
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Very kind, thank you. I appreciate that this is very much a personal crusade so far, and perhaps not something everyone might even understand the point of. But it good to know people are still looking at any updates that trickle through. I must confess, my z80 skills have improved a whole heap since I started this process. Although I still have a lot of areas of the Speccy that I’m not entirely familiar with, I’d like to think that the screen handling is now one thing I understand pretty well.

Anyway, another 2 bytes saved yesterday evening.

Incredibly, the left side print routine managed to shrink by another byte, so that’s 3 in as many days!!

I also moved the piece heights table to FF80h to take advantage of using the carry always being set prior to finding the current piece height for the print loop.

I’ll have to re-comment the altered source before I can post any details as it’s got a bit messy with all the changes.

Main routines are now only 249 bytes
Including the data 474 bytes

Total size 514 bytes

Maybe, just maybe development might move on to the next stage once those final 2 bytes can be saved. :o
User avatar
Pegaz
Dynamite Dan
Posts: 1209
Joined: Mon Nov 13, 2017 1:44 pm

Re: 3D Chess 2K18

Post by Pegaz »

arkannoyed wrote: Sun Apr 28, 2019 9:00 amMaybe, just maybe development might move on to the next stage once those final 2 bytes can be saved. :o
I totally agree with that. :)
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Changed the left print routine now to this at 21 bytes;

Code: Select all

get_lhs:
           ex de,hl                          ;swap addressing SCReen to DE
           pop hl                            ;LHS data retrieve from stack
           ld c,80h                          ;left bit mask set +1 right so that DEC L happens
left:
           rlc c                             ;next left bit
           jr nc,left_ovr                    ;
           dec e                             ;next left screen address
left_ovr:
           ld a,(de)                         ;get the SCReen byte in A
           or c                              ;set bit to 1
           xor c                             ;reset bit to 0
           adc hl,hl                         ;propagate data in HL to get MSB
left_set:
           ld (de),a
           ret z                             ;if result of shift gave zero then RET
           jr nc,left                        ;if no carry then loop
           or c
           jr left_set                       ;write result by looping back and as OR has cleared carry
                                             ;and the result will not be zero then we can continue
                                             ;the loop
First time I've really had an opportunity to use ADC HL,HL, but its 2 bytes smaller than doing individual register shifts, and it affects the Zero flag too, which in this case is a big help!

Also, as the next line up routine that follows once we RET has to POP the previous screen vector as a pre-corrected address, theres no need to restore the screen address when we exit here either.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: 3D Chess 2K18

Post by reeagbo »

Hi there,

Here Alex, the chesSkelet author. I just found this post accidentally and it's nice to see that we get to similar conclusions when thinking about this crazy thing. I need to dig into the details of your 3D Chess. I´m pretty curious at the moment.

FYI, I´m about to release a new version of the code, which is 370 bytes. It has many coding improvements and additional "strategy" improvements, particularly for the king under check, escaping and not being left uncovered. The big size version now will also include an option for castling. Let me know if you have any doubts on the current code (0.802c).
http://chesskelet.x10host.com/snapshots/

I saw the question on the pieces value, the thing is that those values are used for both pointing them for display, for move list generation and also the piece value during valuation. I have changed the king value to 8, so the I can identify it easily on the board through bit 3, (hl) whenever i need to.

I'm wondering if it would be worth opening a thread discussion details on chesSkelet...maybe later.

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

Re: 3D Chess 2K18

Post by arkannoyed »

Hi Alex,

I've not yet been back to your code to investigate the workings any further, but its an impressive achievement. The numbering of the pieces was of interest as far as any scoring or strength calculating thats done to decide upon the most suitable move to perform. Mine are simply numbered 1-6 (actually 2/3, 4/5, 6/7, 8/9, A/B, C/D when their Black or White identifier bit is added in) which is very very for indexing graphics data. Doesn't have to be, and they could be in any order actually.

I did begin to look at the possibility of a simple interpreter to scan through your board and piece format and display it using my 3D engine. You use a 128 byte board, whereas mine is 64 bytes. I can quite easily adapt to the larger format, which is easier to use for various legal move checks. Only adds about 5 bytes.

I'm now at the point where for my own sanity I need to save the final 2 bytes just to give me that satisfying 512 bytes total size. 1 disk sector!

Once thats done and I've fixed the board setting/ resetting routine, then it will be in its final release state. Then development and integration of the GUI aspects can be done, tested and finalised so that I can then move onto the game logic, some of which follows a similar route that you've taken evidently.

I'll be interested to see how you achieve castling, as I've not figured that one out yet.

Keep up the great development, really impressive effort!
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

I think you would get a lot of interest in a thread detailing Chesskelet. Chess still remains a fascinating subject in terms of programming etc.

If you do want to delve deeper into the 3D display routines, then I'm happy to send you the source, though I've posted it earlier in this thread. It has changed a bit since though.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: 3D Chess 2K18

Post by reeagbo »

Hi, On your comments...

I've not yet been back to your code to investigate the workings any further, but its an impressive achievement. The numbering of the pieces was of interest as far as any scoring or strength calculating thats done to decide upon the most suitable move to perform. Mine are simply numbered 1-6 (actually 2/3, 4/5, 6/7, 8/9, A/B, C/D when their Black or White identifier bit is added in) which is very very for indexing graphics data. Doesn't have to be, and they could be in any order actually.

>>>> you´ll need to figure that out when your start looking at evaluation. My method is not standard. As you may now most valuations look like P=1, N=2,5, K=3, R=5, Q=8, K= inf. (more or mess). In my case, I'm not doing tree search, therefore no need to analyze multiple captures, only need to know which is more valuable.

I did begin to look at the possibility of a simple interpreter to scan through your board and piece format and display it using my 3D engine. You use a 128 byte board, whereas mine is 64 bytes. I can quite easily adapt to the larger format, which is easier to use for various legal move checks. Only adds about 5 bytes.

>>>>> I´ve found 16x8 byte board very helpful for OOD detection, and also end of rank and end of board loop detection. Also it allows managing the board coordinates in a single byte with this format (0rrr0ccc), r=rank (0...7), c=col (0...7), which simplifies the tasks above.

I'm now at the point where for my own sanity I need to save the final 2 bytes just to give me that satisfying 512 bytes total size. 1 disk sector!

>>>>> That is awesome for a 3D interface. :-)

Once thats done and I've fixed the board setting/ resetting routine, then it will be in its final release state. Then development and integration of the GUI aspects can be done, tested and finalised so that I can then move onto the game logic, some of which follows a similar route that you've taken evidently.

I'll be interested to see how you achieve castling, as I've not figured that one out yet.

>>>> you can find castling code in the code I shared (it's split in two places). Actually my code is a bit of a cheat, since it does not check for validity, only checks that the king is in the right place. For the rest it trusts the human player. Checking full castling validity involves keeping track of the king and rooks never having been moved, the king not being under check and none of the squares in between attacked. That would need me to re-write the whole thing. And only for the human player to use it. The "AI" in my program would never use it, it's not smart enough...

Keep up the great development, really impressive effort!

>>>> for the 3D interface, I´m not planning to make mine more complex, I would reduce it further if I could. Feel free to use any of my code in your program if that helps. I'd like to hear on any improvement, I think you mentioned something about that in other posts.
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

I'm so far hitting a wall with finding a method of saving these last 2 bytes. One of those days when no matter how hard I look at it, I can't find anywhere that could be optimised. Even looking for a cheat where I might be able to use any handy ROM routines in part yielded nothing.

There are 2 things that have remained pretty much unaltered since some very early versions. First is the routine that draws the lines of the board squares. No matter what method I've attempted, its bigger in bytes. For the playable version I do have a 5 byte longer version thats almost twice as fast, and is a bit easier to add-in the masking to give the squares a greyed-out shaded effect indicating that they're selected. What it does, it does fairly efficiently though.

The second is the board initialising/ resetting routine. Does ChessKelet do that, as I can't find reset routine in the source, or maybe I'm missing it? Einar kindly came up with the code for it a few years ago, and I've just left it there, not really changing it even though it has a bug where it reverses the Black and White King/ Queen positions. Every now and then I have a go at a new version, but usually give up after only managing to get to a larger than 40 byte size. I'm convinced there must be a way of achieving smaller, but so far its eluded me.
reeagbo
Dizzy
Posts: 61
Joined: Mon Apr 29, 2019 9:11 am

Re: 3D Chess 2K18

Post by reeagbo »

I used to include a reset routine to re-create the board in earlier version, but historically, other colleagues producing mini chess games under 500 bytes (total) did not make it replayable, I decided to remove it. However, at the time I thought of two solutions:

(1) placing the "initial" board somewhere else and copying it to the playing board (LDI or other solution). In my case that would cost around 40B-45B, including the "initial" board bytes. Not sure if this solution would apply in your case.

(2) a routine that creates the board from nothing. I was thinking of an array including which pieces and how many of them are needed to fill in the board. This array would be read by a routine that would fill in the board from the beginning to the middle and from the end backards to the middle. Never dug much into that, but I'm sure there is an affordable way to do it, but less than (1)? The nice thing is that with this option the game would be replayable at no cost, since this routine would be used to create the first game board too.

I'm thinking that, at the level you are coding at this point, my comments are worth nothing to you. :-D

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

Re: 3D Chess 2K18

Post by arkannoyed »

The board setting routine I use is as follows and simply copies some data, then adds +1 to those data bytes for pieces of the opposite colour.

Very simplistic, but flawed obviously.

I've written so, so many variations addressing in so many ways, that I've lost count. I WILL GET IT DONE!!!

As this will eventually be (hopefully) a fully game in under 1k, I have to include something that sets up the board, but I've noticed that many mini versions don't allow for this, which is fair I suppose.

The 64 byte board I use is aligned to FFC0h, so the end is and easy zero check.

Code: Select all

init_board:
           ld de,0ffc0h
           ld b,d
           ld c,d
           ld hl,data_17
ib_loop1:
           ld a,(hl)
           dec a
           ld (bc),a
           ldi
           jr nz,ib_loop1
           dec e
           ld b,20h
ib_loop2:
           ld (de),a
           inc e
           djnz ib_loop2

           ret                   ;23 bytes
data_17:
           db 05h,07h,09h,0bh,0dh,09h,07h,05h
           db 03h,03h,03h,03h,03h,03h,03h,03h,01h
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Theoretically then if you were to use an initialising routine, your total size should become smaller, as currently its fixed by the size of the board data?
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Well, not quite there, but this was a new approach thats managed 41 bytes

Code: Select all

init3:
          ld de,0ffbfh
          ld hl,data2s
lp13:
          ld c,(hl)
          xor a
          rrd
lp23:
          inc e
          ret z
          ld (de),a
          dec (hl)
          jr nz,lp23
          ld (hl),c
          inc l
          jr lp13
data2s:
          db 15h,17h,19h,1bh,1dh,19h,17h,15h
          db 83h,0f0h,0f0h,20h,82h
          db 14h,16h,18h,1ah,1ch,18h,16h,14h
The data is held in the lower 4 bits, and the counter (how many repeats of it to write) is in the upper 4 bits.

PLUS, it constructs the board correctly. Just that annoying 1 byte over!! Grrrrrrrrrrrrr!!!!!
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

...And another version, a bit faster, but sadly still 41 bytes!

Code: Select all

init2:
          ld de,0ffc0h
          ld hl,data2s
lp1:
          xor a
          ld c,(hl)
          rrd
          ld b,(hl)
          ld (hl),c
lp2:
          ld (de),a
          inc e
          djnz lp2
          inc hl
          jr nz,lp1
          ret
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

...However, that data is now conveniently ending with 06h,04h, which also reads to the Z80 as LD B,04h. I'm sure I've spotted that somewhere near the beginning of the Main Build Routine?! Oh yes, there it is!! So if I place the data just before it, adjust the address of everything down a bit, then we save 2 bytes.

So, the shiny new Initialise routine is 1 byte bigger overall, however, sharing 2 bytes lets us save 1 byte. Not the most helpful in terms of flexibility when it comes to adding functionality later, but, it works, and it gets to within 1 byte of the Holy Grail of 512!

So, total size now at 513 bytes :o

But more importantly, the board setup is now correct!
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: 3D Chess 2K18

Post by Einar Saukas »

arkannoyed wrote: Mon Apr 29, 2019 4:38 pm ...However, that data is now conveniently ending with 06h,04h, which also reads to the Z80 as LD B,04h. I'm sure I've spotted that somewhere near the beginning of the Main Build Routine?! Oh yes, there it is!! So if I place the data just before it, adjust the address of everything down a bit, then we save 2 bytes.

So, the shiny new Initialise routine is 1 byte bigger overall, however, sharing 2 bytes lets us save 1 byte. Not the most helpful in terms of flexibility when it comes to adding functionality later, but, it works, and it gets to within 1 byte of the Holy Grail of 512!

So, total size now at 513 bytes :o

But more importantly, the board setup is now correct!
I think you skipped a step in your explanation :)

You added INC B in order to reduce 1 byte in data2s, right?
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Correct, yes! Sorry, so focused on saving the byte and re-arranging the code that I omitted that fact. :oops:
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: 3D Chess 2K18

Post by Einar Saukas »

At least you know we are paying attention :)
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

Perhaps I should pay more attention! :D
d2010
Dizzy
Posts: 79
Joined: Tue Mar 26, 2019 9:19 am

Re: 3D Chess 2K18

Post by d2010 »

arkannoyed wrote: Mon Apr 29, 2019 5:32 pm Perhaps I should pay more attention! :D
:?:
I work 12hours-in-continuu(non-stop), is very hard (i cannot fix the colours of pieces,i can not inverse colours of pieces..
Perhaps, your pieces can be more dynamically, not static.
Believe me, is very , very hard,very hard (many bugs and crash,rewrite the some-code-sources.
some).
https://youtu.be/bpnSDqa2QNs
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: 3D Chess 2K18

Post by arkannoyed »

still confused!! :|
User avatar
Morkin
Bugaboo
Posts: 3251
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: 3D Chess 2K18

Post by Morkin »

...You'll probably be at a wedding when the registrar asks if anyone objects

...Or at a footy match during a 1 minute silence

...Or at a funeral

...And suddenly work out how to save that last byte....

I suspect you won't be able to contain yourself... :P
My Speccy site: thirdharmoniser.com
Post Reply