Skip to content

Commit

Permalink
Alternative fitness for tiling pattern game 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthijs den Toom authored and Matthijs den Toom committed Feb 14, 2019
1 parent c14b80e commit 509e25f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions gym_multi_robot/envs/tiling_pattern_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ def get_fitness(self):
count = np.sum(np.sum(sub_grid))
p_js.append(count)

summed_p_j = sum(p_js)

f = 0
for p in p_js:
p /= summed_p_j # Divide by sum of all elements.
if p != 0:
f += p * math.log(p) # Calculate entropy.

f *= s / math.log(len(p_js))
# Alternative fitness calculation, difference from 4 per square.
p_js = np.array(p_js)
difference = sum(abs(p_js - 4))
f = len(p_js) - difference

# summed_p_j = sum(p_js)
# f = 0
# for p in p_js:
# p /= summed_p_j # Divide by sum of all elements.
# if p != 0:
# f += p * math.log(p) # Calculate entropy.
#
# f *= s / math.log(len(p_js))
# TODO: possibly count tiles that robot holds.

return f

def write(self, storage_file='tiling_pattern_game.pickle'):
Expand Down

0 comments on commit 509e25f

Please sign in to comment.