(define first-empty
to-prison
(while not-empty? next-prison)
)
(define convert-prisoner
change-owner
(if (flag? bSilver) (change-type Silver))
(if (flag? bPawn) (change-type Pawn))
(if (flag? bBishop) (change-type Bishop))
(if (flag? bRook) (change-type Rook))
(if (flag? bLance) (change-type Lance))
(if (flag? bKnight) (change-type Knight))
)
(define prisoner-check
(if enemy?
(set-flag bSilver (piece? Promoted-Silver))
(set-flag bPawn (piece? Tokin))
(set-flag bBishop (piece? Promoted-Bishop))
(set-flag bRook (piece? Promoted-Rook))
(set-flag bKnight (piece? Promoted-Knight))
(set-flag bLance (piece? Promoted-Lance))
cascade
mark
(first-empty)
to
(convert-prisoner)
back
)
)
(define shift (
(verify (in-zone? play-zone))
$1
(verify not-friend?)
(prisoner-check)
add
))
(define shiftP (
(verify (in-zone? play-zone))
(set-flag came-from-zone (in-zone? promotion-zone))
$1
(verify not-friend?)
(prisoner-check)
(if (in-zone? $3) add)
(verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
(if enemy?
(change-type $2)
(if (in-zone? $3) (first-empty) (convert-prisoner))
add
else
(add $2)
)
))
(define shift2P (
(verify (in-zone? play-zone))
(set-flag came-from-zone (in-zone? promotion-zone))
$1
$2
(verify not-friend?)
(prisoner-check)
(if (in-zone? $4) add)
(verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
(if enemy?
(change-type $3)
(if (in-zone? $4) (first-empty) (convert-prisoner))
add
else
(add $3)
)
))
(define slide (
(verify (in-zone? play-zone))
$1 (while empty? add $1)
(verify not-friend?)
(prisoner-check)
add
))
(define slideP (
(verify (in-zone? play-zone))
(set-flag came-from-zone (in-zone? promotion-zone))
$1
(while empty?
(if (in-zone? promotion-zone) (set-flag came-from-zone true))
(if (in-zone? $3) add)
(if (flag? came-from-zone) (add $2))
$1
)
(verify not-friend?)
(prisoner-check)
(if (in-zone? $3) add)
(verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
(if enemy?
(change-type $2)
(if (in-zone? $3) (first-empty) (convert-prisoner))
add
else
(add $2)
)
))
(define drop-for-rank
(while (on-board? e)
(if empty? add)
e
)
(if empty? add)
)
(define drop ( ; $1 = drop zone
(verify (not-in-zone? play-zone))
to-board
(while (not-in-zone? $1) s)
(while (on-board? s)
mark
(drop-for-rank)
back
s
)
(drop-for-rank)
))
(define check-dir
(if (and (not-flag? bSafe)
(on-board? $1)
(not-enemy? $1)
(not-defended? $1)
)
(set-flag bSafe true)
)
)
(define drop-pawn-for-file
(set-flag friendly-pawn false)
mark
(if (and friend? (piece? Pawn)) (set-flag friendly-pawn true))
(while (and (not-flag? friendly-pawn) (on-board? s))
s
(if (and friend? (piece? Pawn)) (set-flag friendly-pawn true))
)
back
(if (not-flag? friendly-pawn)
mark
(while (on-board? s)
s
(if empty?
; Check and disallow if it attacks a King with mate
(if (and (enemy? n) (piece? King n))
; Can undefended Pawn be taken by King or can protected Pawn be taken?
(set-flag bSafe (or not-defended? (attacked? no-king)))
; Check if King can make a move in any other direction
n
(check-dir e)
(check-dir w)
(check-dir n)
(check-dir ne)
(check-dir nw)
(check-dir se)
(check-dir sw)
s
(if (flag? bSafe) add)
else
add
)
)
)
back
)
)
(define drop-pawn (
(verify (not-in-zone? play-zone))
to-board
(drop-pawn-for-file)
(while (on-board? e)
e
(drop-pawn-for-file)
)
))
; *********************************************************************
; SHOGI
; *********************************************************************
(define ranki 9i 8i 7i 6i 5i 4i 3i 2i 1i)
(define rankii 9ii 8ii 7ii 6ii 5ii 4ii 3ii 2ii 1ii)
(define rankiii 9iii 8iii 7iii 6iii 5iii 4iii 3iii 2iii 1iii)
(define rankiv-vi 9iv 8iv 7iv 6iv 5iv 4iv 3iv 2iv 1iv
9v 8v 7v 6v 5v 4v 3v 2v 1v
9vi 8vi 7vi 6vi 5vi 4vi 3vi 2vi 1vi)
(define rankvii 9vii 8vii 7vii 6vii 5vii 4vii 3vii 2vii 1vii)
(define rankviii 9viii 8viii 7viii 6viii 5viii 4viii 3viii 2viii 1viii)
(define rankix 9ix 8ix 7ix 6ix 5ix 4ix 3ix 2ix 1ix)
(define wprison
pw3i pw2i pw1i
pw3ii pw2ii pw1ii
pw3iii pw2iii pw1iii
pw3iv pw2iv pw1iv
pw3v pw2v pw1v
pw3vi pw2vi pw1vi
pw3vii pw2vii pw1vii
pw3viii pw2viii pw1viii
pw3ix pw2ix pw1ix
)
(define bprison
pb1i pb2i pb3i
pb1ii pb2ii pb3ii
pb1iii pb2iii pb3iii
pb1iv pb2iv pb3iv
pb1v pb2v pb3v
pb1vi pb2vi pb3vi
pb1vii pb2vii pb3vii
pb1viii pb2viii pb3viii
pb1ix pb2ix pb3ix
)
(game
(title "Shogi")
(description
"Object: Checkmate your opponent's King (just like Western Chess)\\
Right-click on the pieces to see how they move. Most of the pieces
can optionally promote when they reach the last 3 ranks. A piece
can also promote if it moves within or from the last 3 ranks.\\
When a piece is captured it is added to the capturer's `reserve`, an
army of pieces which can be reintroduced into play on the capturer's
side (pieces in reserve are also said to be `in hand`). Pieces are
all the same color, and the direction a piece is pointing from indicates
which player it belongs to. On any subsequent turn, the capturer may
`drop` any captured piece (in its unpromoted state) onto a vacant square
on the board, subject to a few rules:\\
* A Pawn may not be placed on a file that already contains a Pawn\
* A Pawn may not be dropped with mate\
* A Pawn, Knight, or Lance may not be placed on a square from which it
will never be able to move."
)
(strategy
"Keep the squares in your camp protected to keep your opponent
from dropping his pieces there. In particular the squares around
your King must be well guarded. Middle game play is heavily influenced
by play (and threats to play) from the reserves. Watch for squares
(on both sides) vulnerable to drops. A good way to defend against
a drop on a particular square is to move or drop a piece to that
square yourself. In Shogi, unlike Western Chess, material isn't so
important once the Kings are attacked. What is important is initiative
or `sente`; many games end in `races` to see which player can mate the
opposing king more quickly.\\
The relative values of the initial pieces may be: Rook - Bishop -
Gold/Silver - Lance/Knight - Pawn. Golds are slightly better than
Silvers, especially for defense. Lances and Knights are only useful
for offense; since they are weak, they want to push forward and promote
when possible. Pawns are not worth very much until they approach the
promotion zone, but a pawn in hand (i.e. part of the reserve of captured
pieces) can be very useful.\\
The game is widely covered in Japanese books, magazines, and newspapers.
Some detailed books and magazines in English on shogi strategy
can be found at
http://www.zillions-of-games.com/shogi.html."
)
(history
"Growing slowly in popularity outside of Japan, Shogi, the Japanese
form of Chess, is perhaps the most popular board game in Japan, with
perhaps a million active players. Some early form of chess was imported
into Japan (perhaps from Korea or Thailand), probably between the 10th
and 12th centuries. In the 16th century a rule was added (perhaps
inspired by the changeable loyalties of mercenaries), allowing captured
pieces to be re-used by the capturer, which sets shogi apart from all
other chesslike games. Other larger forms of the game have been recorded
(up to the inconceivable 25x25 Tai Shogi), but these have largely died
out, except for the 12x12 Chu (Middle) Shogi. The Nihon Shogi Remmei
(Japan Shogi Federation), formed in 1927, regulates play, conducts
tournaments, and maintains player rankings."
)
(option "prevent flipping" true)
(opening-sound "Audio\\Japan1.wav")
(win-sound "Audio\\Japan2.wav")
(loss-sound "Audio\\Japan2.wav")
(release-sound "Audio\\BongPercussive.wav")
(move-sound "Audio\\Bong5th.wav")
(capture-sound "Audio\\WoodBells.wav")
(players Black White)
(turn-order Black White)
(board
(image "images\Shogi\SHaag\ShogiBrd.bmp" "images\Shogi\IntlSHaag\ShogiBrd.bmp" "images\Shogi\ShogiBrd.bmp")
(grid
(start-rectangle 15 15 55 60) ; 22 25 62 70)
(dimensions ;17x9
; za = zb = "no mans land" area between board and prisons
; pb1-3 = black's prison table
; pw1-3 = white's prison table
("pw3/pw2/pw1/za/9/8/7/6/5/4/3/2/1/zb/pb1/pb2/pb3" (41 0))
("i/ii/iii/iv/v/vi/vii/viii/ix" (0 46))
)
(directions
(n 0 -1) (e 1 0) (s 0 1) (w -1 0) (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
)
)
; delete "no mans land"
(kill-positions
zai zaii zaiii zaiv zav zavi zavii zaviii zaix
zbi zbii zbiii zbiv zbv zbvi zbvii zbviii zbix
)
(unlink (wprison) (bprison))
; setup prisoners chains (is there a better way to specify a general many to one link?)
(links to-prison
(9i pb1ix) (8i pb1ix) (7i pb1ix) (6i pb1ix) (5i pb1ix) (4i pb1ix) (3i pb1ix) (2i pb1ix) (1i pb1ix)
(9ii pb1ix) (8ii pb1ix) (7ii pb1ix) (6ii pb1ix) (5ii pb1ix) (4ii pb1ix) (3ii pb1ix) (2ii pb1ix) (1ii pb1ix)
(9iii pb1ix) (8iii pb1ix) (7iii pb1ix) (6iii pb1ix) (5iii pb1ix) (4iii pb1ix) (3iii pb1ix) (2iii pb1ix) (1iii pb1ix)
(9iv pb1ix) (8iv pb1ix) (7iv pb1ix) (6iv pb1ix) (5iv pb1ix) (4iv pb1ix) (3iv pb1ix) (2iv pb1ix) (1iv pb1ix)
(9v pb1ix) (8v pb1ix) (7v pb1ix) (6v pb1ix) (5v pb1ix) (4v pb1ix) (3v pb1ix) (2v pb1ix) (1v pb1ix)
(9vi pb1ix) (8vi pb1ix) (7vi pb1ix) (6vi pb1ix) (5vi pb1ix) (4vi pb1ix) (3vi pb1ix) (2vi pb1ix) (1vi pb1ix)
(9vii pb1ix) (8vii pb1ix) (7vii pb1ix) (6vii pb1ix) (5vii pb1ix) (4vii pb1ix) (3vii pb1ix) (2vii pb1ix) (1vii pb1ix)
(9viii pb1ix) (8viii pb1ix) (7viii pb1ix) (6viii pb1ix) (5viii pb1ix) (4viii pb1ix) (3viii pb1ix) (2viii pb1ix) (1viii pb1ix)
(9ix pb1ix) (8ix pb1ix) (7ix pb1ix) (6ix pb1ix) (5ix pb1ix) (4ix pb1ix) (3ix pb1ix) (2ix pb1ix) (1ix pb1ix)
)