Comments/Ratings for a Single Item
I have updated the Shogi presets to spot check, checkmate, and stalemate, and they can now also enforce the rule against checkmating the King with a Pawn drop. They can also now use aliases for promoted pieces that each equal the label for its unpromoted state with a + sign in front. To see the code behind this, check out one of the presets, such as this one: http://play.chessvariants.org/pbm/play.php?game%3DShogi%26settings%3DJapanese-PNG&submit=Edit and the include file used for all Shogi presets: http://play.chessvariants.org/pbm/includes/shogi.txt
Fergus, I'm playing my first ever Shogi game. When it's my turn, the pieces are displayed off the center of the squares, shifted half way up, on the middle of the lines above their squares. When I look at the link for the game to see it (not when it's my turn) the pieces are perfectly in the middle. My opponent says that he is seeing everything fine. Any ideas what is wrong? Jose
Mine went away too. I change the board pieces and the board type, and suddenly it started working. Weird...
I have been working on getting Shogi to display legal moves when you click a piece. Since I am too tired to continue now, and it is not quite finished yet, I have restored the previous version until I can continue working on it again.
The code for displaying legal moves in Shogi appears to be working correctly now. The last touch was to make it recognize when a Pawn cannot be dropped because it would checkmate the King. Since this uses separate subroutines for checkmate and stalemate, I'm wondering if there is a circumstance in which a Pawn drop could, if it wern't illegal, simultaneously block a check on one's own King and checkmate the opponent's King. I'm thinking that a Pawn drop could both block a check and check the opponent's King only when checked by a Rook or Dragon King on the same rank or a Bishop or Dragon Horse attacking diagonally. Normally, the piece that had been attacking the King could capture the Pawn whose drop blocked its check. But if that piece were pinned, it could not. Can anyone come up with an example I can use for testing? I have noticed that adding the ability to display moves helps me in spotting bugs. In working on this, I have corrected some bugs in the Shogi include file.
The game below is not logical, or even plausible by any stretch of the imagination; it is, however a sequence of legal moves leading to a position in which Black's king is in check (and about to be mated), but cannot save himself with a pawn drop for the sole reason that it would give an illegal checkmate to White's king.
1. p 7g-7f 1... P 7c-7d 2. n 8i-7g 2... K 5a-6b 3. n 7g-8e 3... P 3c-3d 4. n 8e-7c; skip 4... K 6b-7c 5. b 8h-5e 5... K 7c-8d 6. b 5e-8b; skip 6... S 7a-8b 7. p 9g-9f 7... K 8d-8e 8. r 2h-9h 8... K 8e-7f 9. r*2f 9... K 7f-8g 10. s 7i-6h 10... P 7d-7e 11. s 6h-7g 11... K 8g-7g 12. g 6i-7i 12... K 7g-6g 13. g 7i-8h 13... P 7e-7f 14. p 5g-5f 14... N*5g 15. p 5f-5e 15... B 2b-5e 16. g 4i-4h 16... B*3c 17. r 9h-9g 17... P 7f-7g; skip 18. r 9g-8g 18... S 3a-2b 19. r 8g-8c; +r-dest 19... S 2b-3a 20. +r 8c-8g 20... L 1a-1b 21. g 8h-7g 21... B 5e-7g; skip
By the way, when entering these moves, I noticed an odd glitch. When I tried to play 9... K 7f-8g, a message appeared saying that the move was "not marked as legal". Strangely, the preset still allowed the move (but would not allow moves that truly were illegal). This may be connected to another glitch I stumbled across a couple days ago, which caused one of the Shogi presets to prematurely end a game by false checkmate. The log where this occurred was: tamandua-cvgameroom-2015-175-942
By the way, when entering these moves, I noticed an odd glitch. When I tried to play 9... K 7f-8g, a message appeared saying that the move was "not marked as legal". Strangely, the preset still allowed the move (but would not allow moves that truly were illegal).
This is not a glitch but a failsafe. For the JavaScript to know which moves are legal, they all have to be calculated ahead of time. But this is trickier than just testing any move for legality, because it also involves anticipating every possible move. Just in case the precalculation of legal moves misses something, the failsafe is built in of allowing any move with just a warning that it isn't recognized. This failsafe is especially helpful when developing code for calculating legal moves in advance.
I fixed the bug you found on line 9 of your game. Thanks.
And I corrected the log you mentioned. Thanks.
I'm working on a new Shogi preset that will use the fairychess file. I created new built-in functions for it I'll describe tomorrow. Here is a sequence of moves I am using for testing. The current position is one where a Pawn drop would cause checkmate if it were allowed. It currently stops the actual move, but it still displays the Pawn drop as a legal move. Since I am having trouble posting the form, here is the list of moves:
1. p 5g-5f
1... P 3c-3d
2. p 7g-7f
2... B 2b-8h; +B-dest
3. s 7i-8h
3... B*5g
4. g 6i-6h
4... B 5g-2d; +B-dest
5. p 2g-2f
5... P 5c-5d
6. p 5f-5e
6... P 5d-5e
7. g 6h-5g
7... +B 2d-5g
8. g 4i-5h
8... +B 5g-3i
9. b*5g
9... +B 3i-2h
10. n 8i-7g
10... S*7h
11. k 5i-6h
11... S 7h-8i; +S-dest
12. p 2f-2e
12... P 2c-2d
13. p 2e-2d
13... P 6c-6d
14. p 2d-2c; +p-dest
14... P*2b
15. +p 2c-2b
15... R 8b-2b
16. p 6g-6f
16... +S 8i-8h
17. p*5b // - Check! -
17... G 4a-5b
18. n 7g-6e
18... P 6d-6e
19. p 6f-6e
19... +S 8h-9i
20. p*5f
20... N*7e
21. p 8g-8f
21... R*8g
22. p 5f-5e
22... L*7g
23. p 6e-6d
23... +S 9i-8i
24. p 5e-5d
24... +S 8i-7i
25. p 5d-5c; +p-dest
25... G 5b-5c
26. p 6d-6c; +p-dest
26... G 5c-6c
27. p*5i
27... P*6g // - Check! -
28. g 5h-6g
28... N 7e-6g; +N-dest // - Check! -
29. k 6h-6g
29... R 8g-8h; +R-dest
30. b 5g-4f
30... R 2b-5b
31. n*2c
31... S*6e
32. n 2c-1a; +n-dest
I fixed the bug I described last night and some others. When I checked the current preset, it had the same bug and another one. Instead of working on fixing the current preset, I will work on finishing the new preset, then replace the current one with it. It seems to be working correctly, but there are some features I want to add.
Since the new preset appears to be more bug-free, I copied the default settings file to default-backup, and I copied the one I was working on to default. So, past, current and new Shogi games will all use the new Shogi preset that uses the fairychess include file. Details are on the page.
Besides using the fairychess include file, the new Shogi preset uses its own fairyshogi include file. Here I'll go over some of the new features in this include file.
Besides using -Range functions to indicate the range of movement of a piece, this include file uses -Drop functions to indicate which spaces a piece may be legally dropped on. The stalemated function uses a foreach-next loop to go through all empty spaces on the board, and it tests each space with the Drop function for the piece to be dropped. The simplest Drop function looks like this:
def Unrestricted-Drops #0 or true;
This just returns true, and it gets copied to every piece that can be dropped to any empty space like so:
foreach notation array r R b B g G s S:
set funcname join const #notation "-Drop";
copyfn Unrestricted-Drops #funcname;
next;
Lances and Knights have slightly more complicated Drop functions:
def White_Lance-Drop onboard where #0 0 1;
def Black_Lance-Drop onboard where #0 0 -1;
def White_Shogi_Knight-Drop onboard where #0 0 2;
def Black_Shogi_Knight-Drop onboard where #0 0 -2;
Instead of testing for specific ranks, these use onboard and where to test whether there is a space on the board one or two spaces ahead of the location the piece might be dropped on. This works better with boards of different sizes than naming specific ranks would.
The Pawns have the most complicated Drop functions:
def White_Shogi_Pawn-Drop allfalse lambda (== const space #0 White_Shogi_Pawn) merge ray #0 0 1 ray #0 0 -1 and onboard where #0 0 1;
def Black_Shogi_Pawn-Drop allfalse lambda (== const space #0 Black_Shogi_Pawn) merge ray #0 0 1 ray #0 0 -1 and onboard where #0 0 -1;
Beginning at the end, these first make the same test as the Lance's Drop functions do. Next, they test whether there is another Pawn on the same file. This is done by passing allfalse a lambda function that takes as its input an array of all the spaces in the file except the one the Pawn may potentially drop to. Whether this is an actual or a potential move, this space does not need to be tested. For an actual move, the Pawn will already be there before the test is performed, and for a potential move, a drop there would not be considered unless this space were already empty. To test the other spaces, the code uses the codename for the type of Pawn being checked. This is to prevent the function from being dependent on specific notation for a piece.
This function does not test whether a Pawn drop will checkmate the King. This last test is done within the stalemated subroutine after temporarily dropping the Pawn.
Because not all piece labels are entirely alphabetic, it now uses haslower and hasupper instead of islower and isupper to identify which side pieces are on.
Because functions are normally global, the stalemated and matedbypawn subroutines do not define functions within themselves. Instead of defining the friend function, they set the variable friend to a lambda function that gets called by fn #friend. Instead of defining the friends function, they set the friends variable to an array of all pieces on the same side. Unlike functions, these are kept local to the subroutine they were created in, allowing matedbypawn to use some of the same variable names as stalemated without messing up the assignments stalemated has made to variables with the same name.
It currently stops the actual move, but it still displays the Pawn drop as a legal move.
Shogi rules are different from Chess, in this respect. In Chess illegal moves can never occur in a game; FIDE rules prescribe that such move should be taken back, and replaced by a legal one. But in Shogi, you just lose. In practice this seems to happen quite often even between club players through dropping Pawns in files that already contain one. The Japanese consider this an important thing: the 81-Dojo server does not refuse illegal Pawn drops, because that would be considered computer help.
So I think it would be logical to add the illegal move that caused game termination to the game record. Otherwise you would never know why the game suddenly ended.
Using fairy-test rather than default, I am working on getting it to handle the scenario where all pieces except the King are held in hand. The board has only 36 spaces pieces can be held in hand on, but there are 38 that may be held in hand. For testing purposes, the following series of moves brings the board to a position in which 36 pieces have been captured, and the others may soon be captured:
1. p 7g-7f
1... P 3c-3d
2. b 8h-2b; +b-dest
2... S 3a-2b
3. b*2f
3... B*8h
4. b 2f-5c; +b-dest
4... B 8h-9i; +B-dest
5. +b 5c-6c
5... +B 9i-8i
6. +b 6c-7c // - Check! -
6... N 8a-7c
7. p 7f-7e
7... +B 8i-7i
8. p 7e-7d
8... +B 7i-6i // - Check! -
9. k 5i-6i
9... R 8b-5b
10. p 7d-7c; +p-dest
10... R 5b-5g; +R-dest
11. +p 7c-8c
11... +R 5g-4g
12. +p 8c-9c
12... +R 4g-3g
13. r 2h-7h
13... +R 3g-2g
14. r 7h-7a; +r-dest
14... +R 2g-2i
15. +r 7a-9a
15... +R 2i-1i
16. +r 9a-6a // - Check! -
16... K 5a-4b
17. +r 6a-4a // - Check! -
17... K 4b-3c
18. +r 4a-2a
18... +R 1i-1g
19. +r 2a-1a
19... +R 1g-6g // - Check! -
20. k 6i-7i
20... +R 6g-8g
21. +r 1a-2b // - Check! -
21... K 3c-4d
22. +r 2b-1c
22... +R 8g-9g
23. +r 1c-2c
23... +R 9g-9c
24. +r 2c-3d // - Check! -
24... K 4d-5e
25. +r 3d-4c
25... +R 9c-4c
26. k 7i-6h
26... +R 4c-4i
27. s 3i-4h
27... K 5e-5f
28. s 4h-4g // - Check! -
In Chess illegal moves can never occur in a game; FIDE rules prescribe that such move should be taken back, and replaced by a legal one. But in Shogi, you just lose.
I checked Wikipedia, and it says the following:
In professional and serious (tournament) amateur games, a player who makes an illegal move loses immediately.[c] The loss stands even if play continued and the move was discovered later in game. However, if neither the opponent nor a third party points out the illegal move and the opponent later resigned, the resignation stands as the result.
This makes sense for over-the-board games, which is how Shogi is normally played in professional tournaments. But it does not make sense for Game Courier, which lets players preview their moves before confirming them. Just like it makes sense for Game Courier to ignore the rule in Chess that you have to move a piece if you touch it, it makes sense for Game Courier to ignore this rule.
The Japanese consider this an important thing: the 81-Dojo server does not refuse illegal Pawn drops, because that would be considered computer help.
I have never played on that server. Given the way this Game Courier preset works, each side is provided computer help, but it is equal for each player. If players want to play without computer help, as players in over-the-board tournaments do, they can play an unprogrammed preset. The programmed preset is programmed to display legal moves and forbid illegal moves, and to do this consistently, it should display only legal moves as legal and forbid all illegal moves.
The code for handling every piece but the Kings being held in hand seems to be working now. Instead of expanding the area of the board available for captured pieces, it uses a couple variables to hold the last two pieces. When the last two captured pieces are not Pawns, it switches them with Pawns, so that they remain available for dropping. As pieces are dropped, it moves Pawns from the variables back to the visible in-hand area. In practice, actual games will usually not get this far, and they will have no need for this code. The updated preset seems to be displaying past games well, though since Shogi is the most popular game on Game Courier, I have not tested them all.
There's a bug with this preset now where when you select a piece to drop no squares are highlighted as legal moves
There's a bug with this preset now where when you select a piece to drop no squares are highlighted as legal moves
Thanks for reporting this. It's now fixed.
23 comments displayed
Permalink to the exact comments currently displayed.