1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
-
|
-
|
|
-
|
-
|
|
|
|
|
|
-
|
!
-
|
!
!
-
|
-
|
|
!
-
|
|
|
!
-
|
|
|
|
|
|
|
-
-
|
-
|
!
!
| #module SRPGWalk
#deffunc srpginit str s1, int p2, int p3
map = s1 : mapsizeX = p2 : mapsizeY = p3
dim subx, 4 : subx = 0, 1, 0, -1
dim suby, 4 : suby = -1, 0, 1, 0
return
#deffunc serch@SRPGWalk int p1, int p2, local dir
dir = p2 : many++
serchX = x+subx(dir)
serchY = y+suby(dir) if (serchX<0)|(serchY<0)|(serchX>=mapsizeX)|(serchY>=mapsizeY) {
} else {
i = p1-peek(map, serchY*mapsizeX+serchX)+'0'
if i>0 { j = peek(result, serchY*mapsizeX+serchX)
if j<i {
x = serchX : y = serchY
logmes strf("[%03d]地点("+serchX+","+serchY+")は移動可能です", many)
poke result, serchY*mapsizeX+serchX, i
serch i, 0
x -= subx(dir) : y -= suby(dir)
} else {
logmes strf("[%03d]地点("+serchX+","+serchY+")は既に調査完了しています", many)
}
} else {
logmes strf("[%03d]地点("+serchX+","+serchY+")は移動不可能です", many)
}
}
if dir<3 : serch p1, dir+1
return
#deffunc mapserch var v1, int p2, int p3, int p4
sdim result, mapsizeX*mapsizeY
sdim v1, mapsizeX*mapsizeY
x = p2 : y = p3
many = 0
poke result, y*mapsizeX+x, p4+1
serch p4+1, 0
memcpy v1, result, mapsizeX*mapsizeY
return
#defcfunc prev@SRPGWalk int p1, int p2
stt = -1
i1 = peek(result, p1+p2*mapsizex)
repeat 4 serchX = p1+subx(cnt) : serchY = p2+suby(cnt) if (serchX<0)|(serchY<0)|(serchX>=mapsizex)|(serchY>=mapsizey){
continue } else {
i2 = peek(result, serchY*mapsizex+serchX)
if i2>i1 : i1 = i2 : stt = cnt^2
}
loop
return stt
#deffunc getwalk var v1, int p2, int p3
v1 = "" : x = p2 : y = p3
if peek(result, x+y*mapsizeX)==0 : return -1 repeat
b = prev(x, y) if b<0 : a = cnt : break v1 = str(b)+v1
x -= subx(b) : y -= suby(b) loop
poke v1, a, 0 return a
#global
#define MAPX 11 #define MAPY 11 #define MOVE 5 #define SQSIZE 32 randomize
screen 0, MAPX*SQSIZE, MAPY*SQSIZE
sdim mapdata, MAPX*MAPY
repeat MAPX*MAPY if rnd(4)==0 : poke mapdata, cnt, '2' : else : poke mapdata, cnt, '1'
loop
dim subx, 4 : subx = 0, 1, 0, -1
dim suby, 4 : suby = -1, 0, 1, 0
srpginit mapdata, MAPX, MAPY mx = (MAPX-1)/2 : my = (MAPY-1)/2 mapserch s, mx, my, MOVE targetX = mx : targetY = my
*main
redraw 0 repeat MAPY : c1 = cnt
repeat MAPX
a = 255-64*(peek(mapdata, c1*MAPX+cnt)-'0')
color a, a, a : boxf cnt*SQSIZE, c1*SQSIZE, (cnt+1)*SQSIZE, (c1+1)*SQSIZE
i = peek(s, c1*MAPX+cnt)
if i { color 255, 255, 255
x = cnt : y = c1 : gosub *draw_sq
pos cnt*SQSIZE+12, c1*SQSIZE+8 : mes i-1 }
loop
loop
getwalk walk, targetX, targetY : i = stat
if i>0{
title "移動可能 ["+targetX+","+targetY+"]"
color 255 : x = mx : y = my
repeat i a = peek(walk,cnt)-'0'
x += subx(a) : y += suby(a)
gosub *draw_sq
loop
}else{
if i {
title "移動不可 ["+targetX+","+targetY+"]"
} else {
title "現在地 ["+targetX+","+targetY+"]"
}
}
color 255, 255, 255 : circle mx*SQSIZE, my*SQSIZE, (mx+1)*SQSIZE, (my+1)*SQSIZE
redraw onclick goto *set_target
stop
*set_target
targetX = mousex/SQSIZE : targetY = mousey/SQSIZE
goto *main
*draw_sq
line x*SQSIZE+1, y*SQSIZE+1, (x+1)*SQSIZE-2, y*SQSIZE+1
line (x+1)*SQSIZE-2, y*SQSIZE+1, (x+1)*SQSIZE-2, (y+1)*SQSIZE-2
line (x+1)*SQSIZE-2, (y+1)*SQSIZE-2, x*SQSIZE+1, (y+1)*SQSIZE-2
line x*SQSIZE+1, (y+1)*SQSIZE-2, x*SQSIZE+1, y*SQSIZE+1
return
|