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.)
——