The MASM Forum

General => The Workshop => Topic started by: daydreamer on July 10, 2019, 03:43:16 AM

Title: chess engine
Post by: daydreamer on July 10, 2019, 03:43:16 AM
Hi
I read up on chess and bitboards benefit from run it 64bit because 64squares fit into register and benefit from 64bit muls
Anyone tried make a chess game with chess engine?

Title: Re: chess engine
Post by: hutch-- on July 11, 2019, 10:38:39 PM
Its not the register size that is complex with a chess game, its the size of the library which has to be truly massive to be effective. Its usually done with super computers.
Title: Re: chess engine
Post by: daydreamer on July 12, 2019, 12:52:36 AM
Quote from: hutch-- on July 11, 2019, 10:38:39 PM
Its not the register size that is complex with a chess game, its the size of the library which has to be truly massive to be effective. Its usually done with super computers.
there exist chess games running at slow 32bit cpus,I have to satisfy with newbie-chessengine level to begin with

I will take one step at a time,first step adviced is a bugfree representation of the board,bugfree important in handling all chess rules before doing search/evaluation part
maybe best output the underlying datasets to console for easier debug
Title: Re: chess engine
Post by: aw27 on July 12, 2019, 08:02:54 PM
You can download and inspect the stockfish source code (Elo 3438) and try to improve on it.  :icon_idea: Despite being the best chess engine, it is all made in "slow" C++  :sad: . May be translating some parts to Asm will improve it even further.
Title: Re: chess engine
Post by: FORTRANS on July 12, 2019, 10:29:45 PM
Hi,

   For your amusement only:

"SARGON A COMPUTER CHESS PROGRAM", by Dan and
Kathe Spracklen, Hayden Book Company, Inc., 1978.
A well commented Z-80 assembly language program to
play chess.  With 114 pages of mostly code, some
commentary. a description of Z-80 opcodes, and so forth.

   Amazing what gets on your bookshelf.

Cheers,

Steve N.
Title: Re: chess engine
Post by: daydreamer on July 12, 2019, 11:27:23 PM
thanks AW,I check that source up
thanks steve,how big is the final z80 program?
Title: Re: chess engine
Post by: FORTRANS on July 13, 2019, 12:42:48 AM
Hi,

Quote from: daydreamer on July 12, 2019, 11:27:23 PM
thanks steve,how big is the final z80 program?

   A quote from the introduction; "The program occupies
8K of RAM, which includes 2K of data areas, 2K graphics
display and user interface, and 4K of move logic."  Hm,
Jochen might be pleased with the lack of code bloat?

Regards,

Steve
Title: Re: chess engine
Post by: jj2007 on July 13, 2019, 02:48:15 AM
Quote from: FORTRANS on July 13, 2019, 12:42:48 AM
Jochen might be pleased with the lack of code bloat?

I am, I am, Steve, although my standards have shifted a little bit - I tolerate up to 40kB overhead nowadays. Still very little compared to the 8MB of a QT hello world proggie ;-)
Title: Re: chess engine
Post by: aw27 on July 13, 2019, 03:08:58 AM
Interesting, there is already a Stockfish ASM port (https://github.com/lantonov/asmFish), called ASMFish. It was developed in Flat Assembler G (https://flatassembler.net/docs.php?article=fasmg).  First time i hear about Flat Assembler G and seems like a masturbation paradise for Macro Lovers.
Title: Re: chess engine
Post by: TimoVJL on July 13, 2019, 03:10:55 AM
Quote from: jj2007 on July 13, 2019, 02:48:15 AM
I tolerate up to 40kB overhead nowadays. Still very little compared to the 8MB of a QT hello world proggie ;-)
C and C++ don't have that overhead, if programmers are gentle and have some sort of knowledge of CRT :winking:
Title: Re: chess engine
Post by: jj2007 on July 13, 2019, 03:38:56 AM
That's correct, Timo, but they also don't have commands like Recall (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1172) ;-)
                    include \masm32\MasmBasic\MasmBasic.inc
                    Init                                    ; show a data set from the World Health Organisation
                    Recall "https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates", who$(), csv
                    Print Str$("%i records downloaded", eax)
                    For_ ct=0 To who$(?)-1
                                Print CrLf$, who$(ct, 0)
                                Print At(33, Locate(y)) Spc2$, who$(ct, 4), Space$(40)
                                For_ ecx=8 To 14                ; columns 8...14 contain the data
                                                                Print At(ecx*8-25, Locate(y)) Spc2$, who$(ct, ecx)
                                Next
                    Next
                    EndOfCode


