Shogi

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi

Post by Ferdy »

Evert wrote:I've added some special king-safety code for drop variants (having Shogi in mind, but the code is general).

First of all it calculates a shelter score based on the squares surrounding the king that are protected/occupied by friendly pieces. This already helps a lot, but the real improvement seems to come from counting pieces that are "in hand" as attacking the king's position (after all, they can just drop in there). The new version solidly defeats the old version, and play looks much more coordinated.

So far no idea how it measures up against other engines though...
I am working on mini shogi, for incoming UEC Cup this November 23. It would be interesting if you can join.
I do something similar to what you do. In the eval I identify all unprotected squares empty or not. If opponent has on-hand then surely the empty unprotected squares are penalized. The penalty is increased when the opponent has an on-hand piece that when dropped to the said square is able to check my king. Contact check is very dangerous here, as the board is small, escape squares are low. I added a SEE applied to captures at the moment and there is improvement. Next will be to apply SEE on drop and promote moves. LMR also helps, I have not tried yet the futility stuff, probably will not work as this game is not decided by material but by initiative and king attack. Other rules, you lose if you check perpetually the opponent. The other rule is Black/Gote will win if 4-times the position appears on the board or 3 repeats, both on-hand and on-board pieces should be the same.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Shogi

Post by Evert »

