Skip to content

Commit

Permalink
Refactored by Sourcery
Browse files Browse the repository at this point in the history
  • Loading branch information
SourceryAI committed Feb 24, 2020
1 parent 0702f10 commit 112b4ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 1 addition & 4 deletions consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
DISK_FOUR_COUNTS = np.zeros([HEIGHT, WIDTH], int)
for row in range(HEIGHT):
for column in range(WIDTH):
disk_fours = []
for four in FOURS:
if four[row, column]:
disk_fours.append(four)
disk_fours = [four for four in FOURS if four[row, column]]
DISK_FOURS[row, column] = disk_fours
DISK_FOUR_COUNTS[row, column] = len(disk_fours)

Expand Down
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
25 changes: 14 additions & 11 deletions policy_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,31 @@ 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(
tag=self.training_scope.name + '/' + opponent.name + '/win_rate',
simple_value=win_rate)
simple_value=win_rate,
)
opponent_summary.value.add(
tag=self.training_scope.name + '/' + opponent.name + '/moves',
simple_value=average_moves)
simple_value=average_moves,
)

self.writer.add_summary(summary, step)
self.writer.add_summary(opponent_summary, step)

self.opponents.update_win_rate(opponent, win_rate)

print('Step %d. Opponent %s, win rate %.2f <%.2f>, %.2f moves' %
(step, opponent.name, win_rate, self.opponents.win_rates[opponent],
average_moves))
print('Step %d. Opponent %s, win rate %.2f <%.2f>, %.2f moves' % (
step,
opponent.name,
win_rate,
self.opponents.win_rates[opponent],
average_moves,
))

def create_new_opponent(self, name):
# Create clone of policy_player
Expand Down Expand Up @@ -263,10 +269,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

0 comments on commit 112b4ed

Please sign in to comment.