reviving old c# codebase engine, 0x88

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
spirch
Posts: 44
Joined: Thu Nov 08, 2012 11:36 pm

reviving old c# codebase engine, 0x88

Post by spirch » Fri Mar 05, 2021 3:56 am

hello, in the past 2 weeks i found an old copy of my chess engine in c# (from 2012/13) i never looked at it since then

using 0x88 board with bitwise operation, there is no instantiation done (after the container of the board is created), only use array / value type (long/int), etc

my board is simply defined by a simple:

long[] board = new long[0x88]

right now there is no hashing, no ai, no transposition table no nothing, it's just a simple move generator

what i have done in the past 2 weeks is relearn how i did it (wasnt easy, still learning) and i implemented some basic multi thread

single thread result

Code: Select all

  A B C D E F G H
1 ■ N ■ Q ■ B ■ R  Kind of perft: Normal Perft, doing all move/undo and only count the last depth
2 ■ R ■ B ■ K ■ N  Started 6 depths at 2021-03-04 22:40:56 finished at 2021-03-04 22:41:53
3 P ■ P ■ P ■ P ■  FEN: 1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
4 ■ P ■ P ■ P ■ P
5 p ■ p ■ p ■ p ■  Expected Moves   : 3,650,917,701
6 ■ p ■ p ■ p ■ p  Total Moves Done : 3,650,917,701
7 ■ r ■ b ■ k ■ n  Time Taken       : 56,330ms
8 ■ n ■ q ■ b ■ r  Moves per second : 64,813,025
multi thread result (12 core / 24 thread)
not really linear but i know why i think, i just did a very very basic implementation of multi threading

Code: Select all

  A B C D E F G H
1 ■ N ■ Q ■ B ■ R  Kind of perft: Normal Perft, doing all move/undo and only count the last depth
2 ■ R ■ B ■ K ■ N  Started 6 depths at 2021-03-04 22:39:46 finished at 2021-03-04 22:39:50
3 P ■ P ■ P ■ P ■  FEN: 1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
4 ■ P ■ P ■ P ■ P
5 p ■ p ■ p ■ p ■  Expected Moves   : 3,650,917,701
6 ■ p ■ p ■ p ■ p  Total Moves Done : 3,650,917,701
7 ■ r ■ b ■ k ■ n  Time Taken       : 4,018ms
8 ■ n ■ q ■ b ■ r  Moves per second : 908,640,542
(side question, how does it look speed wise?)

i think i will try to implement some AI in the next few weeks, i just need to figure out where to start and see what i can achieve, so this should be only the beginning of this thread (hopefully...)

mar
Posts: 2397
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: reviving old c# codebase engine, 0x88

Post by mar » Fri Mar 05, 2021 7:03 am

spirch wrote:
Fri Mar 05, 2021 3:56 am
FEN: 1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
wow, this invalid FEN crashes my engine. need to improve castling validation :o
not so long ago, there was a discussion about FEN validation :)

to sum up:
1) no castling possible
2) ep square is invalid

other than that, I think speed looks pretty good for a C# program I think
Martin Sedlak

User avatar
mvanthoor
Posts: 986
Joined: Wed Jul 03, 2019 2:42 pm
Location: Netherlands
Full name: Marcel Vanthoor
Contact:

Re: reviving old c# codebase engine, 0x88

Post by mvanthoor » Fri Mar 05, 2021 8:16 am

mar wrote:
Fri Mar 05, 2021 7:03 am
spirch wrote:
Fri Mar 05, 2021 3:56 am
FEN: 1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
wow, this invalid FEN crashes my engine. need to improve castling validation :o
not so long ago, there was a discussion about FEN validation :)

to sum up:
1) no castling possible
2) ep square is invalid

other than that, I think speed looks pretty good for a C# program I think
Good luck reviving the engine.

Mine just sets up the position you provided, exactly as is. It's not the place of the FEN-routine to check if the position is actually legal, IMHO. After setup, the FEN-routine could ask the engine, and then still reject the position if the engine deems it to be illegal or impossible.
Author of Rustic.
Releases | Code | Docs

spirch
Posts: 44
Joined: Thu Nov 08, 2012 11:36 pm

Re: reviving old c# codebase engine, 0x88

Post by spirch » Fri Mar 05, 2021 1:17 pm

haha yeah this is a FEN that someone gave me or I found more than 10 years ago, it was to test not if it was legal position but more about testing the move generation engine itself

reviving it is a challenge in itself, the original reason was to implement multi threading and now I think I want to try, again, to implement hash / transposition table / basic alpha/beta and more, i want to see where i can go from here

this might be a better one to compare 8-)
single thread

Code: Select all

  A B C D E F G H
