Simple method for simple mates for programs without TBs.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Simple method for simple mates for programs without TBs.

Post by jwes »

I found a way to have my program easily perform the basic mates. If there are no pawns on the board, use an evaluation of: material - distance between the two kings as given at chessprogramming.net D=max(|r2−r1|,|f2−f1|) + the piece-square values for the two kings using this table.

Code: Select all

char kk[64] =
{
	-7, -6, -5, -4, -4, -5, -6, -7,
	-6, -5, -3, -2, -2, -3, -5, -6,
	-5, -3,  0,  0,  0,  0, -3, -5,
	-4, -2,  0,  0,  0,  0, -2, -4,
	-4, -2,  0,  0,  0,  0, -2, -4,
	-5, -3,  0,  0,  0,  0, -3, -5,
	-6, -5, -3, -2, -2, -3, -5, -6,
	-7, -6, -5, -4, -4, -5, -6, -7,
};
This works for KQk, KRk, KBBk, KQkr, KQkb, and KQkn for relatively quick searches (40/1m or faster for my program). KBNk takes longer with a different table. This is the table for a bishop on white squares.

Code: Select all

char kkbw[64] =
{
	-2, -2, -3, -4, -4, -5, -6, -7,
	-2, -1, -1, -2, -2, -3, -5, -6,
	-3, -1,  0,  0,  0,  0, -3, -5,
	-4, -2,  0,  0,  0,  0, -2, -4,
	-4, -2,  0,  0,  0,  0, -2, -4,
	-5, -3,  0,  0,  0,  0, -2, -3,
	-6, -5, -3, -2, -2, -2, -1, -2,
	-7, -6, -5, -4, -4, -3, -2, -2,
};
I am certain these could be improved especially for KBNk, but they work well enough.
User avatar
Kotlov
Posts: 266
Joined: Fri Jul 10, 2015 9:23 pm
Location: Russia

Re: Simple method for simple mates for programs without TBs.

Post by Kotlov »

nothing new... sorry
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple method for simple mates for programs without TBs.

Post by hgm »

Awarding proximity of the Kings for the strong side indeed is very helpful. I already did that in Usurpator II.

Al aternative is to use a parabolic PST for the Kings, where the differences get larger the closer you get to the edge. Then the cost of stepping the strong King away from the center is much less than the gain from pressing the bare King against the edge. In fact the pair of Kings acts as a dipole, sucked into the region with the largest field gradient.

Nevertheless I had some problems making Fairy-Max master 4-vs-1 checkmates (e.g. Knight + 2 Ferz or 3 Ferz). For such mates 4 pieces that are drawn to the center need to approach a bare King in the corner square to get the mate within the horizon, and that was just too much. So I made it detect a bare King, and switch to multiplying the PST for it by 5. That makes driving the bare King to the corner the overwhelming concern, and the strong side will do anything needed to achieve it.

End-games that can only force mate in a corner of a specific color were still a problem, though. So whenever a bare King reaches a corner at game level, I switch the King PST to one that makes that corner look good, and the two neighboring corners bad. This actually is beneficial in two ways. If the mate in the current corner is already within the horizon, evaluation nolonger plays a role, and it just performs the mate. But otherwise it will try to drive the bare King out of the corner, which typically requires more material than just confining it there. So where otherwise it could get trapped in a state where two of the four pieces confine the bare King to (say) a1, a2, while the other twojust optimize their PST score by centralizing, they now all start to run to the corner where the bare King is. If there is a mate there, this usually brings it within the horizon. If not, it starts to drive the King to an adjacent corner until it arraives there, after which the procedure repeats in that corner.

This worked for all end-games where color-bound pieces make mate only possible in corers of a specific color.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Simple method for simple mates for programs without TBs.

Post by jwes »

Kotlov wrote:nothing new... sorry
I hadn't seen it before. Could you quote some sources?
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Simple method for simple mates for programs without TBs.

Post by Robert Pope »

Kotlov wrote:nothing new... sorry
Even if it isn't new, there's nothing wrong with sharing when you've discovered something interesting.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Simple method for simple mates for programs without TBs.

Post by jwes »

It may be better to only use this method when the pawnless position is at the root as your regular evaluation should return a very large score for these positions.
Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: Simple method for simple mates for programs without TBs.

Post by Daniel Anulliero »