30kB is clearly too much, right? Show me the shorter C++ version ;-)
Title: Re: chess engine
Post by: daydreamer on July 13, 2019, 09:35:34 PM
Quote from: jj2007 on July 13, 2019, 03:38:56 AM
That's correct, Timo, but they also don't have commands like Recall (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1172) ;-)
                    include \masm32\MasmBasic\MasmBasic.inc
                    Init                                    ; show a data set from the World Health Organisation
                    Recall "https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates", who$(), csv
                    Print Str$("%i records downloaded", eax)
                    For_ ct=0 To who$(?)-1
                                Print CrLf$, who$(ct, 0)
                                Print At(33, Locate(y)) Spc2$, who$(ct, 4), Space$(40)
                                For_ ecx=8 To 14                ; columns 8...14 contain the data
                                                                Print At(ecx*8-25, Locate(y)) Spc2$, who$(ct, ecx)
                                Next
                    Next
                    EndOfCode


30kB is clearly too much, right? Show me the shorter C++ version ;-)
cool :thumbsup:

great guys,smallest chessboard drawing a stretchblt and using a tiny checkered image?
8k chess.exe seem possible
Title: Re: chess engine
Post by: aw27 on July 14, 2019, 01:27:10 AM
@JJ
It is easy to replace your MasmBasic with a 3 or 4KB equivalent in C/C++.
But is even easier to do all that with a simple Powershell script, which shows clearly that your code has a few bugs.


$desiredColumns = 'country','year', 'e_rr_pct_new','e_rr_pct_new_lo','e_rr_pct_new_hi','e_mdr_pct_rr_new','source_rr_ret','source_drs_coverage_ret'
$web = New-Object Net.WebClient
$web.DownloadString("https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates") | ConvertFrom-Csv | Select $desiredColumns | Format-Table


Output:


country                                              year e_rr_pct_new e_rr_pct_new_lo e_rr_pct_new_hi e_mdr_pct_rr_new source_rr_ret source_drs_coverage_ret
-------                                              ---- ------------ --------------- --------------- ---------------- ------------- -----------------------
Afghanistan                                          2017 3.7          2               5.9             79               Model
Albania                                              2017 2.3          0.64            5.8             100              Surveillance  National
Algeria                                              2017 2.5          1.1             4.3             67               Model
American Samoa                                       2017 2.3          0.86            4.4             78               Model
Andorra                                              2017 0            0               98              100              Surveillance  National
................... Cut

Zimbabwe                                             2017 4.6          3               6.2             39               Survey        National
Title: Re: chess engine
Post by: jj2007 on July 14, 2019, 08:16:29 AM
Which bugs?
Title: Re: chess engine
Post by: aw27 on July 14, 2019, 02:44:56 PM
Quote from: jj2007 on July 14, 2019, 08:16:29 AM
Which bugs?

You clip column names to the point of appearing as duplicates. You clip results to the point of being clueless.
So, you may need a function to calculate the needed columns widths before printing, it is risky to arbitrate some fixed value and shoot.
And you show a double quote at the start of each line, only God knows why.
Title: Re: chess engine
Post by: jj2007 on July 14, 2019, 07:50:48 PM
Quote from: AW on July 14, 2019, 02:44:56 PMAnd you show a double quote at the start of each line, only God knows why.

That's a bug indeed, I'll have to investigate. The rest is nonsense.

P.S.: That WHO csv file is kind of malformed, as it uses quotes where there is no need for quotes. If you open it in Excel and save it, the quotes will be removed.

In MasmBasic, there is a simple workaround: A Csv2Tab (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1271) right after the Recall. Works perfect.

As always, csv is a can of worms.
Title: Re: chess engine
Post by: aw27 on July 15, 2019, 12:24:30 AM
Quote from: jj2007 on July 14, 2019, 07:50:48 PM
The rest is nonsense.
It's common sense, but that's OK  :thumbsup:. Note that with Powershell you can do it, and even change the table titles:


