1 (edited by rand() 2017-09-24 17:03:49)

Topic: Yet another bot in teeworlds

Hi all,

I'm working on making a bot for teeworlds.
It's not a aimbot but 100% computer controlled.

The code is based on teeworlds 0.6.3 client source. I removed graphics to run it on a server side. Thus the bot uses 2% cpu on average.

Basically, the bot has two modes : fight and idle.

On map load, the bot computes a simplified map by homotopic thinning of air tiles.
Example with cft5: http://pastebin.com/cxTs0Z4R
Crossing points are marked as waypoints.

When idle, the bot tries to follow path between two consecutive waypoints. At a waypoints, the bot choose randomly the next path to follow.

To follow a path, the bot uses jump and hook.

The bot grab the flag when it sees it. However it still does random moves so it can hardly capture the flag.

It enters fight mode when a enemy enter in a line of sight and is in idle mode otherwise. If there are many enemies, it takes the closest one.
If the flagcarrier is in hookrange, he becomes the new target enemy.

When in fighting mode, the bot tries to get close to the enemy and uses all the weapon it have from laser to hammer, choosing according to the distance. The bot does not care of other tees (except the flag carrier if in ctf).
About aim, at the moment, the bot assumes that target tee are not moving. Thus grenade are not really accurate.
When the target is in hookrange, the bot hooks in his direction regardless of other tees.

I run the bot on my server (search "Random" or "bot()") if you wanna test it. 163.172.95.239:8303)

I add autorejoin when kick/ban/spectator since the server run for the bot.

There is many things to do such as :
- route planning (on whole map and not locally)
- weapons/armor/heart pickup
- grenade boost/jump
- dead-end (the bot tries to go on the top on ctf5 from the main level)
- startegy on ctf: defence, attack (or trolling when winning)
- difficulty parameters
- …

Please, leave some feedback smile

PS: i m doing this for fun, because i never did bot or ai before and i like teeworlds and i miss bot|royale. The bots may have some interest in the future for training (a running tee to train aiming for example).

Updates


Wish list/suggestions/Ideas:
- auto leave when server is full (-> priority for human player)
- leaves when no player and joins when >0 player
- communication between bots (=> strategy)
- server mod (?)
- running/evading bot

13-09-2015
------------------------------------
- some stuff i forgot
- the server run on 195.154.80.148:8303

27-07-2015
------------------------------------
- Clean client.cpp using config file to connect a server
- Add command to add messages in config file

------------------------------------
25-06-2015
Changelog:
- Fix segfault on dm type
- Add Econ

------------------------------------
14-06-2015
Changelog:
- Chat every ~5min

------------------------------------
05-06-2015
Changelog:
- Occasional rocket jump
- Random weapons pickup

------------------------------------
03-06-2015
Changelog:
- Higher ping (5 -> 20)
- don't vote yes for ban/move to spectator

------------------------------------
28-05-2015
Changelog:
- Add random deviation on fire
- don't ignore enemy in hook range when carrying the flag

------------------------------------
26-05-2015
Changelog:
- Pathfinding on the whole map
- Go to the enemy flag if at stand and go to its flag stand if has the enemy flag
- Don't follow enemy when carrying the flag

Technical:
- a graph is made from the homotopic thinning with vertex (waypoints) and edges.
- pathfinding is only done between two waypoints
- the graph don't handle multi edge yet

Issue:
- following long path can imply big cpu usage, thus the algorithm is not fitted with complex map (standard maps are fine)
- when carrying the flag, the bot fires in wrong direction.
- try to take impossible way without rocket jump (or skill, depends smile ) (ctf5)

Well, at this point, the bot is competitive on ctf1/2/7, i did not try (or get feedback) on ctf3/4
ctf5 is still too open for it.
ctf6 has death tile that i don't handle properly.

Edit: server changes IP

2

Re: Yet another bot in teeworlds

Interesting. What's the issue with ctf5 exactly? Not enough hookpoints?

Not Luck, Just Magic.

3

Re: Yet another bot in teeworlds

