I'm interested in making a bot for TeeWorlds, with the ultimate aim of making a "campaign" mode, with scenarios. Not that I'll ever have time to do this, but these are my notes so far.
The bot would take as parameters:
* Accuracy
* Which weapons (including grappling hook) it's allowed to use. This could be used in scenarios to spawn 'hostages' (no weapons), 'zombies' (just hammer), 'ninjas' (sword and grapling hook), 'snipers' (laser only) etc.
Upon starting the Bot:
the bot would make waypoints for the map. (Appendix A)
Each 'Tick' of the bot:
it sees what waypoints are in line-of-sight of it.
it decides which of these it most wants to move towards. (Appendix B)
it moves towards it (Appendix C)
it sees what enemies are in line-of-sight of it.
it decides at which of these, and with which weapon, it most wants to shoot. (Appendix D)
it shoots with that weapon at that enemy (Appendix E)
the bot should maybe run in a separate thread, so a 'bot tick' can take multiple 'game ticks' to complete.
== Appendix A: making waypoints ==
make a waypoint on top of each item, spawn point, weapon, etc.
make a waypoint every N pixels, in a 2d grid
remove all waypoints that are inside walls
remove waypoint 'A' if it isn't on-top-of an item, and there exists another waypoint 'B', and 'B' is in line of sight of (at least) every waypoint that waypoint 'A' is line of sight of. Iterate until no more waypoints can be removed.
This should produce a graph (the comp-sci kind) of waypoints connected by line-of-sight. They should run all round the map and to all the items. This waypoint graph can be cached for maps (to save loading time when starting a new bot).
Waypoints should also be placed on each other player in the game - these waypoints move with the other players during the course of the game.
== Appendix B: deciding which waypoint to move towards ==
the bot uses a small feed-forward, 2-layer, neural net, with connection weights genetically evolved using "evolution strategy" over lots of games played.
The neural net takes as input:
* the bot's health, armour, weapons, ammo, etc.
* what weapons it is allowed to use (parameter to the bot)
* its accuracy (parameter to the bot)
* the distance from the waypoint to each item (shortest path along waypoints), and to each other player (along with their status).
It produces as output:
* the "goodness" of moving towards that waypoint
== Appendix C: moving towards a waypoint ==
if to left of waypoint, press "left"
if to right of waypoint, press "right"
if on grappling hook and not moving towards the waypoint faster than "cutoff", let go of hook
if the bot is X pixels more to the side of the waypoint than it is above it:
if on ground, jump
if at peak of jump, double jump
if can use the grappling hook (parameter to the bot), hook diagonally up and to the side towards the waypoint
== Appendix D: deciding which target to shoot at ==
the bot uses another small feed-forward, 2-layer, neural net, with connection weights genetically evolved using "evolution strategy" over lots of games played.
The neural net takes as input:
* its accuracy (parameter to the bot)
* the distance to the target
* the status of the target (armour, health, etc)
It produces as output:
* the "goodness" of attacking that target with each weapon type (including the "null" 'dont shoot' weapon)
the bot picks the best target&weapon it's allowed to (parameter to the bot).
== Appendix E: shooting at an enemy ==
Aim towards the enemy target, taking into account their current velocity, the speed of the projectile the bot is firing, and the distance to the enemy target. Use basic trigonometry to determine the angle to fire at - assuming all weapons go along a straight line (they don't - but the bot's aim-algorithm can be improved later).
Randomise the aim angle in a normal distribution, with standard deviation determined by the "accuracy" bot parameter.
Questions, comments, suggestions?