Robert Pope wrote:
Kotlov wrote:nothing new... sorry
Even if it isn't new, there's nothing wrong with sharing when you've discovered something interesting.
Indeed
Forums exists for sharing , too .
Well , the method I use in Isa is so close to yours , just an algorithm a little bit more complex for KNB vs K ( I 'll show my routine one day if you want)
I tested a lot of KNB vs K positions , it find the mate before the 50 moves rules each time .
Isa download :
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple method for simple mates for programs without TBs.

Post by hgm »

An example of Fairy-Max 5.0 vs Stockfish 6, which knows to flee to the safe corner. (Fruit 2.1 apparently did not; it chose immediately for the deadly corner, and got mated very quickly there.)
[pgn][Event "Computer Chess Game"]
[Site "ONTWIKKELLAPTOP"]
[Date "2016.11.26"]
[Round "-"]
[White "Fairy-Max 5.0b3"]
[Black "Stockfish 6 64 POPCNT"]
[Result "1-0"]
[TimeControl "40/60"]
[VariantMen "Q:QisO2"]
[FEN "8/8/8/8/4k3/8/6KN/7B w - - 0 1"]
[SetUp "1"]

1. Kf2+ {+6.08/13} Kd3 {-39.76/27 1.3} 2. Nf3 {+5.98/12 4} Ke4
{-39.76/28 1.3} 3. Kg3 {+5.88/12 3} Kf5 {-39.76/28 1.1} 4. Nh4+
{+5.82/12 2.1} Kg5 {-39.76/26 0.7} 5. Be4 {+5.89/13 1.9} Kf6
{-39.76/27 1.1} 6. Kf4 {+5.75/12 2.8} Kg7 {-39.80/26 0.7} 7. Ke5
{+5.63/12 3} Kh8 {-39.80/27 0.7} 8. Nf5 {+5.57/9 1.4} Kg8 {-39.80/28 0.8}
9. Kf6 {+5.57/10 1.4} Kh8 {-39.80/34 1.4} 10. Bd5 {+5.52/8 2.5} Kh7
{-39.68/1} 11. Be6 {+5.70/10 3} Kh8 {-39.65/1} 12. Nh4 {+5.61/8 1.9} Kh7
{-39.68/1} 13. Ng6 {+5.62/9 1.1} Kh6 {-39.72/1} 14. Bg8 {+5.58/10 1.2} Kh5
{-39.76/1} 15. Ne5 {+5.56/12 2.6} Kh4 {-99.66/32 1.4} 16. Kf5
{+5.53/10 1.2} Kg3 {-99.68/34 1.3} 17. Bb3 {+5.55/10 1.0} Kg2
{-99.68/33 1.6} 18. Ke4 {+5.51/10 1.4} Kf2 {-99.68/35 1.8} 19. Bc2
{+5.54/10 1.1} Ke2 {-99.72/36 1.7} 20. Nf3 {+5.58/11 1.1} Kf2
{-99.74/36 1.8} 21. Nd4 {+5.58/11 0.9} Kg2 {-99.76/35 1.4} 22. Kf4
{+5.52/10 1.0} Kf2 {-99.76/36 1.5} 23. Bb3 {+5.58/10 0.9} Ke1
{-99.78/35 1.0} 24. Ke3 {+5.59/10 0.9} Kf1 {-99.80/1} 25. Be6
{+5.56/11 1.3} Kg2 {-99.82/35 1.7} 26. Ne2 {+5.56/10 1.0} Kf1
{-99.84/38 2.1} 27. Nf4 {+5.63/11 0.8} Ke1 {-99.86/42 1.8} 28. Nd3+
{+1000.09/10 1.1} Kf1 {-99.88/47 1.7} 29. Kf3 {+1000.06/9 0.7} Kg1
{-39.88/1} 30. Bh3 {+1000.05/11 0.9} Kh2 {-99.92/67 1.3} 31. Nf4
{+1000.04/19 0.7} Kg1 {-99.94/127 0.2} 32. Kg3 {+1000.03/28 0.1} Kh1
{-99.96/1} 33. Bg2+ {+1000.02/28 0.1} Kg1 {-99.98/1} 34. Ne2#
{+1000.01/28 0.1}
{White mates} 1-0
[/pgn]
This is a rather typical game; initially Fairy-Max just drives the bare King into any corner. Once it succeeds, (here already on move 9), it either sees mate, or will start driving it to the other corner.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Simple method for simple mates for programs without TBs.

Post by Gerd Isenberg »

In Chess 4.x this technique was called Mop-up Evaluation, see

David Slate, Larry Atkin (1977). CHESS 4.5 - The Northwestern University Chess Program. Chess Skill in Man and Machine, reprinted (1988) in Computer Chess Compendium