33
16
This is the Grid Game:
It's a game based on cellular automata, where the aim is to remove all of the pieces belonging to your opponent.
How it works:
- There are two kinds of piece in the game, cities and walkers.
- Each player starts with one city (marked with C and a number, which is it's health), which will regularly send out walkers (marked with a number, initially the number 1) in a given direction.
- The player can change the direction of all of their walkers to be north, south, east or west at any time.
- When walkers can't go any further, they will stay still and can be joined by other walkers, increasing their number.
- When 10 or more walkers join up, they become another city. All new cities have 10 health.
- When walkers meet walkers or cities belonging to the opponent, they deal damage to the opponent equal to their number, and take damage equal to the opponent's number.
- Damage is dealt to all adjacent opponent pieces.
- There is no way to replenish the health of a city.
- The game ends when either player has no pieces remaining, or when a clear stale-mate is reached.
Because this question is already very long, I've attempted to write a more detailed description of the game, addressing specific queries about it in this wiki page.
The Challenge
To write a bot to play Grid Game, and defeat as many rival bots as possible.
- A bot is some code which will be run on each turn of the game.
- It can only be JavaScript, sorry.
- The size of the code is immaterial.
- An object named
api
will be provided as an interface to the player from your bot. - In this iteration of the challenge, there is no way for your bot to know what it's opponent is doing. The challenge is to write a proactive (not reactive) strategy.
Forbidden:
- Interacting with GridGame except via the documented api methods.
The API
- api.turn() - Returns the numbered turn the game is on.
- api.towardsX() - Aim your walkers towards the opponent on the East-West axis.
- api.towardsY() - Aim your walkers towards the opponent on the North-South axis.
- api.awayX() - Aim your walkers away from the opponent on the East-West axis.
- api.awayY() - Aim your walkers away from the opponent on the North-South axis.
- api.random_direction() - Aim your walkers in a randomly selected direction.
- api.north() - Alias of awayY. North for green player, South for red player.
- api.south() - Alias of towardsY. South for green player, North for red player.
- api.east() - Alias of towardsX. East for green player, West for red player.
- api.west() - Alias of AwayX. West for green player, East for red player.
- api.wait(turns) - Your bot code will not be run again until
turns
turns after this method is called. - api.spawning_turn() - Returns a boolean which if true if the Cities are going to send out a Walker this turn.
Notes:
- The last direction function called will define the next direction the walkers move in from that turn until a different direction is called.
- If no direction function is called walkers will continue in their current direction.
- Please do not set global variables, as these may conflict with those used by oponents, instead use
this.variable_name
to communicate between method calls.
How to write a bot
Note: I recommend playing a manual game or two first; to do this, grab a friend to play against and select 'Manual (simple)' in the footer.
- Go to https://ajfaraday.github.io/grid_game/
- Select a default bot as your base (in the green or red box)
- Click Edit Code in the same coloured box.
- Click Use when you're happy with it.
To test it:
- Select an opponent bot as the other colour (or 'Manual' if you'd like to challenge it yourself.
- Open the developer console (f12) in case of errors in your code.
- Click Start.
- Watch the game unfold.
- Click Reset and repeat the process as desired.
How to deploy your bot
Once you've written a boss you'd like to keep:
- Go to https://gist.github.com
- Log in, if not already logged in.
- (The default page is the form to create a new gist, this is where we want to be.)
- Name the file 'bot.js'
- Copy the code into bot.js
- Save the gist
- Copy the gist ID (an alphanumeric string found after the last forward slash in the URL).
This Gist ID can now be used to import your bot into Grid Game at any time:
- Select Gist Id in a coloured box.
- Paste the ID into the field which appears.
You will need to include this gist ID in your answer.
Note: Grid Game will use the most recent version of bot.js in the gist, updating the gist will update your answer.
Answer Format
Your answer will consist of:
- A Title consisting of
- A name for your bot
- The gist ID (which should be a link the gist).
- A brief description of the bot's strategy.
- Any notes you wish to include.
Note: I would like to include answers in the respository's code, partly to sidestep rate limiting on github's gist and partly to include more interesting bots for future users to challenge or modify. Please clearly indicate if you consent to your bot becoming a part of the game code or not.
Example answer:
### The Faraday Cage - d9eb9a70ad0dc0fb1885be0fce032adc
The Faraday Cage is an arrangement of four cities in the player's starting corner, which this bot will attempt to build, which then allows it to repeatedly send two 9's towards the opponent.
* This is named after Alan Faraday, the elder brother of the game creator, who discovered it while playing the game manually.
* It has proven difficult to defeat.
Please include this in the repository.
The Tournament
The competition will involve running a match for every permutation of two of the available bots.
There are three possible outcomes to a match:
- Outright win - A player is completely removed from the board. 3 points to the winner.
- Timeout win - The game will end if it reaches 3,000 turns. At this point, the winner is determined by the total health count. 2 points to the winner.
- Draw - If the game reaches 3,000 and the bots have an identical total health, it's a draw. Both players get 1 point.
Notes:
- The below scores are from the very first working tournament runner. I hope to present the results better in future.
- Currently this is a single match for each permutation. There will likely be multiple matches in future to smooth out the results for bots which use random functions.
- I also want to present the results of specific matches in future.
- I'll try to run it again for new bots, please alert me to changes in existing bots to request a re-run.
Current scores
(Run at 2019/11/12 09:15 UTC)
Detailed results (with links to replay matches) can be found at https://ajfaraday.github.io/grid_game/results/rankings.html
Avi - Intercept and Destroy 60
Brilliand - Line Drive 60
Brilliand - Galeforce 57
Brilliand - CBC Goes With Everything 55
william porter - Twin Citites 54
Brilliand - CBC Forever 51
Brilliand - Feint 51
Brilliand - Cage Bar Cutter 49
Brilliand - Parry and Slice 48
Avi - Hocus Pocus(!?) 48
Alion - Evolvor: First Encounter 47
Alion - Evolvor: Overnight 45
Brilliand - Backstabber 42
BradC - Sweeping Endgame 36
BradC - Quad Rush 35
Alion - Doombeam 33
Alion - Slideout 31
AJFaraday - Faraday Cage 28
Alion - Zerg Rush 25
BradC - Double Barrel 22
Alion - Weirdflow 21
Alion - Rushdown 15
AJFaraday - Rotate 12
AllirionX - 3 Base rush 9
AJFaraday - Orbit 8
AJFaraday - All Towards 3
(Thanks to @brilliand for correcting the unexpected interactions between bots in the tournament runner.)
——
7Since we're using computers and they are fast, does the tournament really have to be single-elimination? – my pronoun is monicareinstate – 2019-10-21T12:28:38.410
1Based on running a sample game, a few questions: walkers spawn every 3 ticks, yeah? Walkers are stopped by their own cities, yeah? What happens if there's two green cities in a row and try to spawn? Is one walker lost? Two walkers collide and they do damage orthogonally or diagonally? – Veskah – 2019-10-21T12:29:19.650
Is the bots' starting position always 2 cells away from their corners? Are they always at opposite corners? – my pronoun is monicareinstate – 2019-10-21T13:08:17.627
I think your "rotate" example bot writes to the global variable
n
, leading to weird results when competing with self. – my pronoun is monicareinstate – 2019-10-21T13:54:52.0406This seems to be missing a lot of critical information: for a start, how initial board positioning works, what stops walkers going any further, how turns work (simultaneous or sequential? What's the API which a bot must implement to be invoked each turn?), and the full signatures for the methods in the controller's API. – Peter Taylor – 2019-10-21T15:18:03.077
10The question should be self-contained. If we have to reverse engineer the controller to learn how to write an answer, the question has failed to fulfil its purpose. – Peter Taylor – 2019-10-21T16:02:19.010
1I'm highly against a single-elimination tournament. I'd much rather have a reliable ranking than uncertain short-lived enjoyment. – Alion – 2019-10-21T21:03:37.883
2
@AJFaraday I'd recommend looking at past KotHs. I am biased, but Formic Functions is a good example of a relatively well-handled ranking system, though here it could be simplified significantly, since it's a series of 1v1 games. Having a livestream is unheard of. It doesn't sound like too bad of an idea initially, but considering the fact that you should mark an answer at the end really makes it suboptimal.
– Alion – 2019-10-21T21:08:31.807@AJFaraday You might be best off just sticking to the 3000 turn limit. – Alion – 2019-10-21T21:12:54.917
Let us continue this discussion in chat.
– Alion – 2019-10-21T21:14:02.570This challenge is all about maximizing spawning, if there was a bit more board information available, this would've been a lot more interesting. Something like last board state, and current board state, even if it just showed your own cities and walkers. – LiefdeWen – 2019-10-22T12:49:37.970
1@AJFaraday I look forward to it, and I really like your online editor for the bots. +1 – LiefdeWen – 2019-10-22T13:20:55.403
What happens when 3 walkers (2 green and 1 red) end up on the same cell within a single turn? Moreover, what happens when the 2 green ones have a value total >= 10? – Alion – 2019-10-22T14:59:56.563
@AJFaraday Oh, my bad. The moment I started drawing the case I realized it couldn't be reached in normal gameplay due to the damage phase, because whenever greens and reds are adjacent, at least one color must disappear completely before the movement phase starts. – Alion – 2019-10-22T15:15:24.067
If more than 10 walkers join up, do they become a City with more than 10 health? For example, if a pair of 9-walkers from a City met up, would that become an 18-city? (i.e. Current rules only say "When 10 walkers join up, they become another city" - nothing about whether it has to be exactly 10 walkers, nor the health of the resulting city) – Chronocidal – 2019-10-22T16:05:43.057
Tournament rules for a corner switch? Except for Doombeam, no other solution has active targeting, and when you play off any of the other's (well any of the other answers by @Alion as of now) against FCage, the just end up exchanging corners and chill out with no changes – Varad Mahashabde – 2019-10-22T16:46:34.977
If the team starting on the west builds a city on the east, and their original city is destroyed, then does the meaning of "toward" and "away" update? What if there are multiple cities? Which one is "toward"? – Frambot – 2019-10-23T20:13:05.897