$desiredColumns = 'country','year', 'e_rr_pct_new','e_rr_pct_new_lo','e_rr_pct_new_hi','e_mdr_pct_rr_new','source_rr_ret','source_drs_coverage_ret'
$web = New-Object Net.WebClient
$web.DownloadString("https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates") | ConvertFrom-Csv | Select $desiredColumns | Format-Table -AutoSize Country, Year, @{L='Header1';E={$_.e_rr_pct_new}}, @{L='Header2';E={$_.e_rr_pct_new_lo}}, @{L='Header3';E={$_.e_rr_pct_new_hi}},@{L='Header4';E={$_.e_mdr_pct_rr_new}},@{L='Header5';E={$_.source_rr_ret}},@{L='Header6';E={$_.source_drs_coverage_ret}}


Output:


country                                              year Header1 Header2 Header3 Header4 Header5      Header6
-------                                              ---- ------- ------- ------- ------- -------      -------
Afghanistan                                          2017 3.7     2       5.9     79      Model
Albania                                              2017 2.3     0.64    5.8     100     Surveillance National
Algeria                                              2017 2.5     1.1     4.3     67      Model
American Samoa                                       2017 2.3     0.86    4.4     78      Model
Andorra                                              2017 0       0       98      100     Surveillance National
Angola                                               2017 2.5     1.1     4.3     67      Model
Anguilla                                             2017 2.3     0.79    4.5     83      Model
Antigua and Barbuda                                  2017 2.3     0.79    4.5     83      Model
Argentina                                            2017 2.3     1.3     3.8     94      Survey       National
......
United Kingdom of Great Britain and Northern Ireland 2017 1.4     0.93    2       86      Surveillance National
United Republic of Tanzania                          2017 0.9     0.3     1.5     100     Survey       National
......
Zambia                                               2017 1.1     0.34    2.3     27      Survey       National
Zimbabwe                                             2017 4.6     3       6.2     39      Survey       National
Title: Re: chess engine
Post by: aw27 on July 15, 2019, 12:49:59 AM
Quote from: jj2007 on July 14, 2019, 07:50:48 PM
P.S.: That WHO csv file is kind of malformed, as it uses quotes where there is no need for quotes. If you open it in Excel and save it, the quotes will be removed.

You can only insert the double quotes when they are escaped, i.e, if you have 3 double quotes in a row.
Title: Re: chess engine
Post by: jj2007 on July 15, 2019, 01:07:24 AM
If you like this kind of stuff, try this UN database (http://mdgs.un.org/unsd/mdg/Handlers/ExportHandler.ashx?Type=Csv). Line 42257, for example (WB Staff estimates) is interesting. The correct decoding of column 1 would be

WB Staff estimates. Cambodia Poverty Assessment 2013 "Where Have All The Poor Gone?",  May 2013. Cambodia Socio-Economic Survey 2009.
Title: Re: chess engine
Post by: aw27 on July 15, 2019, 01:44:21 AM
Quote from: jj2007 on July 15, 2019, 01:07:24 AM
If you like this kind of stuff, try this UN database (http://mdgs.un.org/unsd/mdg/Handlers/ExportHandler.ashx?Type=Csv). Line 42257, for example (WB Staff estimates) is interesting. The correct decoding of column 1 would be

WB Staff estimates. Cambodia Poverty Assessment 2013 "Where Have All The Poor Gone?",  May 2013. Cambodia Socio-Economic Survey 2009.

All right, the UN database does not appear to conform to common practices.
However, the WHO.INT does appear to conform, they use double quotes even when not needed but there is nothing wrong with that.
Title: Re: chess engine
Post by: daydreamer on July 27, 2019, 07:35:48 PM
thanks for showing me ways of make .exe smaller with help of fetch data from website ala Java applet way JJ&AW

so far chessboard can be made with 33 rects but also 33 2D polys are prefered because you can draw a pseudo3d chessboard chesspieces can be made with GDI 2Dpolys or ellipses&lines,trouble with make knights look good
later it maybe possible to make with 3dmeshes,could be nice to have Marinus advice on this
Title: Re: chess engine
Post by: daydreamer on August 06, 2019, 02:11:06 AM
havent got so far,3dmeshcreator unfinished
included some unfinished meshes as well