1 -- generic functions for shogi themes
2 -- FIXME: still depends on Shogi.ttf for the tile
4 function tile(white
, ratio
)
5 return function(size
, args
)
6 local i
= Image(size
,size
)
9 local g
= RadialGradient(Point(size
*0.5,size
*0.5), size
*0.5, Point(size
*0.3,size
*0.3))
14 local flip
= (white
or args
.flipped
) and not (white
and args
.flipped
)
17 i
:translate(-size
, -size
)
19 b
:translate(-size
, -size
)
25 i
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
27 b
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
30 i
:draw_glyph(Rect(0,0,size
,size
), "../ShogiSVG-TTF/Shogi.ttf", "0x2c", "black", b
)
31 --i:draw_svg(Rect(0,0,size,size), "../ShogiSVG/tile.svg")
36 function draw_arrowhead(i
, p
, vx
,vy
, length
, rwidth
, linecolor
,linewidth
)
37 -- normalize to 1 the direction vector
38 local vl
= (vx
*vx
+ vy
*vy
)^
0.5
40 -- the component vector along the arrow direction
41 local vxdirect
, vydirect
= -vx
*length
, -vy
*length
42 -- an orthogonal vector of requested relative width
43 local vxortho
,vyortho
= vydirect
*rwidth
, -vxdirect
*rwidth
45 i
:draw_line(p
,Point(p
.x
+vxdirect
+vxortho
,p
.y
-vydirect
-vyortho
), linecolor
,linewidth
)
46 i
:draw_line(p
,Point(p
.x
+vxdirect
-vxortho
,p
.y
-vydirect
+vyortho
), linecolor
,linewidth
)
49 function shogi_moves(moves
)
50 return function(i
,size
)
51 if not theme
.options
.moves_overlay
.value
then
56 --local xcenter, ycenter, width = size/2, size/2, size/4
57 local xcenter
, ycenter
, width
= 0.8*size
, 0.82*size
, 0.08*size
58 local tilesize
,shortsize
= 0.8*width
, 0.3*width
59 local arrowlen
,arrowrwidth
= 0.2*width
, 0.5
60 local centerpoint
= Point(xcenter
,ycenter
)
61 local b
= Brush("red")
62 for index
,move
in ipairs(moves
) do
63 local x
,y
,long
= move
[1],move
[2],move
[3]
65 local p2
= Point(xcenter
+1.5*x
*width
, ycenter
-1.5*y
*width
)
66 i
:draw_line(centerpoint
,p2
, "purple",1)
67 draw_arrowhead(i
, p2
, x
,y
, arrowlen
,arrowrwidth
, "purple",1)
69 i
:draw_line(centerpoint
, Point(xcenter
+x
*width
,ycenter
-y
*width
),"red",1)
70 i
:fill_rect(Rect(xcenter
+x
*width
-shortsize
/2, ycenter
-y
*width
-shortsize
/2,
71 shortsize
, shortsize
), b
)
76 i
:fill_rect(Rect(xcenter
-tilesize
/2,ycenter
-tilesize
/2,
77 tilesize
,tilesize
), b
)
85 shogichars
["king"] = {"0x7389", {"0x7389", "0x5c06"}}
86 shogichars
["jade general"] = {"0x738b", {"0x738b", "0x5c06"}}
87 shogichars
["flying chariot"] = {"0x98db", {"0x98db", "0x8eca"}}
88 shogichars
["bishop"] = {"0x89d2", {"0x89d2", "0x884c"}}
89 shogichars
["gold general"] = {"0x91d1", {"0x91d1", "0x5c06"}}
90 shogichars
["silver general"] = {"0x9280", {"0x9280", "0x5c06"}}
91 shogichars
["knight"] = {"0x6842", {"0x6842", "0x99ac"}}
92 shogichars
["incense chariot"] = {"0x9999", {"0x9999", "0x8eca"}}
93 shogichars
["pawn"] = {"0x6b69", {"0x6b69", "0x5175"}}
94 shogichars
["dragon king"] = {"0x9f8d", {"0x9f8d", "0x738b"}}
95 shogichars
["dragon horse"] = {"0x99ac", {"0x9f8d", "0x99ac"}}
96 shogichars
["narigin"] = {"0x5168", {"0x6210", "0x9280"}}
97 shogichars
["narikei"] = {"0x572d", {"0x6210", "0x6842"}}
98 shogichars
["narikyo"] = {"0x674f", {"0x6210", "0x9999"}}
99 shogichars
["tokin"] = {"0x3068", {"0x3068", "0x91d1"}}
101 shogichars
["drunken elephant"] = {"0x9154", {"0x9154", "0x8c61"}}
102 shogichars
["crown prince"] = {"0x592a", {"0x592a", "0x5b50"}}
104 shogichars
["tori phoenix"] = { "0x9d6c" }
105 shogichars
["tori falcon"] = { "0x9df9" }
106 shogichars
["tori eagle"] = { "0x9d70" }
107 shogichars
["tori crane"] = { "0x9db4" }
108 shogichars
["tori quail"] = { "0x9d89" }
109 shogichars
["tori pheasant"] = { "0x96c9" }
110 shogichars
["tori swallow"] = { "0x71d5" }
111 shogichars
["tori goose"] = { "0x9d08" }
112 -- Chess compatibility (part of Dai Shogi)
113 shogichars
["free king"] = {"0x5954", {"0x5954", "0x738b"}}
118 {-1,-1},{0,-1},{1,-1}}
119 shogimoves_rook
= {{-1,0,1},{1,0,1},{0,-1,1},{0,1,1}}
120 shogimoves_dragon
= {
121 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
122 {-1,-1},{1,-1},{-1,1},{1,1}}
123 shogimoves_bishop
= {{-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1}}
125 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
126 {-1,0},{1,0},{0,-1},{0,1}}
130 shogimoves_silver
= {
133 shogimoves_knight
= {{-1,2},{1,2}}
134 shogimoves_lance
= {{0,1,1}}
135 shogimoves_pawn
= {{0,1}}
137 shogimoves_drunken_elephant
= {
142 shogimoves_freeking
= {
143 {-1,1,1},{0,1,1},{1,1,1},
145 {-1,-1,1},{0,-1,1},{1,-1,1}}
148 {-1,1,1},{0,1},{1,1,1},
150 {-1,-1},{-2,-2},{0,-1,1},{1,-1},{2,-2}}
153 {-1,-1},{0,-1},{1,-1}}
154 shogimoves_right_quail
= {{0,1,1},{-1,-1,1},{1,-1}}
155 shogimoves_left_quail
= {{0,1,1},{1,-1,1},{-1,-1}}
156 shogimoves_pheasant
= {{0,2},{-1,-1},{1,-1}}
157 shogimoves_goose
= {{-2,2},{2,2},{0,-2}}