New chess engine: Rustic

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: New chess engine: Rustic

Post by xr_a_y »

You can keep an update table index by piece in combination with que square indexed mailbox.
There is a post on this topic somewhere, and I'm sure there are very fast mailbox engine out there.

Here it is : http://talkchess.com/forum3/viewtopic.p ... ilbox+fast

https://www.chessprogramming.org/Joker_NL

Anyway, in Minic it was big improvement indeed. I use HQBB first, taken from amoeba and switch to magic BB (from Rubi) after that.
Both are cheap to implement.
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New chess engine: Rustic

Post by mvanthoor »

Interesting... but too late for this engine :) Maybe in the future I'll fork Rustic, and replace the move generator with one that doesn't use bitboards, just to see the difference.

Today I've implemented SliderInfo. Its a (temporary) struct that collects all the information on sliders, such as move masks, number of squares to the edge, permutations of all possible blockers in a ray, etc, which will then be used to generate the actual bitboards. I hope to be able to finish the bitboards and the move generator by the end of the week, if I can find the time.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New chess engine: Rustic

Post by mvanthoor »

Njergh. At first I didn't want to invest the time to look into magic bitboards, so I started out using a mailbox 10x12 board. Halfway through I decided to go for magic bitboards anyway, but didn't want to invest the time to change the functions that already worked using the mailbox board; so I turned it into a helper board to generate some of the bitboards.

Now, I was of the opinion that my code was becoming far too huge and unwieldy already (way too many loops in loops and such), so I started fasing out the helper board. Today I rewrote the functions that generate the King, Knight and Pawn attack boards to not use the helper board. Tomorrow I'll rewrite generating the rook mask boards (the ones without the edges) to not use the helper board, and then I'll be where I was yesterday, minus a HUGE chunk of code, and minus a lot of lines.

Should have started out with full bitboards in the beginning.

Maybe I can still finish the move generator by the end of the weekend.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
NaltaP312
Posts: 56
Joined: Wed Oct 29, 2008 1:06 pm
Full name: Marc Paule

Re: New chess engine: Rustic

Post by NaltaP312 »

Hi,

if you want the best perft try xiphos it is better than cfish
xiphos perft 6 = 119060324 for 1176ms nps 101155755
cfish perft 6 = 119060324 for 2128ms nps 55949400
may be sungorus is better to or near xiphos.

under linux material teclast f6 intel apollo lake processor 2.2ghz
Regards
Naltap
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New chess engine: Rustic

Post by mvanthoor »

Some progress; somewhat later than planned due to time constraint, refactoring, cleanup, and commenting the code. I finally finished implementing the magics, and testing them. Everything seems to work as expected. Next step: castling, and then testing make/unmake for the new magics. After that, a perft function.

Some output... (Move 45 for white is correct; the b6 EP flag is set :))

Code: Select all

Engine: Rustic Alpha 1
Author: Marcel Vanthoor

8   . . r . . r . .
7   . . . . k . . .
6   n . . . I . i .
5   I i b q . b . .
4   . I . . . . . .
3   . . B . . I . B
2   . . . . Q . . .
1   . R . . . K R .

    A B C D E F G H

