Detecting if move that gives check exists

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Detecting if move that gives check exists

Post by R. Tomasi »

hgm wrote: Sat Sep 18, 2021 7:58 pm What Ed descibes is detecting opportunities to capture a King with a sequence of 3 moves (of the same player). What you asked for is detecting opportunities to capture the King with a sequence of 2 moves.
Moves or plies? I may have completely missunderstood what Ed suggested: I was thinking of sequences like Ra8 ... Ra1#. Thus preventing the node that is a checkmate from being overlooked.

Edit: and yes, what he suggests would happen one node up in the tree, thus is not exactly what I asked for. Yet it might actually help solving the problem.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Detecting if move that gives check exists

Post by Rebel »

hgm wrote: Sat Sep 18, 2021 7:58 pm What Ed descibes is detecting opportunities to capture a King with a sequence of 3 moves (of the same player). What you asked for is detecting opportunities to capture the King with a sequence of 2 moves.
Not exactly, in diagram 1 the black rook is already on a8 and in diagram 2 the white rook is already on e1. I posted it that way to emphasize it's about one move only, not all moves. It's a kind of fast static nullmove looking for checks.
90% of coding is debugging, the other 10% is writing bugs.
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Detecting if move that gives check exists

Post by klx »

R. Tomasi wrote: Sat Sep 18, 2021 10:22 am
klx wrote: Sat Sep 18, 2021 7:09 am Do you want to hear about Emanuel's Bit-Based Move Checking Methodology?
Clearly you're not even smart enough to understand my post... so no. :roll: :lol:
Well, your loss. I'll keep this gem to myself then. Could have taken your little chess engine to the next level.
[Moderation warning] This signature violated the rule against commercial exhortations.
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Detecting if move that gives check exists

Post by klx »

Wait, what are you even trying to do?
[Moderation warning] This signature violated the rule against commercial exhortations.
pedrojdm2021
Posts: 157
Joined: Fri Apr 30, 2021 7:19 am
Full name: Pedro Duran

Re: Detecting if move that gives check exists

Post by pedrojdm2021 »

Mergi wrote: Sat Sep 18, 2021 10:05 am
pedrojdm2021 wrote: Sat Sep 18, 2021 6:43 am you can see there that my trick to known if the move is giving check is just to call InCheck function AFTER the MakeMove
Thats exactly what he doesnt want to do. He wants to know whether there are even such moves in the first place, rather than generating them or even worse, making them on the board.

I think the confusion stems from why you would even need such a functionality in the first place. If you are in a node, that would be cut, you would generate all the checking moves, presumably with a special mask or even just a separate generator. If there are no such moves, you simply get back an empty list, and cut the node. This should be already very very fast.

Why don't you want a function that predicts whether there's any move at all to detect checkmates early? Seeing as checking moves are a subset of all moves, finding out whethere there's any move might be easier than finding out whether there's a very special kind of move, a checking move, right? Yet nobody, at least to my knowledge, is doing checkmate verification before the move loop. If you can predict that there is a move, you might as well generate it.

Even if there's some Emanuels-smart-move-prediction algorithm, that is yet to be discovered, this really seems like a pointless thing to attempt to do.
oh ok, well that functionality is a defined rule in order to implement frutility pruning.

you can take a look:
https://www.chessprogramming.org/Futili ... Conditions
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Detecting if move that gives check exists

Post by hgm »

Rebel wrote: Sat Sep 18, 2021 9:04 pm
hgm wrote: Sat Sep 18, 2021 7:58 pm What Ed descibes is detecting opportunities to capture a King with a sequence of 3 moves (of the same player). What you asked for is detecting opportunities to capture the King with a sequence of 2 moves.
Not exactly, in diagram 1 the black rook is already on a8 and in diagram 2 the white rook is already on e1. I posted it that way to emphasize it's about one move only, not all moves. It's a kind of fast static nullmove looking for checks.
It is not entirely clear to me at which time the move is judged. Is the following understanding correct?

* In the position of the diagram, you generate all moves, including Ra8.
* All these moves are made
* Then it is tested whether the moved piece could capture the King in two moves (the first possibly by discovering it).
For Ra8 this is the case (Ra8-a1, Ra1xg1). For other moves (or at least non-captures), you immediately return a fail low, effectively pruning it retro-actively. (Because the eval remains too much below alpha?)
* With the Rook on a8 you now generate and search all moves of white.
* After most of those you search at least Ra8.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Detecting if move that gives check exists

Post by hgm »

R. Tomasi wrote: Sat Sep 18, 2021 8:02 pmMoves or plies?
Moves of a specified players are always plies. But three moves of that player in a row is not the same as three ply, as a three-ply search would have the second ply made by the opponent. So it is actually a 5-ply search, where the opponent only plays null moves.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Detecting if move that gives check exists

Post by R. Tomasi »

hgm wrote: Sun Sep 19, 2021 12:04 pm
R. Tomasi wrote: Sat Sep 18, 2021 8:02 pmMoves or plies?
Moves of a specified players are always plies. But three moves of that player in a row is not the same as three ply, as a three-ply search would have the second ply made by the opponent. So it is actually a 5-ply search, where the opponent only plays null moves.
Ok, I think we actually mean the same: What I thought Ed's idea to be, was that Ed's routine would influence the pruning decision for the node that is 2 ply down the tree, since it detects if there is a new check 3 ply down (which corresponds to capturing the king 5 ply down). So the routine would have to be called at the grandparent of the node that is to be pruned/not pruned.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Detecting if move that gives check exists

Post by Rebel »

hgm wrote: Sun Sep 19, 2021 12:01 pm
Rebel wrote: Sat Sep 18, 2021 9:04 pm
hgm wrote: Sat Sep 18, 2021 7:58 pm What Ed descibes is detecting opportunities to capture a King with a sequence of 3 moves (of the same player). What you asked for is detecting opportunities to capture the King with a sequence of 2 moves.
Not exactly, in diagram 1 the black rook is already on a8 and in diagram 2 the white rook is already on e1. I posted it that way to emphasize it's about one move only, not all moves. It's a kind of fast static nullmove looking for checks.
It is not entirely clear to me at which time the move is judged. Is the following understanding correct?

* In the position of the diagram, you generate all moves, including Ra8.
* All these moves are made
* Then it is tested whether the moved piece could capture the King in two moves (the first possibly by discovering it).
For Ra8 this is the case (Ra8-a1, Ra1xg1). For other moves (or at least non-captures), you immediately return a fail low, effectively pruning it retro-actively. (Because the eval remains too much below alpha?)
* With the Rook on a8 you now generate and search all moves of white.
* After most of those you search at least Ra8.

[fen]r7/1R3pp1/4p1k1/3pP1Np/2pP4/2P5/5PPP/6K1 b - -[/fen]


As simple as possible.

1. In this position during search the move Kxg5 is already searched and thus alpha has a reliable value.

2. The move Rf8-a8 is evaluated (see diagram) and the eval score is way below alpha and we are trying to reduce the move or prune the tree depending on depth. We check if the move Ra8 might be dangerous and if that's true we don't reduce or prune. And one of the conditions is to detect if the move Ra8 may create a check.

3. A rook can go 4 directions, we try them all. We loop through direction -1, via a table look up conclude that Ra7 never can produce a check, same for squares a6,a5,a4,a3,a2. Arrived on a1 the table produces a true value and arrived here I call an existing routine (I suppose everybody has) that checks if the board situation (WKg1 <> BRa1) produces a check and if so the move Rf8-a8 isn't pruned or reduced while all other rook moves are pruned or reduced.

That's is.

Meanwhile I get new 403 Forbidden errors :?
90% of coding is debugging, the other 10% is writing bugs.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Detecting if move that gives check exists

Post by Rebel »

[fen]r3rk2/ppq2pbQ/2p1b1p1/4p1B1/2P3P1/3P1B2/P3PPK1/1R5R w - -[/fen]

A working example.

Mate in 7 moves.

Mainline - 1.Qxg7+ Kxg7 2.Rh7+ Kxh7 3.Bf6 Bxg4 4.Bxg4 g5 5.Bf5+ Kg8 6.Rh1 a6 7.Rh8#

The quiet move 6.Rh1 creates a check and thus is not reduced or pruned.
90% of coding is debugging, the other 10% is writing bugs.