質問するログイン新規登録

回答編集履歴

3

5x5の件

2020/11/23 09:33

投稿

退会済みユーザー
answer CHANGED
File without changes

2

5x5の件

2020/11/23 09:32

投稿

退会済みユーザー
answer CHANGED
@@ -69,11 +69,11 @@
69
69
 
70
70
  if action == 0 and self.hunter_Position_X == 5:
71
71
  pass
72
- if action == 1 and self.hunter_Position_X == 0:
72
+ if action == 1 and self.hunter_Position_X == -1:
73
73
  pass
74
74
  if action == 2 and self.hunter_Position_Y == 5:
75
75
  pass
76
- if action == 3 and self.hunter_Position_Y == 0:
76
+ if action == 3 and self.hunter_Position_Y == -1:
77
77
  pass
78
78
  #例外処理としてエリア外に出る行為は1ターン無駄に消費する事とする。andは&と書くと想定外の動作となった為使用禁止。
79
79
  # time.sleep(0.01)

1

5x5の件

2020/11/23 09:32

投稿

退会済みユーザー
answer CHANGED
@@ -11,17 +11,17 @@
11
11
  class Game(gym.core.Env):
12
12
  #初期条件や各種変数の初期格納する。
13
13
  def __init__(self):
14
- self.hunter_Position_X=random.randint(0,5)
14
+ self.hunter_Position_X=random.randint(0,4)
15
- self.hunter_Position_Y=random.randint(0,5)
15
+ self.hunter_Position_Y=random.randint(0,4)
16
16
  # print("鬼の初期位置は"+str(self.hunter_Position_X),self.hunter_Position_Y)
17
17
  #selfでグローバル変数化している。鬼のx,y座標をランダムに配置。
18
- self.fugitive_Position_X=random.randint(0,5)
18
+ self.fugitive_Position_X=random.randint(0,4)
19
- self.fugitive_Position_Y=random.randint(0,5)
19
+ self.fugitive_Position_Y=random.randint(0,4)
20
20
  # print("逃亡者の初期位置は"+str(self.fugitive_Position_X),self.fugitive_Position_Y)
21
21
  #selfでグローバル変数化している。逃亡者のx,y座標をランダムに配置。fugitiveは逃亡者という意味。
22
22
  while self.hunter_Position_X == self.fugitive_Position_X and self.hunter_Position_Y == self.fugitive_Position_Y:
23
- self.hunter_Position_X=random.randint(0,5)
23
+ self.hunter_Position_X=random.randint(0,4)
24
- self.hunter_Position_Y=random.randint(0,5)
24
+ self.hunter_Position_Y=random.randint(0,4)
25
25
  #print(self.hunter_Position_X,self.hunter_Position_Y)
26
26
  #逃亡者と鬼の位置が完全に一致している場合、鬼の初期位置を再度決める。
27
27
  self.game_count=0
@@ -38,7 +38,7 @@
38
38
 
39
39
  self.action_space = gym.spaces.Discrete(4)
40
40
  low = np.array([0, 0, 0, 0])
41
- high = np.array([5, 5, 5, 5])
41
+ high = np.array([4, 4, 4, 4])
42
42
  self.observation_space = gym.spaces.Box(low, high, dtype=np.int64)
43
43
  #逃走エリアを定義している。
44
44
  self.hunter_reward=0
@@ -53,13 +53,14 @@
53
53
  self.game_count += 1
54
54
  self.learn_count += 1
55
55
  # print("学習回数は",self.learn_count)
56
+
56
57
  if action == 0 and self.hunter_Position_X < 5:
57
58
  self.hunter_Position_X += 1
58
- if action == 1 and self.hunter_Position_X > 0:
59
+ if action == 1 and self.hunter_Position_X >= 0:
59
60
  self.hunter_Position_X -= 1
60
61
  if action == 2 and self.hunter_Position_Y < 5:
61
62
  self.hunter_Position_Y += 1
62
- if action == 3 and self.hunter_Position_Y > 0:
63
+ if action == 3 and self.hunter_Position_Y >= 0:
63
64
  self.hunter_Position_Y -= 1
64
65
  # print("鬼の位置は"+str(self.hunter_Position_X),self.hunter_Position_Y)
65
66
  # print("逃亡者の位置は"+str(self.fugitive_Position_X),self.fugitive_Position_Y)
@@ -104,13 +105,13 @@
104
105
  #self.fugitive_Position_Y -= 1
105
106
 
106
107
  def reset_position(self):
107
- hunter_Position_X=random.randint(0,5)
108
+ hunter_Position_X=random.randint(0,4)
108
- hunter_Position_Y=random.randint(0,5)
109
+ hunter_Position_Y=random.randint(0,4)
109
- fugitive_Position_X=random.randint(0,5)
110
+ fugitive_Position_X=random.randint(0,4)
110
- fugitive_Position_Y=random.randint(0,5)
111
+ fugitive_Position_Y=random.randint(0,4)
111
112
  while hunter_Position_X == fugitive_Position_X and hunter_Position_Y == fugitive_Position_Y:
112
- hunter_Position_X=random.randint(0,5)
113
+ hunter_Position_X=random.randint(0,4)
113
- hunter_Position_Y=random.randint(0,5)
114
+ hunter_Position_Y=random.randint(0,4)
114
115
  print("リセットされました!!!")
115
116
  print()
116
117
  return hunter_Position_X,hunter_Position_Y,fugitive_Position_X,fugitive_Position_Y