Python 2

Overview

The version of Python 2 supported is Python 2.7.17

Each turn your source code will be compiled within a new sandbox, by default no information is shared or persisted between turns, if you wish to persist data then you should use the User Data field within the API.


Input - Standard Input (STDIN)

Within Python you can use sys.stdin to capture the STDIN input

for line in sys.stdin:

Ouput - Standard Outout (STDOUT)

Within Python you can simply use print() to return your CSV based instructions to BotWars.

print(','.join(actions))

Example Bot

The example bot will simply instruct it's robots to move in random directions around the map, it's just to show how the input and output works within PHP

import sys
import random

rdm = random.SystemRandom()
spawns = ["12:5", "12:12", "5:5", "5:12"]
directions = ['N','E','S','W']
actions = []

# Read the input from STDIN
for line in sys.stdin:

    # Get the MapData from the input
    gameData = line.split('#')

    # Loop through each bot
    for nextBot in gameData[1].split(','):

        botData = nextBot.split('-')

        # If it's our own bot, then select a random direction
        if(botData[0] == 'F'):
            actions.append(botData[1] + '-M-' + rdm.choice(directions))

# Return to STDOUT
print(','.join(actions))
❤️ Feedback