Engine with a Witch

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

evert823
Posts: 8
Joined: Thu Oct 29, 2020 9:32 am
Full name: Evert Jan Karman

Engine with a Witch

Post by evert823 »

I wanted to write an engine that supports a fairy piece called the Witch. The Witch makes transparent, so that other pieces that normally don't leap can actually leap, as a side-effect of the Witch.

To some extent I succeeded here. With quite straightforward C# code, not caring too much about efficiency and performance. But this is my very first attempt to write a chess engine, I'm stuck on a playing strength that is no match for a stronger human player. It's too slow and I can't reasonably ask it to calculate more than 5 plies deep.

Is there any existing open source code base where it is not too difficult to add this feature?
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Engine with a Witch

Post by hgm »

Hi Evert,

I did not know you were a programmer too! There are lots of open-source engines. I don't know about any in C#, but perhaps you can find that info in the chessprogramming wiki. I don't know C# myself.

What exactly is your goal? You want to do this on 8x8 or 10x8? For other than 8x8 there is not so much; many engines now use so-called bitboards, which is a game-state representation that is essentially dependent on the computer's word length (64 bits, nowadays) being at least as large as the number of board squares. It would not be easy to adapt those. You would have to spend more effort on adapting the board size than on implementing a Witch.

You could try to adapt Fairy-Max; as chess engines go it is not very strong, but I think it is still a challenging opponent for humans. It can handle boards up to 14x16, and up to 15 piece types. It is a very small program, but the code is very cryptic. The change you need to implement a Witch would not be very difficult, though: at the point where a piece bumps into a friendly piece (which would normally terminate the move in that direction) it would have to test all neighboring squares for presence of a Witch, and continue with the next step in that direction if one is detected. That is all.
evert823
Posts: 8
Joined: Thu Oct 29, 2020 9:32 am
Full name: Evert Jan Karman

Re: Engine with a Witch

Post by evert823 »

Just to be sure, the source code for Fairy-Max can be found here:
https://home.hccnet.nl/h.g.muller/CVfairy.html
Is that indeed where I should pick it?
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Engine with a Witch

Post by hgm »

The latest source is in my on-line git repository: http://hgm.nubati.net/cgi-bin/gitweb.cgi . Just download the latest 'snapshot' from there. The source code is in the file fairymax.c .

The point where it would have to be changed is

Code: Select all

      {if(t&&(t&16)==k)break;                  /* capture own              */
The if() testst whether the occupant t of the encountered square y is of the current player's color k. Instead of always breaking out of the loop when this is the case, you would have to test the neighborhood of y for a Witch, and do a 'continue' instead of a 'break' when you find one.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Engine with a Witch

Post by hgm »

Hmm... I looked at the exact rules for the Witch, and it is a bit more involved than I thought. For one, the Witch is also transparent itself, for friendly pieces. So you would have to examine 9 squares rather than 8 for a Witch. But it doesn't make pieces transparent for itself. So you would have to verify that any Witch in the neighborhood of an obstacle is not the on the piece that you try to move (i.e. is not on the square x).

Also, you would have to make sure the castling code doesn't object to a transparent piece in the b-file for Q-side castling. Worst of all is that it can cause double capture, because the e.p. square doesn't have to be empty. This would require saving and restoring of the destination occupant in addition to the capture target. (Which for e.p. captures are different.)
evert823
Posts: 8
Joined: Thu Oct 29, 2020 9:32 am
Full name: Evert Jan Karman

Re: Engine with a Witch

Post by evert823 »

And there are a few more things. The evaluation should assign material value for having a Witch (perhaps 3 pawns). And recognize the value of cooperation between the Witch and other long-range pieces.
Our favourite setup on chess.com is 10x8 with one more piece: the Guard. Moves like a King without being royal. This is a simple piece, but I'm not sure if Fairy-Max knows it. None of the large Shogi variants has such a piece - if I am not mistaken.

I am going to have a look at the source code of Fairy-Max, and see if I can read and understand it.
evert823
Posts: 8
Joined: Thu Oct 29, 2020 9:32 am
Full name: Evert Jan Karman

Re: Engine with a Witch

Post by evert823 »

And not too forget: implement the own movement abilities of the Witch.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Engine with a Witch

Post by hgm »

Indeed, but that doesn't require any change in the program. Fairy-Max is configurable through an fmax.ini file, and it is only a matter of adding a single line with a list of the possible move steps (16*dy+dx), and what these are allowed to do (slide, capture, non-capture). So it can do pretty much any piece move, including hoppers, lame leapers, bent sliders etc., just through configuring. And you can specify the piece value there too. Only for pieces with side effects (immobilizers) it would require additions to the program.

The code of Fairy-Max is extremely cryptic, because it is a derivative of micro-Max, which was an attempt to make the smallest possible source code for a Chess program. So all variable names are non-discriptive single characters. There is a lot of explanation on the micro-Max project at https://home.hccnet.nl/h.g.muller/max-src2.html , though; If you really want to look at the Fairy-Max code it would be best to look that that first.

BTW, Dai Dai Shogi has a 'Neighbor King', which moves as King. (So I suppose Tai Shogi will have it too.) The Commonor also occurs in Knightmate, one of the variants that Fairy-Max is pre-configured for.
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Engine with a Witch

Post by mvanthoor »

hgm wrote: Fri Oct 30, 2020 3:15 pm Hi Evert,

I don't know about any in C#...
MadChess:

https://www.madchess.net/
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL