SjaakII 1.0 RC1

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

Moderator: Ras

myfish
Posts: 131
Joined: Sat Feb 07, 2015 3:17 pm

Re: SjaakII 1.0 RC3

Post by myfish »

Evert wrote:
However, I gather that the chase rules in Shogi are a bit different in that you are allowed to chase the king perpetually, as long as you don't simply go back-and-forth?
Yes. Well, until your attack dries up yes.

This explains the draw side of things
User avatar
hgm
Posts: 28498
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: SjaakII 1.0 RC3

Post by hgm »

Evert wrote:However, I gather that the chase rules in Shogi are a bit different in that you are allowed to chase the king perpetually, as long as you don't simply go back-and-forth?
No, they are the same. A perpetual is a repeat loop where all moves of one side have been checks. It doesn't matter how long the loop is.

There actually is a very interesting Shogi problem, known as 'The Final Judgement', which is a mate in 60 or so, based on this. The crux is that the winning side drives the losing King all over the board with checks, in a repetition loop. But one of the evasions in that loop is a Pawn drop that counter-checks. And the only way to evade that counter-check is capture that Pawn with the Bishop it was blocking (so you check again). Now the position after BxP is the first of the repetiton loop. So after having run through the loop 3 times, it would be the 4th ocurrence, and thus a perpetual. Hence BxP is forbidden, it is not a legal move anymore. But it was the only way to evade the check by the dropped Pawn. So you are now checkmated (in a position that occurred 3 times before!). But Pawn-drop mate is also illegal. So the losing side was not allowed to drop the Pawn, and must find another evasion from the Bishop check. It cannot stay on the loop that kept him alive the first 3 times, has to make an inferior evasion, which eventually gets him mated.

Actually this has led to a discussion about exact meaning and precedence of the Shogi rules. If you would say perpetual check is allowed but losing, the Pawn drop would not have been a checkmate, but just a way to force a losing move, as there would have been a legal evasionfrom the check.
myfish
Posts: 131
Joined: Sat Feb 07, 2015 3:17 pm

Re: SjaakII 1.0 RC3

Post by myfish »

hgm wrote:
There actually is a very interesting Shogi problem, known as 'The Final Judgement', which is a mate in 60 or so, based on this. The crux is that the winning side drives the losing King all over the board with checks, in a repetition loop. But one of the evasions in that loop is a Pawn drop that counter-checks. And the only way to evade that counter-check is capture that Pawn with the Bishop it was blocking (so you check again). Now the position after BxP is the first of the repetition loop. So after having run through the loop 3 times, it would be the 4th ocurrence, and thus a perpetual. Hence BxP is forbidden, it is not a legal move anymore. But it was the only way to evade the check by the dropped Pawn. So you are now checkmated (in a position that occurred 3 times before!). But Pawn-drop mate is also illegal. So the losing side was not allowed to drop the Pawn, and must find another evasion from the Bishop check. It cannot stay on the loop that kept him alive the first 3 times, has to make an inferior evasion, which eventually gets him mated.

Actually this has led to a discussion about exact meaning and precedence of the Shogi rules. If you would say perpetual check is allowed but losing, the Pawn drop would not have been a checkmate, but just a way to force a losing move, as there would have been a legal evasion from the check.
Hmm, yes I guess so. You'd have to be pretty much on the ball to do loops of mate in 60 though.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: SjaakII 1.0 RC3

Post by Evert »

hgm wrote: There actually is a very interesting Shogi problem, known as 'The Final Judgement', which is a mate in 60 or so, based on this. The crux is that the winning side drives the losing King all over the board with checks, in a repetition loop. But one of the evasions in that loop is a Pawn drop that counter-checks. And the only way to evade that counter-check is capture that Pawn with the Bishop it was blocking (so you check again). Now the position after BxP is the first of the repetiton loop. So after having run through the loop 3 times, it would be the 4th ocurrence, and thus a perpetual. Hence BxP is forbidden, it is not a legal move anymore. But it was the only way to evade the check by the dropped Pawn. So you are now checkmated (in a position that occurred 3 times before!). But Pawn-drop mate is also illegal. So the losing side was not allowed to drop the Pawn, and must find another evasion from the Bishop check. It cannot stay on the loop that kept him alive the first 3 times, has to make an inferior evasion, which eventually gets him mated.
That sounds like a very interesting problem, also from a debugging point of view. I wonder of Sjaak would correctly identify the pawn drop as illegal on the repetition.

Something to look up at some point, I guess.
myfish
Posts: 131
Joined: Sat Feb 07, 2015 3:17 pm

Re: SjaakII 1.0 RC3

Post by myfish »

Using a compiled version of sjaakII from this thread, I started a few xboard games and indeed it seemed, the illegal moves mentioned earlier have stopped.

However, one game went on and on. At one point, ALL the pieces in play were promoted and, in the latter half, all the pieces from each side were in opposite ranks.

However, on move 488,

