Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A naive attempt at being aggressive #4

merged 4 commits into from Jan 27, 2018

A naive attempt at being aggressive #4

merged 4 commits into from Jan 27, 2018


Copy link

smallsco commented Jan 24, 2018

The original Robosnake tries to play defensively, keeping to the centre of the game board. This was done for a few reasons: firstly, because the original implementation was against the 2016 API which would place gold in the centre, secondly, because it forces the enemy to the outside which makes it easier for them to get pinned against the edge of the arena, and finally, because head-on-head collisions were never fully supported in minimax.

With PRs #2 and #3 in place, we can now act more aggressively. This is a simple change that scores the game board higher the closer we are to neighbouring squares of the enemy's head (replacing the centre).

I'm actually shocked by how well this works. Using our win conditions from last year (17x17 board, 10 food) and a recursion depth of just four, we have a 100% win rate against all of my test snakes, except for YND and old Robo. (The sample size is 5 games against each snake). This includes powerhouses such as BTaS (sorry Tyler), Come Slither (sorry Stew), and D.Va...

Versus the 2017 Robosnake we have a 60% win rate.
Versus YND we have a 20% win rate.

Increasing the recursion depth improved our performance against YND. With a recursion depth of 6 we beat YND 40% of the time, and with a recursion depth of 8 we beat YND a whopping 80% of the time (however I had to increase the api timeout to 2s as we're only running on a t2.medium in dev). Given the small sample size however I'm not completely confident in these results.

@@ -180,10 +180,19 @@ local function heuristic( grid, state, my_moves, enemy_moves )
log( DEBUG, string.format('Food %s, distance %s, score %s', inspect(food[i]), dist, (dist*foodWeight) ) )

-- Hang out near the enemy's head
local kill_squares = algorithm.neighbours( state[ 'enemy' ][ 'body' ][ 'data' ][1], grid )

This comment has been minimized.

Copy link

tills13 Jan 24, 2018


should we not also check the enemy's length so we avoid hanging out next to a snake who is much larger than us?

This comment has been minimized.

Copy link

smallsco Jan 24, 2018

Author Contributor

That's magically handled by PR #2 - moving into the head of a larger snake scores the board negative infinity (negative max int) which will always be worse than anything this does to affect the board score.


This comment has been minimized.

Copy link
Contributor Author

smallsco commented Jan 27, 2018

Update Jan 26th:

I've increased aggressiveness even further, by modifying the snake to ignore food (more specifically, food won't affect the board weighting) unless our health is at 40 or less (this number can be customized in http.conf).

With this change, we beat YND 90% of the time played over 20 games on a 17x17 board with 10 food, using a recursion depth of 6.

I also fixed a small bug in how food is weighted so that no two food will have the same weight, even if they are equal distance from our head.

@smallsco smallsco merged commit 140fd9f into master Jan 27, 2018
@smallsco smallsco deleted the naive_aggression branch Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.