Move 1: Kf1e1 capture: -, promotion: -, ep: false
Move 2: Kf1f2 capture: -, promotion: -, ep: false
Move 3: Kf1g2 capture: -, promotion: -, ep: false
Move 4: Rb1a1 capture: -, promotion: -, ep: false
Move 5: Rb1c1 capture: -, promotion: -, ep: false
Move 6: Rb1d1 capture: -, promotion: -, ep: false
Move 7: Rb1e1 capture: -, promotion: -, ep: false
Move 8: Rb1b2 capture: -, promotion: -, ep: false
Move 9: Rb1b3 capture: -, promotion: -, ep: false
Move 10: Rg1h1 capture: -, promotion: -, ep: false
Move 11: Rg1g2 capture: -, promotion: -, ep: false
Move 12: Rg1g3 capture: -, promotion: -, ep: false
Move 13: Rg1g4 capture: -, promotion: -, ep: false
Move 14: Rg1g5 capture: -, promotion: -, ep: false
Move 15: Rg1g6 capture: Pawn, promotion: -, ep: false
Move 16: Bc3a1 capture: -, promotion: -, ep: false
Move 17: Bc3e1 capture: -, promotion: -, ep: false
Move 18: Bc3b2 capture: -, promotion: -, ep: false
Move 19: Bc3d2 capture: -, promotion: -, ep: false
Move 20: Bc3d4 capture: -, promotion: -, ep: false
Move 21: Bc3e5 capture: -, promotion: -, ep: false
Move 22: Bc3f6 capture: -, promotion: -, ep: false
Move 23: Bc3g7 capture: -, promotion: -, ep: false
Move 24: Bc3h8 capture: -, promotion: -, ep: false
Move 25: Bh3g2 capture: -, promotion: -, ep: false
Move 26: Bh3g4 capture: -, promotion: -, ep: false
Move 27: Bh3f5 capture: Bishop, promotion: -, ep: false
Move 28: Qe2d1 capture: -, promotion: -, ep: false
Move 29: Qe2e1 capture: -, promotion: -, ep: false
Move 30: Qe2a2 capture: -, promotion: -, ep: false
Move 31: Qe2b2 capture: -, promotion: -, ep: false
Move 32: Qe2c2 capture: -, promotion: -, ep: false
Move 33: Qe2d2 capture: -, promotion: -, ep: false
Move 34: Qe2f2 capture: -, promotion: -, ep: false
Move 35: Qe2g2 capture: -, promotion: -, ep: false
Move 36: Qe2h2 capture: -, promotion: -, ep: false
Move 37: Qe2d3 capture: -, promotion: -, ep: false
Move 38: Qe2e3 capture: -, promotion: -, ep: false
Move 39: Qe2c4 capture: -, promotion: -, ep: false
Move 40: Qe2e4 capture: -, promotion: -, ep: false
Move 41: Qe2b5 capture: Pawn, promotion: -, ep: false
Move 42: Qe2e5 capture: -, promotion: -, ep: false
Move 43: f3f4 capture: -, promotion: -, ep: false
Move 44: b4c5 capture: Bishop, promotion: -, ep: false
Move 45: a5b6 capture: -, promotion: -, ep: true
...
Move 1: Ke7d6 capture: -, promotion: -, ep: false
Move 2: Ke7e6 capture: Pawn, promotion: -, ep: false
Move 3: Ke7f6 capture: -, promotion: -, ep: false
Move 4: Ke7d7 capture: -, promotion: -, ep: false
Move 5: Ke7f7 capture: -, promotion: -, ep: false
Move 6: Ke7d8 capture: -, promotion: -, ep: false
Move 7: Ke7e8 capture: -, promotion: -, ep: false
Move 8: Na6b4 capture: Pawn, promotion: -, ep: false
Move 9: Na6c7 capture: -, promotion: -, ep: false
Move 10: Na6b8 capture: -, promotion: -, ep: false
Move 11: Rc8c6 capture: -, promotion: -, ep: false
Move 12: Rc8c7 capture: -, promotion: -, ep: false
Move 13: Rc8a8 capture: -, promotion: -, ep: false
Move 14: Rc8b8 capture: -, promotion: -, ep: false
Move 15: Rc8d8 capture: -, promotion: -, ep: false
Move 16: Rc8e8 capture: -, promotion: -, ep: false
Move 17: Rf8f6 capture: -, promotion: -, ep: false
Move 18: Rf8f7 capture: -, promotion: -, ep: false
Move 19: Rf8d8 capture: -, promotion: -, ep: false
Move 20: Rf8e8 capture: -, promotion: -, ep: false
Move 21: Rf8g8 capture: -, promotion: -, ep: false
Move 22: Rf8h8 capture: -, promotion: -, ep: false
Move 23: Bc5g1 capture: Rook, promotion: -, ep: false
Move 24: Bc5f2 capture: -, promotion: -, ep: false
Move 25: Bc5e3 capture: -, promotion: -, ep: false
Move 26: Bc5b4 capture: Pawn, promotion: -, ep: false
Move 27: Bc5d4 capture: -, promotion: -, ep: false
Move 28: Bc5b6 capture: -, promotion: -, ep: false
Move 29: Bc5d6 capture: -, promotion: -, ep: false
Move 30: Bc5a7 capture: -, promotion: -, ep: false
Move 31: Bf5b1 capture: Rook, promotion: -, ep: false
Move 32: Bf5c2 capture: -, promotion: -, ep: false
Move 33: Bf5d3 capture: -, promotion: -, ep: false
Move 34: Bf5h3 capture: Bishop, promotion: -, ep: false
Move 35: Bf5e4 capture: -, promotion: -, ep: false
Move 36: Bf5g4 capture: -, promotion: -, ep: false
Move 37: Bf5e6 capture: Pawn, promotion: -, ep: false
Move 38: Qd5d1 capture: -, promotion: -, ep: false
Move 39: Qd5a2 capture: -, promotion: -, ep: false
Move 40: Qd5d2 capture: -, promotion: -, ep: false
Move 41: Qd5b3 capture: -, promotion: -, ep: false
Move 42: Qd5d3 capture: -, promotion: -, ep: false
Move 43: Qd5f3 capture: Pawn, promotion: -, ep: false
Move 44: Qd5c4 capture: -, promotion: -, ep: false
Move 45: Qd5d4 capture: -, promotion: -, ep: false
Move 46: Qd5e4 capture: -, promotion: -, ep: false
Move 47: Qd5e5 capture: -, promotion: -, ep: false
Move 48: Qd5c6 capture: -, promotion: -, ep: false
Move 49: Qd5d6 capture: -, promotion: -, ep: false
Move 50: Qd5e6 capture: Pawn, promotion: -, ep: false
Move 51: Qd5b7 capture: -, promotion: -, ep: false
Move 52: Qd5d7 capture: -, promotion: -, ep: false
Move 53: Qd5a8 capture: -, promotion: -, ep: false
Move 54: Qd5d8 capture: -, promotion: -, ep: false
Move 55: g6g5 capture: -, promotion: -, ep: false
Done.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New chess engine: Rustic

