add history to existing snakes

This commit is contained in:
2024-04-01 05:16:45 +02:00
parent dde746900c
commit b1c0c14444
2 changed files with 9 additions and 2 deletions
+5 -1
View File
@@ -1,6 +1,8 @@
from snakes.TemplateSnake import TemplateSnake
import random
class DummSnake:
class DummSnake(TemplateSnake):
def choose_move(self, data: dict) -> str:
is_move_safe = {"up": True, "down": True, "left": True, "right": True}
@@ -38,6 +40,7 @@ class DummSnake:
if len(safe_moves) == 0:
print(f"MOVE {data['turn']}: No safe moves detected! Moving down")
self.add_to_history({"my_head": my_head, "my_neck": my_neck, "move": move, "safe_moves": safe_moves, "is_move_safe": is_move_safe})
return {"move": "down"}
# Choose a random move from the safe ones
@@ -46,6 +49,7 @@ class DummSnake:
# TODO: Step 4 - Move towards food instead of random, to regain health and survive longer
# food = game_state['board']['food']
self.add_to_history({"my_head": my_head, "my_neck": my_neck, "move": move, "safe_moves": safe_moves, "is_move_safe": is_move_safe})
print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {is_move_safe}")
return move
+4 -1
View File
@@ -1,7 +1,9 @@
from snakes.TemplateSnake import TemplateSnake
import random
from scipy import spatial
class LogicSnake:
class LogicSnake(TemplateSnake):
def avoid_my_body(self, my_body, possible_moves: dict) -> list:
"""
my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake.
@@ -138,6 +140,7 @@ class LogicSnake:
move = "up"
print("GOING TO LOSE!!")
self.add_to_history({"my_head": my_head, "my_body": tuple(my_body), "target": target, "possible_moves": possible_moves, "move": move})
print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {possible_moves}")
return move