How to implement negamax search + eval using unsigned integers only?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
maksimKorzh
Posts: 775
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to implement negamax search + eval using unsigned integers only?

Post by maksimKorzh »

You're right.
Oscar Toledo did chess in 352 bytes of x86 machine codes,
MicroChess, first 'commercial' program ran on unexpanded KIM-1,
so it's possible.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to implement negamax search + eval using unsigned integers only?

Post by hgm »

Yes, it is possible. But the question is whether it would still be possible if you start bloating the code by using unnatural representation of integers.
User avatar
Ras
Posts: 2696
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: How to implement negamax search + eval using unsigned integers only?

Post by Ras »

maksimKorzh wrote: Sat Jun 04, 2022 2:17 pmCan anyone please gimme a clue on how can I alter my code so that it relies only on 8-bit unsigned type integers?
You could use dec 128 as your logical 0 value (i.e. draw score is 128). Anything below 128 corresponds to negative values in conventional engines, anything above 128 to positive ones.
Rasmus Althoff
https://www.ct800.net
benb
Posts: 16
Joined: Sat Dec 12, 2020 5:29 am
Full name: Ben Bradley

Re: How to implement negamax search + eval using unsigned integers only?

Post by benb »

maksimKorzh wrote: Sun Jun 05, 2022 4:48 pm You're right.
Oscar Toledo did chess in 352 bytes of x86 machine codes,
MicroChess, first 'commercial' program ran on unexpanded KIM-1,
so it's possible.
I recall that the source for Microchess is available online. Regardless, I still have an original printed manual with the source listing. Despite my knowledge of 6502 back then, I certainly didn't understand a lot of the Microchess code, but I do recall a thing or two.

One thing Microchess does is use a piece table (32 bytes, each giving the position of a piece) instead of a board array (which would take 64 bytes). This makes the code slower, harder to understand, and probably other bad things, but at least it runs on a KIM-1.

And I agree with others, 2's complement signed numbers are the natural signed type for the 6502, and using 1's complement (which to my knowledge is no longer used in any modern processors) would be a pain and bloat the code. I can only presume a C compiler for the 6502 uses types and condition codes properly.
User avatar
maksimKorzh
Posts: 775
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to implement negamax search + eval using unsigned integers only?

Post by maksimKorzh »

benb wrote: Tue Jun 07, 2022 10:01 pm
maksimKorzh wrote: Sun Jun 05, 2022 4:48 pm You're right.
Oscar Toledo did chess in 352 bytes of x86 machine codes,
MicroChess, first 'commercial' program ran on unexpanded KIM-1,
so it's possible.
I recall that the source for Microchess is available online. Regardless, I still have an original printed manual with the source listing. Despite my knowledge of 6502 back then, I certainly didn't understand a lot of the Microchess code, but I do recall a thing or two.

One thing Microchess does is use a piece table (32 bytes, each giving the position of a piece) instead of a board array (which would take 64 bytes). This makes the code slower, harder to understand, and probably other bad things, but at least it runs on a KIM-1.

And I agree with others, 2's complement signed numbers are the natural signed type for the 6502, and using 1's complement (which to my knowledge is no longer used in any modern processors) would be a pain and bloat the code. I can only presume a C compiler for the 6502 uses types and condition codes properly.
Thank you, I have Microchess listing, it's a real treasure)
User avatar
maksimKorzh
Posts: 775
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: How to implement negamax search + eval using unsigned integers only?

Post by maksimKorzh »

hgm wrote: Sun Jun 05, 2022 12:15 pm If I recall correctly the KIM-1 is a very small machine, with only 1.125KB of RAM. It will be a real challenge to fit a chess program in such a small amount of memory. So using inefficent code seems a very bad idea.
Mr. Muller, I've manages to implement it using signed integers, there's a hack for signed comparison in 6502.
Work is still in progress but it definitely would be under 1k of 6502 machine codes + data (data takes most of the zero page)
Currently it searches at depth 2 and comes up with absolutely the same moves as my C prototype!
Fantastic! I'm so happy!

It's not yet available for public testing (it will be soon)
for now I can offer a video demo of how it works:

and the source code (not finished yet):
https://github.com/maksimKorzh/6502-che ... /chess.asm

I know this is not something that would impress you and my 6502 is really ugly,
however I hope you'll enjoy how your MicroMax core is translated into 6502)
Please let me know what you think!