Repository: ASPP/pelita

Issue:
rename Bot.has_respawned
What about renaming `Bot.has_respawned` to `Bot.was_killed`? The word _respawned_ is totally meaningless for most non-hardcore programmers.

Discussion:

Patch:
diff --git a/pelita/game.py b/pelita/game.py
index 5789a9b3..2dd68761 100644
--- a/pelita/game.py
+++ b/pelita/game.py
@@ -275,7 +275,7 @@ def setup_game(team_specs, *, layout_dict, max_rounds=300, layout_name="", seed=
         kills = [0]*4,
 
         # List of boolean flags weather bot has been eaten since its last move
-        bot_eaten = [False]*4,
+        bot_was_killed = [False]*4,
 
         #: Messages the bots say. Keeps only the recent one at the respective bot’s index.
         say=[""] * 4,
@@ -418,7 +418,7 @@ def prepare_bot_state(game_state, idx=None):
         'score': game_state['score'][own_team],
         'kills': game_state['kills'][own_team::2],
         'deaths': game_state['deaths'][own_team::2],
-        'bot_eaten': game_state['bot_eaten'][own_team::2],
+        'bot_was_killed': game_state['bot_was_killed'][own_team::2],
         'error_count': len(game_state['errors'][own_team]),
         'food': list(game_state['food'][own_team]),
         'name': game_state['team_names'][own_team]
@@ -431,7 +431,7 @@ def prepare_bot_state(game_state, idx=None):
         'score': game_state['score'][enemy_team],
         'kills': game_state['kills'][enemy_team::2],
         'deaths': game_state['deaths'][enemy_team::2],
-        'bot_eaten': game_state['bot_eaten'][enemy_team::2],
+        'bot_was_killed': game_state['bot_was_killed'][enemy_team::2],
         'error_count': 0, # TODO. Could be left out for the enemy
         'food': list(game_state['food'][enemy_team]),
         'name': game_state['team_names'][enemy_team]
@@ -627,14 +627,14 @@ def apply_move(gamestate, bot_position):
     n_round = gamestate["round"]
     kills = gamestate["kills"]
     deaths = gamestate["deaths"]
-    bot_eaten = gamestate["bot_eaten"]
+    bot_was_killed = gamestate["bot_was_killed"]
     fatal_error = True if gamestate["fatal_errors"][team] else False
     #TODO how are fatal errors passed to us? dict with same structure as regular errors?
     #TODO do we need to communicate that fatal error was the reason for game over in any other way?
 
 
-    # reset our own bot_eaten flag
-    bot_eaten[turn] = False
+    # reset our own bot_was_killed flag
+    bot_was_killed[turn] = False
 
     # previous errors
     team_errors = gamestate["errors"][team]
@@ -694,7 +694,7 @@ def apply_move(gamestate, bot_position):
             bots[enemy_idx] = init_positions[enemy_idx]
             kills[turn] += 1
             deaths[enemy_idx] += 1
-            bot_eaten[enemy_idx] = True
+            bot_was_killed[enemy_idx] = True
             _logger.info(f"Bot {enemy_idx} reappears at {bots[enemy_idx]}.")
     else:
         # check if we have been eaten
@@ -706,7 +706,7 @@ def apply_move(gamestate, bot_position):
             bots[turn] = init_positions[turn]
             deaths[turn] += 1
             kills[enemies_on_target[0]] += 1
-            bot_eaten[turn] = True
+            bot_was_killed[turn] = True
             _logger.info(f"Bot {turn} reappears at {bots[turn]}.")
 
     errors = gamestate["errors"]
@@ -717,7 +717,7 @@ def apply_move(gamestate, bot_position):
         "score": score,
         "deaths": deaths,
         "kills": kills,
-        "bot_eaten": bot_eaten,
+        "bot_was_killed": bot_was_killed,
         "errors": errors,
         }
 
diff --git a/pelita/player/team.py b/pelita/player/team.py
index 5e80eaa5..a98d6140 100644
--- a/pelita/player/team.py
+++ b/pelita/player/team.py
@@ -104,8 +104,8 @@ class Team:
         team = me._team
 
         for idx, mybot in enumerate(team):
-            # If a bot has been eaten, we reset it’s bot track
-            if mybot.eaten:
+            # If a bot has been killed, we reset it’s bot track
+            if mybot.was_killed:
                 self._bot_track[idx] = []
 
         # Add our track
