So, I wrote a simple Javascript game (as yet unnamed) and naturally I wanted to write an API so I could write a bot to play it for me, and naturally I wanted to let the PPCG community have a go for themselves.
It's a 'snake' game with the simple goal of collecting as many blue squares as possible while avoiding red squares or the edge of the board. It was initially controlled with a mouse.
Find the API edition of the game here: https://ajfaraday.github.io/game_name_here/api.html
Gameplay:
- Type the code for your bot in the field under 'Your function': This will repeat automatically when you tell it to run.
- Only in Javascript, sorry.
- See restrictions, below.
- You can try it step-wise by clicking 'step'.
- I suggest you 'Run (fast)' once you have a workable function.
- Click 'Reset' to try a fresh game.
- Every 10 points will increase the points per blue square by 1.
- Every 10 points will increase the red squares spawned by 1.
- You can lose lives by:
- Gobbling up a red square (Be aware that, while you lose a life, it also breaks down the wall. Sacrificing lives to break through walls is a legitimate tactic).
- Attempting to leave the game board.
- Running down the 'Timeout' clock of 20 seconds between blue squares.
- You will not lose a life by 'stepping on your tail' in this version.
- Every 100 points will earn an additional life.
- Be aware that all coordinates are x, y starting in the top left corner. 0 indexed.
Restrictions:
- There is no security in this code. Please do not hack the game!
- Only use standard JS and the API methods described.
- PLEASE! Don't change API.coord
- You may not interact directly with Sketch, Cell or other entities defined within the game.
The competition
- Please give your entry title a short name for your snake.
- Include your JS code and any explanation you'd like to include.
- The OP will copy/paste the code into the game, and run it 5 times (using 'Run (fast)').
- The highest score achieved in those attempts is your score.
- The OP will add your score to the answer, and to a leader board in the question.
- You may submit more than one function.
Leader Board
+--------------------------+---------------------------------+----------+
| Username | Snake Name | Score |
+--------------------------+---------------------------------+----------+
| orlp | Simple A* | 595 |
+--------------------------+---------------------------------+----------+
Rendering Issue
This rendering issue has now been fixed and deployed.
Be aware that the snake can not travel diagonally between walls without losing a life.
Responsible disclosure: This is written in pure Javascript, it contains no logging, analytics or other data gathering processes. It's hosted on github pages, typically a trusted home of code.
If you want to confirm this, or would prefer to develop your answer on a locally hosted instance, the code is available here: https://github.com/ajfaraday/game_name_here
This is my first attempt at a competitive non-golf challenge, so I'm open to suggestions about how I could make it more suitable for this kind of situation.
Happy snaking!