add history to existing snakes
This commit is contained in:
+5
-1
@@ -1,6 +1,8 @@
|
|||||||
|
from snakes.TemplateSnake import TemplateSnake
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
class DummSnake:
|
class DummSnake(TemplateSnake):
|
||||||
def choose_move(self, data: dict) -> str:
|
def choose_move(self, data: dict) -> str:
|
||||||
is_move_safe = {"up": True, "down": True, "left": True, "right": True}
|
is_move_safe = {"up": True, "down": True, "left": True, "right": True}
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ class DummSnake:
|
|||||||
|
|
||||||
if len(safe_moves) == 0:
|
if len(safe_moves) == 0:
|
||||||
print(f"MOVE {data['turn']}: No safe moves detected! Moving down")
|
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"}
|
return {"move": "down"}
|
||||||
|
|
||||||
# Choose a random move from the safe ones
|
# 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
|
# TODO: Step 4 - Move towards food instead of random, to regain health and survive longer
|
||||||
# food = game_state['board']['food']
|
# 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}")
|
print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {is_move_safe}")
|
||||||
|
|
||||||
return move
|
return move
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
from snakes.TemplateSnake import TemplateSnake
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from scipy import spatial
|
from scipy import spatial
|
||||||
|
|
||||||
class LogicSnake:
|
class LogicSnake(TemplateSnake):
|
||||||
def avoid_my_body(self, my_body, possible_moves: dict) -> list:
|
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.
|
my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake.
|
||||||
@@ -138,6 +140,7 @@ class LogicSnake:
|
|||||||
move = "up"
|
move = "up"
|
||||||
print("GOING TO LOSE!!")
|
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}")
|
print(f"{data['game']['id']} MOVE {data['turn']}: {move} picked from all valid options in {possible_moves}")
|
||||||
|
|
||||||
return move
|
return move
|
||||||
|
|||||||
Reference in New Issue
Block a user