回答編集履歴
1
追記
answer
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
単純にループで処理すればよいでのは?
|
2
|
+
また、移動範囲も制限しました。範囲を越えた移動はキャンセルするようにしています。
|
2
3
|
```Python
|
3
4
|
import random
|
5
|
+
from pprint import pprint
|
4
6
|
|
5
7
|
data = [[10,10]]
|
6
8
|
c = [[0,-1],[0,1],[-1,0],[1,0]]
|
7
9
|
|
8
|
-
for i in range(
|
10
|
+
for i in range(100):
|
9
11
|
rand_0 = random.randint(0,3)
|
10
|
-
|
12
|
+
pos = [data[-1][0]+c[rand_0][0], data[-1][1]+c[rand_0][1]]
|
11
13
|
|
14
|
+
# 移動範囲の制限=移動しないように
|
15
|
+
if pos[0] < 0: pos[0] = 0
|
16
|
+
if pos[0] > 12: pos[0] =12
|
17
|
+
if pos[1] < 0: pos[1] = 0
|
18
|
+
if pos[1] > 12: pos[1] =12
|
19
|
+
|
20
|
+
data.append(pos)
|
21
|
+
|
12
|
-
|
22
|
+
pprint(data) # [[10, 10], [10, 11], [9, 11], [8, 11], [9, 11]]
|
13
23
|
```
|