@@ -414,7 +414,7 @@ class Bot:
                           score,
                           kills,
                           deaths,
-                          eaten,
+                          was_killed,
                           random,
                           round,
                           is_blue,
@@ -441,7 +441,7 @@ class Bot:
         self.score  = score
         self.kills = kills
         self.deaths = deaths
-        self.eaten = eaten
+        self.was_killed = was_killed
         self._bot_index  = bot_index
         self.round = round
         self.is_blue = is_blue
@@ -636,7 +636,7 @@ def make_bots(*, walls, team, enemy, round, bot_turn, rng):
             score=team['score'],
             deaths=team['deaths'][idx],
             kills=team['kills'][idx],
-            eaten=team['bot_eaten'][idx],
+            was_killed=team['bot_was_killed'][idx],
             error_count=team['error_count'],
             food=team['food'],
             walls=walls,
@@ -658,7 +658,7 @@ def make_bots(*, walls, team, enemy, round, bot_turn, rng):
             score=enemy['score'],
             kills=enemy['kills'][idx],
             deaths=enemy['deaths'][idx],
-            eaten=enemy['bot_eaten'][idx],
+            was_killed=enemy['bot_was_killed'][idx],
             is_noisy=enemy['is_noisy'][idx],
             error_count=enemy['error_count'],
             food=enemy['food'],