1 R N B Q K B N R  Kind of perft: Normal Perft, doing all move/undo and only count the last depth
2 P P P P P P P P  Started 7 depths at 2021-03-05 08:09:21 finished at 2021-03-05 08:09:58
3 ■ ■ ■ ■ ■ ■ ■ ■  FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -
4 ■ ■ ■ ■ ■ ■ ■ ■
5 ■ ■ ■ ■ ■ ■ ■ ■  Expected Moves   : 3,195,901,860
6 ■ ■ ■ ■ ■ ■ ■ ■  Total Moves Done : 3,195,901,860
7 p p p p p p p p  Time Taken       : 36,679ms
8 r n b q k b n r  Moves per second : 87,131,651
multi thread

Code: Select all

  A B C D E F G H
1 R N B Q K B N R  Kind of perft: Normal Perft, doing all move/undo and only count the last depth
2 P P P P P P P P  Started 7 depths at 2021-03-05 08:12:41 finished at 2021-03-05 08:12:44
3 ■ ■ ■ ■ ■ ■ ■ ■  FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -
4 ■ ■ ■ ■ ■ ■ ■ ■
5 ■ ■ ■ ■ ■ ■ ■ ■  Expected Moves   : 3,195,901,860
6 ■ ■ ■ ■ ■ ■ ■ ■  Total Moves Done : 3,195,901,860
7 p p p p p p p p  Time Taken       : 2,999ms
8 r n b q k b n r  Moves per second : 1,065,655,838

User avatar
mvanthoor
Posts: 986
Joined: Wed Jul 03, 2019 2:42 pm
Location: Netherlands
Full name: Marcel Vanthoor
Contact:

Re: reviving old c# codebase engine, 0x88

Post by mvanthoor » Fri Mar 05, 2021 2:00 pm

I have seen this engine output before, somewhere. If you are running perft 7 without hash and without bulk counting, what are you doing to reach 87 million leaves per second?
Author of Rustic.
Releases | Code | Docs

spirch
Posts: 44
Joined: Thu Nov 08, 2012 11:36 pm

Re: reviving old c# codebase engine, 0x88

Post by spirch » Fri Mar 05, 2021 2:28 pm

mvanthoor wrote:
Fri Mar 05, 2021 2:00 pm
I have seen this engine output before, somewhere. If you are running perft 7 without hash and without bulk counting, what are you doing to reach 87 million leaves per second?
if you look up my post history, i posted a few threads/questions here a long time ago

maybe you have seen it back then.

i did very very very heavy optimization of my engine, i think i spent more time analyzing profiling result to find bottleneck more than anything
(this is why i'm still re-relearning how i did it, it's not that easy to read)

by memory, i would need to check again, I have zero GC collection while perft is running

spirch
Posts: 44
Joined: Thu Nov 08, 2012 11:36 pm

Re: reviving old c# codebase engine, 0x88

Post by spirch » Fri Mar 05, 2021 2:33 pm

if you look at my output:

doing all move/undo and only count the last depth

so i do counting of last depth legal move, i'm not doing the actual move

User avatar
mvanthoor
Posts: 986
Joined: Wed Jul 03, 2019 2:42 pm
Location: Netherlands
Full name: Marcel Vanthoor
Contact:

Re: reviving old c# codebase engine, 0x88

Post by mvanthoor » Fri Mar 05, 2021 2:38 pm

spirch wrote:
Fri Mar 05, 2021 2:33 pm
if you look at my output:

doing all move/undo and only count the last depth

so i do counting of last depth legal move, i'm not doing the actual move
So you're bulk-counting? That explains it. But you say literally: "doing all move/undo and only count the last depth".

Most people would take that as doing make/unmake, up to and including depth 0 (the leaves). If you're going up to and including depth = 1 (one step before the leaves) and then counting the number of moves in your move list (because you have a fully legal move generator), then you're bulk-counting. That's an enormous speed-up for perft, but not necessarily for actual playing. (That depends on how you wrote the fully legal move generator.)
Author of Rustic.
Releases | Code | Docs

spirch
Posts: 44
Joined: Thu Nov 08, 2012 11:36 pm

Re: reviving old c# codebase engine, 0x88

Post by spirch » Fri Mar 05, 2021 2:50 pm

i will see what happen if i do the last move/undo

User avatar
Ajedrecista
Posts: 1562
Joined: Wed Jul 13, 2011 7:04 pm
Location: Madrid, Spain.
Contact:

Re: Reviving old C# codebase engine, 0x88.

Post by Ajedrecista » Fri Mar 05, 2021 9:02 pm

Hello:

JetChess perft counter does not allow this FEN as input. OTOH, gperft 1.1 accepts it, so I have computed some perft values as a sanity check if you are curious about other values of this weird position:

[d]1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3

Code: Select all

gperft 1.1

1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3

perft(1) =                  44
perft(2) =               1,653
perft(3) =              69,135
perft(4) =           2,518,870
perft(5) =         101,747,485
perft(6) =       3,650,917,701
perft(7) =     144,124,568,547
perft(8) =   5,137,820,173,505
perft(9) = 199,736,924,871,600
Here are the divided perft values for depths higher than 6:

Code: Select all

1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
Depth is 7.