Post by mvanthoor »

Milestone hit: correct perft testing for Rustic :)

Yesterday I finished up implementing castling in make_move en unmake_move. Today I wrote a very simple perft function. (Actually, I took the one from the Wiki because I was lazy.) The initial position was correct up to perft 6, but the engine failed at the "Position 2: KiwiPete" and "Position 5: Talkchess" positions as posted in the Wiki:

https://www.chessprogramming.org/Perft_Results

So, there was still something wrong somewhere. Doing a google search, I found this thread at Talkchess:

http://talkchess.com/forum3/viewtopic.php?f=7&t=55787

Fortunately, HG Mueller already posted perft results for "KiwiPete" without castling rights.

As this was the last part I added into the engine, I perft-tested the position without castling rights as well. The numbers matched those posted by HG Mueller. So, when not castling, the perft was OK, and thus castling must go wrong somewhere. I checked the code, and everything seemed to be fine. (I castle by generating e1g1, etc, and move the rook in make_move.)

After staring at the KiwiPete diagram for some time, it hit me:

The pawn on h3 will at some point capture the Rook on H1, which will make white loose castling permissions for the kingside. The same is true for the knight on F2 in position 5 "Talkchess". Thus, the castling permissions for the side the rook is on should be dropped. I didn't do that.

When generating the king part of the castling move, I consider this:
- There are castling permissions
- There are no blocking pieces between the king and the rook
- The king is not in check
- d1/f1 (d8/f8) are not attacked

If all those conditions are met, the castling move is generated, even if the rook isn't there. make_move will move the king, and then "move" a non-existing rook (move nothing to nothing).

After adding a few lines to make_move (if captured_piece == ROOK ... if to_square == H1 ... drop white king castling permissions and so on), the perft function for position 2 KiwiPete and position 5 Talkchess also checked out correctly.

Board representation, move generation, make_move, unmake_move, and perft testing are now officially done :) (I am assuming that, when I find perftsuite.epd, all the positions will be tested successfully.)

The next step will be a bit of cleanup, put the perft functionality into its own nice testing module with the positions from "perftsuite.epd" (which I still need to find somehwere; probably as part of another engine), and then on to the search, a small evaluation, and a uci-interface to finish this thing up as Rustic Alpha 1 :)

Code: Select all

https://www.chessprogramming.org/Perft_Results

Position 2: "KiwiPete"
r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

Engine: Rustic Alpha 1
Author: Marcel Vanthoor

8   r . . . k . . r
7   i . i i q i b .
6   b n . . i n i .
5   . . . I N . . .
4   . i . . I . . .
3   . . N . . Q . i
2   I I I B B I I I
1   R . . . K . . R

    A B C D E F G H

Zobrist key:        17a25d12a8850d3e
Active Color:       White
Castling:           KQkq
En Passant:         -
Half-move clock:    0
Full-move number:   1

Peft 1: 48
Peft 2: 2039
Peft 3: 97862
Peft 4: 4085603
Peft 5: 193690690
Finished.


Position 5: "Talkchess"
rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8

Engine: Rustic Alpha 1
Author: Marcel Vanthoor

8   r n b q . k . r
7   i i . I b i i i
6   . . i . . . . .
5   . . . . . . . .
4   . . B . . . . .
3   . . . . . . . .
2   I I I . N n I I
1   R N B Q K . . R

    A B C D E F G H

Zobrist key:        f15298ec8a2782f2
Active Color:       White
Castling:           KQ
En Passant:         -
Half-move clock:    1
Full-move number:   8

Peft 1: 44
Peft 2: 1486
Peft 3: 62379
Peft 4: 2103487
Peft 5: 89941194
Finished.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
fabianVDW
Posts: 146
Joined: Fri Mar 15, 2019 8:46 pm
Location: Germany
Full name: Fabian von der Warth

Re: New chess engine: Rustic

Post by fabianVDW »

You should read in a file of perft test positions and run more tests, you will wonder about all the rules in chess you missed. There are pretty exhaustive lists out on talkchess. There even were some things I missed and only fixed some months after the engines was already listed on rating lists, with thousands of games played without problems.
Author of FabChess: https://github.com/fabianvdW/FabChess
A UCI compliant chess engine written in Rust.
FabChessWiki: https://github.com/fabianvdW/FabChess/wiki
fabianvonderwarth@gmail.com
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New chess engine: Rustic

Post by mvanthoor »

Yes, I know. I've already transferred the perft-function to its own module. I'm only debating if I should read in perftsuite.epd, or even just bake it into the program's executable.

Do you, or anyone else, have a verified link to a known good perftsuite.epd file?

There's no way to know if posted positions or files are correct.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
fabianVDW
Posts: 146
Joined: Fri Mar 15, 2019 8:46 pm
Location: Germany
Full name: Fabian von der Warth

Re: New chess engine: Rustic

Post by fabianVDW »

Author of FabChess: https://github.com/fabianvdW/FabChess
A UCI compliant chess engine written in Rust.
FabChessWiki: https://github.com/fabianvdW/FabChess/wiki
fabianvonderwarth@gmail.com