diff --git a/pelita/utils.py b/pelita/utils.py
index 2ba81335..4da42bb9 100644
--- a/pelita/utils.py
+++ b/pelita/utils.py
@@ -58,7 +58,7 @@ def setup_test_game(*, layout, game=None, is_blue=True, round=None, score=None,
         'score': score[team_index],
         'kills': [0]*2,
         'deaths': [0]*2,
-        'bot_eaten' : [False]*2,
+        'bot_was_killed' : [False]*2,
         'error_count': 0,
         'food': food[team_index],
         'name': "blue" if is_blue else "red"
@@ -69,7 +69,7 @@ def setup_test_game(*, layout, game=None, is_blue=True, round=None, score=None,
         'score': score[enemy_index],
         'kills': [0]*2,
         'deaths': [0]*2,
-        'bot_eaten': [False]*2,
+        'bot_was_killed': [False]*2,
         'error_count': 0,
         'food': food[enemy_index],
         'is_noisy': [False] * len(layout['enemy']),


Test patch:
diff --git a/test/test_game.py b/test/test_game.py
index 52f998e8..5f41ce0f 100644
--- a/test/test_game.py
+++ b/test/test_game.py
@@ -884,7 +884,7 @@ def test_play_turn_move():
         "score": 0,
         "kills":[0]*4,
         "deaths": [0]*4,
-        "bot_eaten": [False]*4,
+        "bot_was_killed": [False]*4,
         "errors": [[], []],
         "fatal_errors": [{}, {}],
         "rnd": random.Random()
@@ -1266,9 +1266,9 @@ def test_setup_game_run_game_have_same_args():
 
 @pytest.mark.parametrize('bot_to_move', range(4))
 # all combinations of True False in a list of 4
-@pytest.mark.parametrize('bot_eaten_flags', itertools.product(*[(True, False)] * 4))
-def test_apply_move_resets_bot_eaten(bot_to_move, bot_eaten_flags):
-    """ Check that `prepare_bot_state` sees the proper bot_eaten flag
+@pytest.mark.parametrize('bot_was_killed_flags', itertools.product(*[(True, False)] * 4))
+def test_apply_move_resets_bot_was_killed(bot_to_move, bot_was_killed_flags):
+    """ Check that `prepare_bot_state` sees the proper bot_was_killed flag
     and that `apply_move` will reset the flag to False. """
     team_id = bot_to_move % 2
     other_bot = (bot_to_move + 2) % 4
@@ -1277,27 +1277,27 @@ def test_apply_move_resets_bot_eaten(bot_to_move, bot_eaten_flags):
     # specify which bot should move
     test_state = setup_random_basic_gamestate(turn=bot_to_move)
 
-    bot_eaten_flags = list(bot_eaten_flags) # needs to be a list
-    test_state['bot_eaten'] = bot_eaten_flags[:] # copy to avoid reference issues
+    bot_was_killed_flags = list(bot_was_killed_flags) # needs to be a list
+    test_state['bot_was_killed'] = bot_was_killed_flags[:] # copy to avoid reference issues
 
     # create bot state for current turn
     current_bot_position = test_state['bots'][bot_to_move]
     bot_state = game.prepare_bot_state(test_state)
 
-    # bot state should have proper bot_eaten flag
-    assert bot_state['team']['bot_eaten'] == bot_eaten_flags[team_id::2]
+    # bot state should have proper bot_was_killed flag
+    assert bot_state['team']['bot_was_killed'] == bot_was_killed_flags[team_id::2]
 
-    # apply a dummy move that should reset bot_eaten for the current bot
+    # apply a dummy move that should reset bot_was_killed for the current bot
     new_test_state = game.apply_move(test_state, current_bot_position)
 
-    # the bot_eaten flag should be False again
-    assert test_state['bot_eaten'][bot_to_move] == False
+    # the bot_was_killed flag should be False again
+    assert test_state['bot_was_killed'][bot_to_move] == False
 
-    # the bot_eaten flags for other bot should still be as before
-    assert test_state['bot_eaten'][other_bot] == bot_eaten_flags[other_bot]
+    # the bot_was_killed flags for other bot should still be as before
+    assert test_state['bot_was_killed'][other_bot] == bot_was_killed_flags[other_bot]
 
-    # all bot_eaten flags for other team should still be as before
-    assert test_state['bot_eaten'][other_team_id::2] == bot_eaten_flags[other_team_id::2]
+    # all bot_was_killed flags for other team should still be as before
+    assert test_state['bot_was_killed'][other_team_id::2] == bot_was_killed_flags[other_team_id::2]
 
 
 def test_bot_does_not_eat_own_food():
diff --git a/test/test_network.py b/test/test_network.py
index f01d6d0a..c967753a 100644
--- a/test/test_network.py
+++ b/test/test_network.py
@@ -96,7 +96,7 @@ def test_simpleclient(zmq_context):
                     'score': 0,
                     'kills': [0]*2,
                     'deaths': [0]*2,
-                    'bot_eaten': [False]*2,
+                    'bot_was_killed': [False]*2,
                     'error_count': 0,
                     'food': [(1, 1)],
                     'name': 'dummy',
@@ -107,7 +107,7 @@ def test_simpleclient(zmq_context):
                     'score': 0,
                     'kills': [0]*2,
                     'deaths': [0]*2,
-                    'bot_eaten': [False]*2,
+                    'bot_was_killed': [False]*2,
                     'food': [(2, 2)],
                     'name': 'other dummy',
                     'is_noisy': [False, False],
diff --git a/test/test_team.py b/test/test_team.py
index 6b9cd97f..d78a22f9 100644
--- a/test/test_team.py
+++ b/test/test_team.py
@@ -225,7 +225,7 @@ def test_track_and_kill_count():
         if bot.round == 1 and turn == 0:
             assert bot.track[0] == bot.position
 
-        if bot.eaten:
+        if bot.was_killed:
             state[turn]['eaten'] = True
             # if bot.deaths has increased from our last known value,
             # we add a kill
@@ -234,15 +234,15 @@ def test_track_and_kill_count():
             if state[turn]['deaths'] != bot.deaths:
                 state[turn]['times_killed'] += 1
             state[turn]['deaths'] = bot.deaths
-        if other.eaten:
+        if other.was_killed:
             state[1 - turn]['eaten'] = True
             if state[1 - turn]['deaths'] != bot.other.deaths:
                 state[1 - turn]['times_killed'] += 1
             state[1 - turn]['deaths'] = bot.other.deaths
 
-        if bot.eaten or not state[turn]['track']:
+        if bot.was_killed or not state[turn]['track']:
             state[turn]['track'] = [bot.position]
-        if other.eaten or not state[1 - turn]['track']:
+        if other.was_killed or not state[1 - turn]['track']:
             state[1 - turn]['track'] = [other.position]
         else:
             state[1 - turn]['track'].append(other.position)
@@ -286,9 +286,9 @@ def test_track_and_kill_count():
         team = state['turn'] % 2
 
         # The current bot knows about its deaths, *unless* it made suicide,
-        # so we have to substract 1 if bot_eaten is True
+        # so we have to substract 1 if bot_was_killed is True
         suicide_correction = [0] * 4
-        suicide_correction[state['turn']] = 1 if state['bot_eaten'][state['turn']] else 0
+        suicide_correction[state['turn']] = 1 if state['bot_was_killed'][state['turn']] else 0
 
         # The other team knows about its deaths, *unless* one of the bots got eaten
         # just now, or the previous bot made suicide
@@ -299,7 +299,7 @@ def test_track_and_kill_count():
 
         # suicide
         prev_idx = state['turn'] - 1
-        if old_deaths[prev_idx] == deaths[prev_idx] and state['bot_eaten'][prev_idx]:
+        if old_deaths[prev_idx] == deaths[prev_idx] and state['bot_was_killed'][prev_idx]:
             other_team_correction[prev_idx] = 1
 
         assert bot_states[0][0]['times_killed'] == deaths[0] - suicide_correction[0] - other_team_correction[0]
@@ -338,54 +338,54 @@ def test_eaten_flag_kill(bot_to_move):
                 new_pos = (x - 1, y)
             # The red team should notice immediately
             if bot.round == 1 and not bot.is_blue and bot.turn == 0:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             # as bot 1 has been moved, the eaten flag will be reset in all other cases
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 1:
             # we move in the first round as red team
             if bot.round == 1 and not bot.is_blue and bot.turn == 0:
                 new_pos = (x + 1, y)
             # The other team should notice immediately that its other bot (#0) has been eaten
             if bot.round == 1 and bot.is_blue and bot.turn == 1:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # When bot 0 moves, the flag is still set
             elif bot.round == 2 and bot.is_blue and bot.turn == 0:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 2:
             # we move in the first round as blue team in turn == 1
             if bot.round == 1 and bot.is_blue and bot.turn == 1:
                 new_pos = (x - 1, y)
             # The red team should notice immediately
             if bot.round == 1 and not bot.is_blue and bot.turn == 1:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             # as bot 2 has been moved, the eaten flag will be reset in all other cases
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 3:
             # we move in the first round as red team in turn == 1
             if bot.round == 1 and not bot.is_blue and bot.turn == 1:
                 new_pos = (x + 1, y)
             # The blue team should notice immediately (in round == 2!) that bot 1 has been eaten
             if bot.round == 2 and bot.is_blue and bot.turn == 0:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # When bot 1 moves, the flag is still set
             elif bot.round == 2 and bot.is_blue and bot.turn == 1:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
 
         # otherwise return current position
         return new_pos, state
@@ -414,60 +414,60 @@ def test_eaten_flag_suicide(bot_to_move):
                 new_pos = (x + 1, y)
             # our other bot should notice it in our next turn
             if bot.round == 1 and bot.is_blue and bot.turn == 1:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # bot 0 will notice it in the next round
             elif bot.round == 2 and bot.is_blue and bot.turn == 0:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 1:
             # we move in the first round as red team
             if bot.round == 1 and not bot.is_blue and bot.turn == 0:
                 new_pos = (x - 1, y)
             # we should notice in our next turn
             if bot.round == 1 and not bot.is_blue and bot.turn == 1:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # bot 1 will notice it in the next round
             elif bot.round == 2 and not bot.is_blue and bot.turn == 0:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 2:
             # we move in the first round as blue team in turn == 1
             if bot.round == 1 and bot.is_blue and bot.turn == 1:
                 new_pos = (x + 1, y)
             # we should notice in our next turn (next round!)
             if bot.round == 2 and bot.is_blue and bot.turn == 0:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # bot 2 will notice it in the next round as well
             elif bot.round == 2 and bot.is_blue and bot.turn == 1:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
         if bot_to_move == 3:
             # we move in the first round as red team in turn == 1
             if bot.round == 1 and not bot.is_blue and bot.turn == 1:
                 new_pos = (x - 1, y)
             # we should notice in our next turn (next round!)
             if bot.round == 2 and not bot.is_blue and bot.turn == 0:
-                assert bot.eaten is False
-                assert bot.other.eaten
+                assert bot.was_killed is False
+                assert bot.other.was_killed
             # bot 3 will notice it in the next round as well
             elif bot.round == 2 and not bot.is_blue and bot.turn == 1:
-                assert bot.eaten
-                assert bot.other.eaten is False
+                assert bot.was_killed
+                assert bot.other.was_killed is False
             else:
-                assert bot.eaten is False
-                assert bot.other.eaten is False
+                assert bot.was_killed is False
+                assert bot.other.was_killed is False
 
         # otherwise return current position
         return new_pos, state