It's a mix of holes, multi edges, and impossible edge.
Because of multi edges and the size of the map, the bot restrict itself to the same path. It's not really an issue on other map. But this make humans able to play against it when 4 bots team up ^^

Moreover the bot doesn't detect impossible edge. Basically, it tries to get on the top from the main floor.

At the moment, the main issue is when the bot is stuck in a corner, using hook and trying to go up. But it's a common issue.

4

Re: Yet another bot in teeworlds

rand() wrote:

It's a mix of holes, multi edges, and impossible edge.
Because of multi edges and the size of the map, the bot restrict itself to the same path. It's not really an issue on other map. But this make humans able to play against it when 4 bots team up ^^

Moreover the bot doesn't detect impossible edge. Basically, it tries to get on the top from the main floor.

At the moment, the main issue is when the bot is stuck in a corner, using hook and trying to go up. But it's a common issue.

It's actually possible to go up from the main platform with hook only (near the flag). smile Maybe the bot recognizes this but only fails with the execution?

5

Re: Yet another bot in teeworlds

In fact, the bot can success on this side (i saw it and was quite suprised) but it fails in the vertical tunnel between a base and the middle of the map. The only way is to use rocket jump.

The bot follows path but "thinks" locally. At each tick, the bot look for a (not too) far tile of the path in the line of sigh and set it as target.
When a target is set, the bot hooks randomly and aims the better direction (among 32 directions) that increases its velocity towards the target.

