Skip to content

Commit

Permalink
Fix error caused by different rlboard.py version in root and solution…
Browse files Browse the repository at this point in the history
… dir
  • Loading branch information
shwars committed Jun 22, 2021
1 parent 8ec095c commit 40a1686
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion 8-Reinforcement/1-QLearning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ for epoch in range(5000):
v = probs(Q[x,y])
a = random.choices(list(actions),weights=v)[0]
dpos = actions[a]
m.move(dpos)
m.move(dpos,check_correctness=False) # we allow player to move outside the board, which terminates episode
r = reward(m)
cum_reward += r
if r==end_reward or cum_reward < -1000:
Expand Down
5 changes: 3 additions & 2 deletions 8-Reinforcement/1-QLearning/rlboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ def is_valid(self,pos):
def move_pos(self, pos, dpos):
return (pos[0] + dpos[0], pos[1] + dpos[1])

def move(self,dpos):
def move(self,dpos,check_correctness=True):
new_pos = self.move_pos(self.human,dpos)
self.human = new_pos
if self.is_valid(new_pos) or not check_correctness:
self.human = new_pos

def random_pos(self):
x = random.randint(0,self.width-1)
Expand Down
73 changes: 31 additions & 42 deletions 8-Reinforcement/1-QLearning/solution/notebook.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 8-Reinforcement/1-QLearning/solution/rlboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def is_valid(self,pos):
def move_pos(self, pos, dpos):
return (pos[0] + dpos[0], pos[1] + dpos[1])

def move(self,dpos):
def move(self,dpos,check_correctness=True):
new_pos = self.move_pos(self.human,dpos)
if self.is_valid(new_pos):
if self.is_valid(new_pos) or not check_correctness:
self.human = new_pos

def random_pos(self):
Expand Down

0 comments on commit 40a1686

Please sign in to comment.