Skip to content

Commit

Permalink
make roysnake hungry
Browse files Browse the repository at this point in the history
  • Loading branch information
royboyz committed Jul 9, 2023
1 parent a729d81 commit 1efc17f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
76 changes: 32 additions & 44 deletions snake_roy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"game": {
"id": "a4f3e095-0ca7-4ad7-9b87-39cb91626a17",
"id": "47ddadec-2b19-4fb0-8aef-4b3cd4e80a92",
"ruleset": {
"name": "standard",
"version": "v1.2.3",
Expand All @@ -25,39 +25,35 @@
"timeout": 500,
"source": "custom"
},
"turn": 10,
"turn": 1,
"board": {
"height": 11,
"width": 11,
"snakes": [
{
"id": "gs_jrHBp8mSSmvDRKG8jbKF3Qt3",
"name": "Fat Roy Snake Test",
"latency": "280",
"health": 92,
"id": "gs_GGRjDYCQFpx7XTqtJJJHPyrX",
"name": "Roy Snake Test",
"latency": "406",
"health": 99,
"body": [
{
"x": 7,
"y": 5
"x": 5,
"y": 10
},
{
"x": 8,
"y": 5
"x": 5,
"y": 9
},
{
"x": 8,
"y": 4
},
{
"x": 8,
"y": 3
"x": 5,
"y": 9
}
],
"head": {
"x": 7,
"y": 5
"x": 5,
"y": 10
},
"length": 4,
"length": 3,
"shout": "",
"squad": "",
"customizations": {
Expand All @@ -69,48 +65,40 @@
],
"food": [
{
"x": 5,
"y": 5
},
{
"x": 6,
"y": 3
"x": 4,
"y": 10
},
{
"x": 4,
"y": 6
"x": 5,
"y": 5
}
],
"hazards": []
},
"you": {
"id": "gs_jrHBp8mSSmvDRKG8jbKF3Qt3",
"name": "Fat Roy Snake Test",
"latency": "280",
"health": 92,
"id": "gs_GGRjDYCQFpx7XTqtJJJHPyrX",
"name": "Roy Snake Test",
"latency": "406",
"health": 99,
"body": [
{
"x": 7,
"y": 5
},
{
"x": 8,
"y": 5
"x": 5,
"y": 10
},
{
"x": 8,
"y": 4
"x": 5,
"y": 9
},
{
"x": 8,
"y": 3
"x": 5,
"y": 9
}
],
"head": {
"x": 7,
"y": 5
"x": 5,
"y": 10
},
"length": 4,
"length": 3,
"shout": "",
"squad": "",
"customizations": {
Expand Down
13 changes: 13 additions & 0 deletions snake_roy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def move(game_state: typing.Dict) -> typing.Dict:
if my_head["y"]+1 == part["y"] and my_head["x"] == part["x"]:
is_move_safe["up"] = False

firstfood = game_state['board']["food"][0]
if my_head['x'] > firstfood['x']:
return {"move": "left"}

if my_head['x'] < firstfood['x']:
return {"move": "right"}

if my_head['x'] == firstfood['x']:
if my_head['y'] > firstfood['y']:
return {"move": "down"}
if my_head['y'] < firstfood['y']:
return {"move": "up"}

# Are there any safe moves left?
safe_moves = []
for move, is_safe in is_move_safe.items():
Expand Down

0 comments on commit 1efc17f

Please sign in to comment.