Skip to content

Commit

Permalink
Refactored by Sourcery
Browse files Browse the repository at this point in the history
  • Loading branch information
SourceryAI committed Apr 5, 2020
1 parent 0702f10 commit d42e6c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def variables(self):
self.scope + '/')

def assign(self, other):
copy_ops = []
for self_var, other_var in zip(self.variables, other.variables):
copy_ops.append(tf.assign(other_var, self_var))
return copy_ops
return [
tf.assign(other_var, self_var)
for self_var, other_var in zip(self.variables, other.variables)
]


class PolicyNetwork(BaseNetwork):
Expand Down
8 changes: 2 additions & 6 deletions policy_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def train_games(self, opponent, games):

def process_results(self, opponent, games, step, summary):
win_rate = np.mean([game.policy_player_score for game in games])
average_moves = sum([len(game.moves)
for game in games]) / self.config.batch_size
average_moves = sum(len(game.moves) for game in games) / self.config.batch_size

opponent_summary = tf.Summary()
opponent_summary.value.add(
Expand Down Expand Up @@ -263,10 +262,7 @@ def move(self, move, policy_player_turn=False):
self.positions.append(self.position)
if self.position.gameover():
self.result = self.position.result
if self.result:
self.policy_player_score = float(policy_player_turn)
else:
self.policy_player_score = 0.5
self.policy_player_score = float(policy_player_turn) if self.result else 0.5


def main(_):
Expand Down
2 changes: 1 addition & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def find_previous_run(dir):
if os.path.isdir(dir):
runs = [child[4:] for child in os.listdir(dir) if child[:4] == 'run_']
if runs:
return max([int(run) for run in runs])
return max(int(run) for run in runs)

return 0

Expand Down

0 comments on commit d42e6c6

Please sign in to comment.