Ferdy wrote: I am working on mini shogi, for incoming UEC Cup this November 23. It would be interesting if you can join.
Hmm… I somewhat doubt it. Sjaak does play mini-shogi though (with one rule exception).
I do something similar to what you do. In the eval I identify all unprotected squares empty or not. If opponent has on-hand then surely the empty unprotected squares are penalized. The penalty is increased when the opponent has an on-hand piece that when dropped to the said square is able to check my king.
There's nothing so sophisticated here, but I'm not done tweaking it. Adding the shelter bonus added ~80 elo in a quick test. I'm going to try something similar to what I do for Xiangqi, where the shelter score is based on the presence of defensive pieces, and whether they protect eachother. For Shogi, I would ideally detect the presence of generals, but I have no way to code such knowledge in Sjaak...
Contact check is very dangerous here, as the board is small, escape squares are low.
I'm thinking I should add a simple mate-threat detection in the evaluation. It happens quite often that games are lost because of two quick drops. It shouldn't be hard to detect that statically.
I added a SEE applied to captures at the moment and there is improvement. Next will be to apply SEE on drop and promote moves. LMR also helps, I have not tried yet the futility stuff, probably will not work as this game is not decided by material but by initiative and king attack.
I do quite heavy LMR of drop moves, except when in check or if the drop is next to the enemy king. Drop moves on the enemy half of the board are reduced less. I also outright prune drops with negative SEE in the last two plies (again, unless I'm in check).
Even with this, I sometimes get catastrophic drops in search depth, which end up losing the game...
Other rules, you lose if you check perpetually the opponent. The other rule is Black/Gote will win if 4-times the position appears on the board or 3 repeats, both on-hand and on-board pieces should be the same.
I have the perpetual check, but not the repetition rule (I think I disallow repetition entirely). I'll need to add that in (requires a special rule-flag), but it's not high on my list of priorities...
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi

Post by Ferdy »

There's nothing so sophisticated here, but I'm not done tweaking it. Adding the shelter bonus added ~80 elo in a quick test. I'm going to try something similar to what I do for Xiangqi, where the shelter score is based on the presence of defensive pieces, and whether they protect eachother. For Shogi, I would ideally detect the presence of generals, but I have no way to code such knowledge in Sjaak...
In mini shogi I observed that once you get your attack flowing defensive moves are no longer required much or something that the defense is also covered a bit. Dropping a general safely at the center of the board is already a terror to opponent's king when that king is in front, but attacking potential of general is reduced when the king is behind it, I discourage promoting a silver general to gold general if the position of opponent's king is way behind the promotion square.
I'm thinking I should add a simple mate-threat detection in the evaluation. It happens quite often that games are lost because of two quick drops. It shouldn't be hard to detect that statically.
Those 2 quick drops could be a search issue too, these drop moves searches remain an interesting thing to explore.
I do quite heavy LMR of drop moves, except when in check or if the drop is next to the enemy king. Drop moves on the enemy half of the board are reduced less. I also outright prune drops with negative SEE in the last two plies (again, unless I'm in check).
Even with this, I sometimes get catastrophic drops in search depth, which end up losing the game...
I have some move generation staging, captures(), non_captures(), drop_moves_near_my_king(), drop_moves_near_opp_king() and others. I have LMR to drop moves that are not optimized yet. I suspect that dropping pieces involve trading of pieces not by piece value but by piece that is enough to attack or defend. There are times that exchanging a rook for a general is enough to win though my SEE values place rook higher than a general. It could be interesting to make SEE also aware of full piece gain rather than only part of the piece value gain.
I have the perpetual check, but not the repetition rule (I think I disallow repetition entirely). I'll need to add that in (requires a special rule-flag), but it's not high on my list of priorities...
Not allowing the repetition is enough except that you will not be able to claim a win when you play Black/Gote, the gui may probably claim it for you.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Shogi

Post by Evert »

Ferdy wrote: In mini shogi I observed that once you get your attack flowing defensive moves are no longer required much or something that the defense is also covered a bit. Dropping a general safely at the center of the board is already a terror to opponent's king when that king is in front, but attacking potential of general is reduced when the king is behind it, I discourage promoting a silver general to gold general if the position of opponent's king is way behind the promotion square.
Getting your king out of the promotion zone seems like a good idea anyway, but it's hard to put that in an evaluation term, as just walking your king to the other side of the board indiscriminately is suicide.
Those 2 quick drops could be a search issue too, these drop moves searches remain an interesting thing to explore.
Indeed, I currently don't reduce safe drops in the king zone. This is a mixed bag though.

I have changed my QS so that it returns mate scores from depths 0 and 1 (otherwise it just returns the stand-pat score), but this again appears to neither hurt nor help...
Not allowing the repetition is enough except that you will not be able to claim a win when you play Black/Gote, the gui may probably claim it for you.
Sure. Being able to claim is something that should work eventually though. On the other hand, I don't claim chases in Xiangqi either...
User avatar
hgm
Posts: 27794
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Shogi

Post by hgm »

Evert wrote:Getting your king out of the promotion zone seems like a good idea anyway, but it's hard to put that in an evaluation term, as just walking your king to the other side of the board indiscriminately is suicide.
I am a bit surprised by this remark, because in regular Shogi this is certainly not common practice. On the contrary, one tries to bury his own King quite deep in the zone, preferably in a corner, a strategy known as 'castling' (although there is no special move for it like in Chess). Good places are in the corner behind a Lance next to a Knight, the other 3 squares of the 3x3 corner area behind the Pawns packed with 3 generals (2xG + S). This is considered one of the strongest castles ('Anaguma'). Other popular castles are bases on putting the King in front of the Knight, having the Lance protect the edge file, and putting a general next to it to protect the Pawn shield on the other side and in front of it. Or move up the Pawn shield one rank, and put a Silver in front of the King protecting it ('Silver Crown'). It depends a bit on whether you expect the attack to come from the front or the side. (I.e. if the opponent castled to the same side or the opposite one.) In all cases the King remains on the 1st or 2nd rank.

It is good if you can build a fortress deep in the zone where you promote yourself, though, preferably on the last rank. Because then the opponent would have to attack you backwards, and most Shogi pieces are weak to useless in that direction. While every piece you drop in defense of the castle immediately promotes on the next move, aso that you can build impenetrable walls of promoted Pawns protecting each other. The problem is to get there alive, though.

In mini-Shogi the King usually stays put in the corner where it starts.

BTW, I can recommend participating in the UEC Cup. If you have an engine that doesn't crash and doesn't play illegal moves, there really isn't any reason not to participate. Prof. Takeshi Ito would probably be happy to have you and provide an operator. All you have to do is send him an e-mail to ask: taito (MAGIC SIGN) mbc PERIOD nifty PERIOD com

http://minerva.cs.uec.ac.jp/~uec55shogi ... =FrontPage
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Shogi

Post by Evert »

hgm wrote: I am a bit surprised by this remark, because in regular Shogi this is certainly not common practice. On the contrary, one tries to bury his own King quite deep in the zone, preferably in a corner, a strategy known as 'castling' (although there is no special move for it like in Chess). Good places are in the corner behind a Lance next to a Knight, the other 3 squares of the 3x3 corner area behind the Pawns packed with 3 generals (2xG + S). This is considered one of the strongest castles ('Anaguma'). Other popular castles are bases on putting the King in front of the Knight, having the Lance protect the edge file, and putting a general next to it to protect the Pawn shield on the other side and in front of it. Or move up the Pawn shield one rank, and put a Silver in front of the King protecting it ('Silver Crown'). It depends a bit on whether you expect the attack to come from the front or the side. (I.e. if the opponent castled to the same side or the opposite one.) In all cases the King remains on the 1st or 2nd rank.
Sure. The remark was based on observing a couple of games where the king got drop-swarmed, where many of the dropped pieces had the opportunity to promote. If you're out of the promotion zone it's much harder to have that happen to you, plus enemy pieces are weaker/useless if they have to move backward.

However, walking your king forward into the enemy camp is a sure way to commit suicide.
BTW, I can recommend participating in the UEC Cup. If you have an engine that doesn't crash and doesn't play illegal moves, there really isn't any reason not to participate. Prof. Takeshi Ito would probably be happy to have you and provide an operator. All you have to do is send him an e-mail to ask: taito (MAGIC SIGN) mbc PERIOD nifty PERIOD com

http://minerva.cs.uec.ac.jp/~uec55shogi ... =FrontPage
Ok. I may give it a shot. Part of the reason I'm hesitant is that I haven't tested on anything other than my development machines. In particular I haven't yet tried to make Windows compiles.
Henk
Posts: 7217
Joined: Mon May 27, 2013 10:31 am

Re: Shogi

Post by Henk »

I don't understand what is interesting about Shogi. Almost nobody in Holland knows this game.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Shogi

Post by Evert »

Henk wrote:I don't understand what is interesting about Shogi. Almost nobody in Holland knows this game.
So? Whether something is interesting or not is not determined by how popular something is. I'll also bet that practically no-one has heard of Capablanca Chess, Spartan Chess, Makruk or even Fischer Chess. Chinese Chess is also not very well known.

Anyway, for me personally part of the interest in Shogi is that it's a variant my program couldn't play before. Now it can, so I have a program that can play "normal" Chess, Xiangqi, Shogi, Makruk, Shatranj, Capablanca and a hoard of other variants. I happen to think that's neat.

I'll say this though: the games are interesting to look at, with the tide swinging back and forth often and intense king attacks.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Shogi

Post by Evert »

I'm playing Sjaak against GNUshogi at the moment, just to get some baseline for how strong/weak it is. Not sure this is helping much though, since Sjaak is eating GNUshogi alive and GNUshogi seems to have some issues (like horrible time-management).
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: Shogi

Post by JoshPettus »

Just so long as you're not worse then GNUShogi. :) GPSfish has artificial difficulty settings 1-20. They distribute it as an app eventhough it's just a commandline unix executable. Still, just put it in your applications folder and point uci2wb -s to the MacOS folder inside the app.

http://translate.google.com/translate?h ... rev=search