Files

97 lines
2.5 KiB
Plaintext

# Experimental!
# shogi game core
┌─╴Piece
~ {Type Side}
┌─╴Type
|Pawn |PPawn
|Rook |Dragon
|Bishop |Horse
|Lance |PLance
|Knight |PKnight
|Silver |PSilver
|Gold
|King
└─╴
┌─╴Side
|Sente |Gote
└─╴
└─╴
# translates between equivalent board string
# notation and internal structure
┌─╴Representation
# the standard initial board, in string form
STARTINGBOARDSTRING ← $ l n s g k g s n l
$ . b . . . . . r .
$ p p p p p p p p p
$ . . . . . . . . .
$ . . . . . . . . .
$ . . . . . . . . .
$ P P P P P P P P P
$ . R . . . . . B .
$ L N S G K G S N L
# OptionalPiece ? PieceString
FromString ↚ (
# order matters!
Notation ↚ [" P" "+P" " R" "+R" " B" "+B" " L" "+L" " N" "+N" " S" "+S" " G" " K"]
∊Notation⊸⌵
⨬(⋅[] # empty tile
| Piece ⊃(
⊗Notation⌵
⨬(Piece.Type.Pawn | Piece.Type.PPawn
| Piece.Type.Rook | Piece.Type.Dragon
| Piece.Type.Bishop | Piece.Type.Horse
| Piece.Type.Lance | Piece.Type.PLance
| Piece.Type.Knight | Piece.Type.PKnight
| Piece.Type.Silver | Piece.Type.PSilver
| Piece.Type.Gold
| Piece.Type.King
)
| ⨬(Piece.Side.Gote|Piece.Side.Sente)≍⊸⌵
)
)
)
# PieceString ? Piece
ToString ↚ (
≠0⊸⧻
⨬(⋅" ."
| °Piece
⍡(" P" ⍩°Piece.Type.Pawn | "+P" ⍩°Piece.Type.PPawn
| " R" ⍩°Piece.Type.Rook | "+R" ⍩°Piece.Type.Dragon
| " B" ⍩°Piece.Type.Bishop | "+B" ⍩°Piece.Type.Horse
| " L" ⍩°Piece.Type.Lance | "+L" ⍩°Piece.Type.PLance
| " N" ⍩°Piece.Type.Knight | "+N" ⍩°Piece.Type.PKnight
| " S" ⍩°Piece.Type.Silver | "+S" ⍩°Piece.Type.PSilver
| " G" ⍩°Piece.Type.Gold
| " K" ⍩°Piece.Type.King
)
˜⍥¯
)
)
PieceString ← ⌅(ToString|FromString)
ArrayString ← ⌅(≡₀◇ToString|⍚₁FromString)
BoardString ← ⌅(
ArrayString
/$"_\n_" ≡/⊂
| ⊜(⬚@ ↯∞_2)⊸≠@\n
°ArrayString
)
PrintBoardString ← (
&p" 9 8 7 6 5 4 3 2 1|"
&p"------------------+--"
⊜∘⊸≠@\n
≡⊂@|⍉¤"一二三四五六七八九"
≡&p˜≡⊂
)
└─╴
Representation!(
STARTINGBOARDSTRING
⍜°BoardString(∘)
PrintBoardString
)