bxa5       3,944,782,274
dxc5       3,281,918,844
fxe5       3,185,471,065
hxg5       3,862,092,868
bxc5       3,947,836,525
dxe5       3,180,044,214
fxg5       3,371,872,044
Ng4        3,777,240,717
Nf3        4,286,362,656
Bc1        4,738,783,948
Be1        4,314,245,330
Qh5+         266,555,692
Qa4        3,189,488,060
Qg4        2,889,058,922
Qb3+         531,165,138
Qf3        3,544,568,190
Qc2        3,421,719,855
Qe2        2,837,696,264
Ba6        4,864,763,874
Bb5        4,571,848,244
Bc4+         752,641,268
Bd3        5,570,242,200
Bh3        4,577,362,855
Be2        4,347,058,039
Bg2        4,951,285,007
Rb3        3,068,424,847
Ra2        3,858,280,408
Rc2        3,294,853,442
Qc1        2,746,140,528
Qe1        2,508,698,725
Rg1        3,846,747,143
b5         2,241,084,491
d5         2,583,734,051
f5         1,996,345,203
h5         2,687,509,329
a4         3,524,273,548
c4         3,544,272,303
e4         3,907,783,746
g4         2,969,736,933
Kf3        2,442,233,096
Ke2        2,005,238,536
Kg2        2,824,116,132
Ke1        2,832,488,652
Kg1        3,036,503,341
TOTAL    144,124,568,547

Code: Select all

1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
Depth is 8.

bxa5       140,203,994,737
dxc5       116,316,733,924
fxe5       111,260,173,095
hxg5       139,647,093,677
bxc5       140,163,376,226
dxe5       110,942,252,517
fxg5       119,709,935,267
Nf3        154,054,987,232
Ng4        133,145,858,116
Qc2        120,219,993,942
Qe2        102,388,550,772
Qb3+        18,256,833,897
Qf3        124,874,294,005
Qa4        112,584,060,169
Qg4         98,520,336,860
Qh5+         8,267,300,181
Be2        157,462,402,330
Bg2        179,118,322,346
Bd3        199,203,953,145
Bh3        164,805,308,046
Bc4+        26,051,488,307
Bb5        160,644,338,085
Ba6        176,727,820,317
Bc1        172,000,471,873
Be1        156,021,775,538
Qc1        101,190,158,635
Qe1         92,482,968,823
Rg1        138,944,874,192
Ra2        139,512,687,369
Rc2        119,760,116,335
Rb3        110,926,756,963
a4         125,552,464,519
c4         128,575,141,249
e4         139,168,473,645
g4         105,905,582,018
b5          75,250,320,947
d5          87,871,293,918
f5          64,577,087,428
h5          92,293,319,869
Ke1        101,220,840,363
Kg1        108,823,659,236
Ke2         73,207,096,455
Kg2        101,161,318,013
Kf3         88,804,358,924
TOTAL    5,137,820,173,505

Code: Select all

1n1q1b1r/1r1b1k1n/1p1p1p1p/p1p1p1p1/1P1P1P1P/P1P1P1P1/1R1B1K1N/1N1Q1B1R w KQkq f3
Depth is 9.

bxa5       5,643,299,373,199
dxc5       4,494,022,244,635
fxe5       4,312,289,204,355
hxg5       5,487,096,750,782
bxc5       5,658,260,514,761
dxe5       4,301,605,413,431
fxg5       4,597,038,578,359
Ng4        5,417,466,249,743
Nf3        6,261,470,193,924
Bc1        7,064,065,434,742
Be1        6,170,763,821,696
Qh5+         333,378,132,999
Qa4        4,395,425,394,285
Qg4        3,856,031,132,302
Qb3+         717,454,501,075
Qf3        4,961,222,726,778
Qc2        4,743,796,867,618
Qe2        3,817,915,530,738
Ba6        7,035,035,707,953
Bb5        6,543,820,792,666
Bc4+       1,092,378,224,355
Bd3        8,311,267,319,644
Bh3        6,512,462,716,461
Be2        6,221,671,141,231
Bg2        7,204,000,927,046
Rb3        4,081,032,749,847
Ra2        5,410,257,531,480
Rc2        4,461,170,509,362
Qc1        3,643,752,845,023
Qe1        3,249,477,518,859
Rg1        5,376,266,983,761
b5         2,713,118,837,517
d5         3,250,094,504,646
f5         2,384,028,324,581
h5         3,428,916,374,118
a4         4,922,214,608,450
c4         5,019,621,970,507
e4         5,553,215,157,862
g4         3,948,534,772,692
Kf3        3,122,210,250,406
Ke2        2,500,478,517,314
Kg2        3,766,179,180,056
Ke1        3,712,854,224,911
Kg1        4,040,261,115,430
TOTAL    199,736,924,871,600
Your perft(6) value 3,650,917,701 has been confirmed. This FEN can be found in an old thread at Rybka Forum of 2008.

Regards from Spain.

Ajedrecista.

Post Reply