*** Error in `sjaakii': free(): invalid pointer: 0x0000000000b7d710 ***

Xboard stopped responding. Sadly I didn't have xboard -debug active.
User avatar
hgm
Posts: 28498
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: SjaakII 1.0 RC3

Post by hgm »

I guess Sjaak has some maximum game length it can handle, before arrays overflow and data corruption occurs. XBoard has a maximum too, btw. (But I now upped that from 500 to 1000 moves, for the benefit of Chu Shogi, where a typical gae is already more than 20 moves.)

It makes in general no sense to let games that would go on forever really go on forever. It is easy to make that XBoard (or Sjaak, presumably) could handle upto a million moves. But then games in an impasse would really go on for a million moves and take a year, which is probably not what you want, and would run into the same error eventally. In Chess the 50-move rule protects you from this, but in Shogi there are no irreversible moves. The best policy is to use XBoard's option to adjudicate games as a draw as soon as the length reaches a specified number of moves. What is reasonable for this depends on the variant.
myfish
Posts: 131
Joined: Sat Feb 07, 2015 3:17 pm

Re: SjaakII 1.0 RC3

Post by myfish »

hgm wrote:I guess Sjaak has some maximum game length it can handle, before arrays overflow and data corruption occurs. XBoard has a maximum too, btw. (But I now upped that from 500 to 1000 moves, for the benefit of Chu Shogi, where a typical gae is already more than 20 moves.)

It makes in general no sense to let games that would go on forever really go on forever. It is easy to make that XBoard (or Sjaak, presumably) could handle upto a million moves. But then games in an impasse would really go on for a million moves and take a year, which is probably not what you want, and would run into the same error eventally. In Chess the 50-move rule protects you from this, but in Shogi there are no irreversible moves. The best policy is to use XBoard's option to adjudicate games as a draw as soon as the length reaches a specified number of moves. What is reasonable for this depends on the variant.
Agreed. I was speaking to someone about 'King Entering' recently and how it gets VERY hard to find mates in these situations. The issue with goro goro is the pieces don't really allow for any leeway in strategy when sente's and gote's pieces are laid out in opposite camps as you simply have golds, promoted knights (golds), tokins (golds), silvers (golds) etc etc.

So you are faced with a wall of pieces, all facing the wrong direction for attacks and no rearward diagonals. This was something I was surprised to see sjaaakII do in almost continuity. It didn't seem to consider, NOT promoting silver to make the mate.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: SjaakII 1.0 RC3

Post by Evert »

hgm wrote:I guess Sjaak has some maximum game length it can handle, before arrays overflow and data corruption occurs. XBoard has a maximum too, btw. (But I now upped that from 500 to 1000 moves, for the benefit of Chu Shogi, where a typical gae is already more than 20 moves.)
It does have a limit to the length of the game before it will crash and burn, but only because I got lazy and never implemented the functionality to increase the size of the movelist when you reach the limit. The limit is 1000 ply, so it doesn't seem to be the problem here (although I suppose that there is a possibility that you run into trouble if you get close to that limit and search+qsearch pushes you over it).

I did once run into XBoard's 500 ply limit during a test, in that instance it was actually XBoard that crashed. Not sure what version, but it was before I upgraded to 4.8, so it would have been old.
It makes in general no sense to let games that would go on forever really go on forever. It is easy to make that XBoard (or Sjaak, presumably) could handle upto a million moves. But then games in an impasse would really go on for a million moves and take a year, which is probably not what you want, and would run into the same error eventally. In Chess the 50-move rule protects you from this, but in Shogi there are no irreversible moves. The best policy is to use XBoard's option to adjudicate games as a draw as soon as the length reaches a specified number of moves. What is reasonable for this depends on the variant.
That sounds reasonable. I haven't given it much thought with respect to Sjaak, except that really the correct behaviour would be for it to not crash. I suppose it could offer a draw in that situation, but it would still have to play on if the draw offer is refused. Resigning seems little better than crashing...
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: SjaakII 1.0 RC3

Post by Evert »

myfish wrote:Using a compiled version of sjaakII from this thread, I started a few xboard games and indeed it seemed, the illegal moves mentioned earlier have stopped.
You may want to check the version number, I don't think there was a binary linked to in this thread that doesn't trip up on '=' to defer promotion that is more recent than the version that had the problem (the problem is something that I introduced when I re-wrote the move scanning to be less complicated).
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: SjaakII 1.0 RC3

Post by Evert »

myfish wrote: Agreed. I was speaking to someone about 'King Entering' recently and how it gets VERY hard to find mates in these situations.
I guess this is the situation that the Wikipedia page on Shogi refers to as "Impasse". It's very hard to do anything about that without resorting to special knowledge in the search and evaluation.

If there's a simple solution, I'd be happy to hear it.
The issue with goro goro is the pieces don't really allow for any leeway in strategy when sente's and gote's pieces are laid out in opposite camps as you simply have golds, promoted knights (golds), tokins (golds), silvers (golds) etc etc.

So you are faced with a wall of pieces, all facing the wrong direction for attacks and no rearward diagonals. This was something I was surprised to see sjaaakII do in almost continuity. It didn't seem to consider, NOT promoting silver to make the mate.
Well, in simple material balance a gold is worth more than a silver, so it's not surprising that it would promote the silver at every opportunity. Having an army of golds is less useful than having a few silvers mixed in, but it's not so easy to give a general rule for that.
The other issue is that Sjaak will consider the gold to have mate potential - which is correct, as long as the defending king is in front of the gold. It doesn't take that into account. If it did, it might be enough to convince it to keep a silver around to avoid the loss of mate potential. That requires quite a bit of changes to the code though (as well as the rule of thumb that says that > 2 pieces are considered mate potential if they're not all color-bound on the same colour).

The tricky part here is that really all Sjaak knows about a variant are the rules and the piece values you give it. Everything else (whether pieces can deliver mate or not, whether pieces should be centralised or not) is derived from the rules and a set of heuristics.

However, there is an easy way to encourage it to keep a silver around: simply set the value of a promoted silver to be lower than that of a silver itself. Sjaak will then prefer to not promote the silver unless it sees an immediate benefit to doing that. It's wrong in general, but it would avoid this particular problem.