To handle properly this kind of path, the bot should compute a sequence of move (i don't have another idea). But this  would be costly unless i find a efficient way to predict moves and know about the error in computation.
(i may have some idea while writing these lines ^^)

6

Re: Yet another bot in teeworlds

This bot is hard to beat...
Nice job!

A is for Apple.

7

Re: Yet another bot in teeworlds

rand() wrote:

In fact, the bot can success on this side (i saw it and was quite suprised) but it fails in the vertical tunnel between a base and the middle of the map. The only way is to use rocket jump.

The bot follows path but "thinks" locally. At each tick, the bot look for a (not too) far tile of the path in the line of sigh and set it as target.
When a target is set, the bot hooks randomly and aims the better direction (among 32 directions) that increases its velocity towards the target.

Whoa, that's awesome!

You've got to make it so that bots are not included in the player count to respect masterservers etiquette though.

Not Luck, Just Magic.

8 (edited by Oblique. 2015-05-29 02:37:30)

Re: Yet another bot in teeworlds

You ought to change the topic of this thread.
There are no other bots (that I know of) like this! big_smile

A is for Apple.

9

Re: Yet another bot in teeworlds

This sounds amazing! Good job!

Clan: Riot (I'm one of three leaders: Mile, Deku, pie)
Host teeworlds maps on a fng/ctf/dm/ddrace server for testing:http://riotproductions.tk/teewo/ broken-need reinstall nginx http://riotproductions.tk/bounce?whatEven, Teeworlds NA Discord chat

10 (edited by rand() 2015-05-30 09:38:45)

Re: Yet another bot in teeworlds

Oblique. wrote:

You ought to change the topic of this thread.
There are no other bots (that I know of) like this! big_smile

There were. More info about this in this thread https://www.teeworlds.com/forum/viewtopic.php?id=731 There are also interesting ideas that i may use.

Dune wrote:

You've got to make it so that bots are not included in the player count to respect masterservers etiquette though.

What do you mean ? My bots are mod client, the server is original. The binaries run on the same machine though.

11

Re: Yet another bot in teeworlds

rand() wrote:
Oblique. wrote:

You ought to change the topic of this thread.
There are no other bots (that I know of) like this! big_smile

There were. More info about this in this thread https://www.teeworlds.com/forum/viewtopic.php?id=731 There are also interesting ideas that i may use.

Dune wrote:

You've got to make it so that bots are not included in the player count to respect masterservers etiquette though.

What do you mean ? My bots are mod client, the server is original. The binaries run on the same machine though.

He's saying that it's master server etiquette to not count non-player clients.

12

Re: Yet another bot in teeworlds

For example, one of your servers is showing 4 players when it's empty.

Not Luck, Just Magic.

13

Re: Yet another bot in teeworlds

To make it, i must mod the server…
Are you suggesting me to make a mod from this point ? -> new gamemode to exclude specifically my bot client from the player list to master server ?

14

Re: Yet another bot in teeworlds

rand() wrote:

To make it, i must mod the server…
Are you suggesting me to make a mod from this point ? -> new gamemode to exclude specifically my bot client from the player list to master server ?

Your bots are actual connected clients - so everything is fine.
Keep up the work and bring them to ctf5 wink

Remember the 80s - good times smile

15

Re: Yet another bot in teeworlds

This sounds really cool.  what happens as the room fills up?  I think it would be a good idea to make it so that when someone joins a game a bot would disappear and when a player leaves a bot would rejoin to keep the game going.  Do you think this would be possible to do with your mod?  This would definitely make my TeeWorlds experience a lot better as I always seem to log on when there is no one online.  Corce I also only run vanilla TeeWrolds and don't play with mods or other peoples servers.. I don't know how to play on other TeeWorlds servers. I would love to play on yours to see how these bots work.

Jesus is my Lord and Savior. Praise be unto God for giving us a way to live with him.

Check out my DeviantArt for all my TeeWorlds art and ideas for Teeoworlds

16

Re: Yet another bot in teeworlds

Oh well I misunderstood the way this server works then. It doesn't require any server-side modification?

Not Luck, Just Magic.

17

Re: Yet another bot in teeworlds

Oy wrote:
rand() wrote:

To make it, i must mod the server…
Are you suggesting me to make a mod from this point ? -> new gamemode to exclude specifically my bot client from the player list to master server ?

Your bots are actual connected clients - so everything is fine.
Keep up the work and bring them to ctf5 wink

The best would be a server mod that lowers the actual player number. I can help you with that, if needed. Here's a patch:

diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 19745b3..7631324 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -1082,10 +1082,21 @@ void CServer::SendServerInfo(const NETADDR *pAddr, int Token)
 
        // count the players
        int PlayerCount = 0, ClientCount = 0;
+       int MaxPlayers = m_NetServer.MaxClients()-g_Config.m_SvSpectatorSlots;
+       int MaxClients = m_NetServer.MaxClients();
        for(int i = 0; i < MAX_CLIENTS; i++)
        {
                if(m_aClients[i].m_State != CClient::STATE_EMPTY)
                {
+                       // `Token != -1`: Only lie to external clients.
+                       if(Token != -1 && g_Config.m_SvModeratorBots && m_aClients[i].m_Authed == IConsole::ACCESS_LEVEL_MOD)
+                       {
+                               MaxClients--;
+                               if(MaxClients < MaxPlayers || GameServer()->IsClientPlayer(i))
+                                       MaxPlayers--;
+                               continue;
+                       }
+
                        if(GameServer()->IsClientPlayer(i))
                                PlayerCount++;
 
@@ -1114,14 +1125,17 @@ void CServer::SendServerInfo(const NETADDR *pAddr, int Token)
        p.AddString(aBuf, 2);
 
        str_format(aBuf, sizeof(aBuf), "%d", PlayerCount); p.AddString(aBuf, 3); // num players
-       str_format(aBuf, sizeof(aBuf), "%d", m_NetServer.MaxClients()-g_Config.m_SvSpectatorSlots); p.AddString(aBuf, 3); // max players
+       str_format(aBuf, sizeof(aBuf), "%d", MaxPlayers); p.AddString(aBuf, 3); // max players
        str_format(aBuf, sizeof(aBuf), "%d", ClientCount); p.AddString(aBuf, 3); // num clients
-       str_format(aBuf, sizeof(aBuf), "%d", m_NetServer.MaxClients()); p.AddString(aBuf, 3); // max clients
+       str_format(aBuf, sizeof(aBuf), "%d", MaxClients); p.AddString(aBuf, 3); // max clients
 
        for(i = 0; i < MAX_CLIENTS; i++)
        {
                if(m_aClients[i].m_State != CClient::STATE_EMPTY)
                {
+                       if(g_Config.m_SvModeratorBots && m_aClients[i].m_Authed == IConsole::ACCESS_LEVEL_MOD)
+                               continue;
+
                        p.AddString(ClientName(i), MAX_NAME_LENGTH); // client name
                        p.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan
                        str_format(aBuf, sizeof(aBuf), "%d", m_aClients[i].m_Country); p.AddString(aBuf, 6); // client country
diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h
index 4732729..83466c2 100644
--- a/src/engine/shared/config_variables.h
+++ b/src/engine/shared/config_variables.h
@@ -93,6 +93,7 @@ MACRO_CONFIG_INT(SvRconMaxTries, sv_rcon_max_tries, 3, 0, 100, CFGFLAG_SERVER, "
 MACRO_CONFIG_INT(SvRconBantime, sv_rcon_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if remote console authentication fails. 0 makes it just use kick")
 MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos")
 MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)")
+MACRO_CONFIG_INT(SvModeratorBots, sv_moderator_bots, 0, 0, 1, CFGFLAG_SERVER, "Count all logged-in moderators as bots, ignore them for the serverbrowser")
 
 MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
 MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console")

If you need it compiled for an operating system, tell me!

18 (edited by [pieLover] 2015-05-31 07:28:00)

Re: Yet another bot in teeworlds

rand() you could make it so when it's empty, the client-bots disconnect (and reconnect when someone joins), thus fixing the master-server etiquette issue.
Edit: After playing it, even on ctf5 I noticed that these bots are.. like bringing a claymore personnel mine to a fist fight. Excellent job, rand().

Clan: Riot (I'm one of three leaders: Mile, Deku, pie)
Host teeworlds maps on a fng/ctf/dm/ddrace server for testing:http://riotproductions.tk/teewo/ broken-need reinstall nginx http://riotproductions.tk/bounce?whatEven, Teeworlds NA Discord chat

19 (edited by rand() 2015-05-31 09:25:25)

Re: Yet another bot in teeworlds

Dune wrote:

Oh well I misunderstood the way this server works then. It doesn't require any server-side modification?

None, the bot is a client that can join any server.

@heinrich5991: i would like to avoid make the bot server dependent.

android272 wrote:

This sounds really cool.  what happens as the room fills up?  I think it would be a good idea to make it so that when someone joins a game a bot would disappear and when a player leaves a bot would rejoin to keep the game going.  Do you think this would be possible to do with your mod?  This would definitely make my TeeWorlds experience a lot better as I always seem to log on when there is no one online.  Corce I also only run vanilla TeeWrolds and don't play with mods or other peoples servers.. I don't know how to play on other TeeWorlds servers. I would love to play on yours to see how these bots work.

I add this to the wish list, you are not the first to ask for this smile

20

Re: Yet another bot in teeworlds

The bot support tuned servers?

21 (edited by 2015-06-06 00:41:01)

Re: Yet another bot in teeworlds

It should but i think some basic prediction and test use default tune params instead of server tuning. (because i did it badly)
I did try on modded server (i'm sure it will sucks on zcatch grenade)

I made a break in my break to add locally a rocket jump that you will hardly see since it use it with very restricted conditions.
I modify the linear graph so that the bot eventually take weapons. You can note the difference on a dm map.

22

Re: Yet another bot in teeworlds

Could you pleeaase make the bots quiet? smile

check out these maps: infiltrate - choco - dustycloud

23

Re: Yet another bot in teeworlds

Oh, i forgot to update the first message about this.

I will rewrite how message are handle to make the bot less chatty.
For the update, the bot remember 100 chat messages that players sent and sends one of them every ~30s with a random timeout.

24

Re: Yet another bot in teeworlds

But there are like 4~5 bots ingame. They spam a lot tongue

check out these maps: infiltrate - choco - dustycloud

25

Re: Yet another bot in teeworlds

Holy crap your bots are hard.

Jesus is my Lord and Savior. Praise be unto God for giving us a way to live with him.

Check out my DeviantArt for all my TeeWorlds art and ideas for Teeoworlds