#!/usr/bin/env python3

# Zigzags leaving short dead-end "traps" that dumb bots will go down (this bot included)

from LightningBot import LightningBot
from random import randint, shuffle

bot = LightningBot(
  bot_name = 'Trapr' + '%04d' % randint(0, 9999),
)

move_direction = randint(0, 3)

# Cycle of turns to make
turn_path = [0, 0, 0, 1, 1, -1, 1, 0, 0, 0, 0, 0, -1, -1, 1, -1, 0, 0]

# Randomize where in the cycle to start
cycle_offset = randint(0, len(turn_path))

# Reverse the direction
if randint(0, 1) == 0:
  turn_path = [i * -1 for i in reversed(turn_path)]

# First move
bot.waitForNextTurn()
bot.move(move_direction)

while bot.waitForNextTurnDirections():

  # Turn direction is based on position in cycle
  turn_direction = turn_path[(bot.turn_number + cycle_offset) % len(turn_path)]
Exemplo n.º 2
0
#!/usr/bin/env python3

# Turn whichever way leads to the longest possible path, or go straight if there's a tie

from LightningBot import LightningBot
from random import randint

bot = LightningBot(bot_name='Depth' + '%04d' % randint(0, 9999), )

while bot.waitForNextTurnDirections():

    bot.move(bot.directionToLongestPath())
#!/usr/bin/env python3

# Move along a hilbert curve which fills the board

from LightningBot import LightningBot
from random import randint

bot = LightningBot(
  bot_name = 'Hilbert' + '%03d' % randint(0, 999),
)


# Return the direction to the next point in the hilbert curve
def directionToNextHilbertCurvePoint(game_size, position, direction):

  number_of_tiles = game_size * game_size

  # Find current position in hilbert curve
  for i in range(0, number_of_tiles):
    test_position = hilbertIndexToXY(i, game_size)
    if test_position[0] == position[0] and test_position[1] == position[1]:
      break

  next_point = hilbertIndexToXY( (i + direction) % number_of_tiles, game_size)

  # right
  if next_point[0] > position[0]:
    return 0
  # down
  if next_point[1] < position[1]:
    return 1
Exemplo n.º 4
0
#!/usr/bin/env python3

# Choose a random direction and move in that direction forever,
# but move one tile over when crossing the board so we don't hit our trail

from LightningBot import LightningBot
from random import randint

# Initialize bot and connect to a game
bot = LightningBot(

  # Unique bot name for test server
  bot_name = 'Basic' + '%04d' % randint(0, 9999),

  # Or token for ranked server, supplied as first command line argument
  #api_token = '00000000000000000000',

  # Disable the interactive output to run in the background or multiple bots in parallel in the same terminal
  #background_output = True,

)

# Choose a direction to start moving in
# 0: right, 1: down, 2: left, 3: up
move_direction = randint(0, 3)

# Wait until we have the directions for the next turn
while bot.waitForNextTurnDirections():

  # After crossing the board, avoid hitting self
  if bot.turn_number % bot.game_size == 0:
Exemplo n.º 5
0
#!/usr/bin/env python3

# Lose on the first turn by breaking the rules

from LightningBot import LightningBot
from random import randint

bot = LightningBot(bot_name='Loser' + '%05d' % randint(0, 99999), )

bot.move(-1)
#!/usr/bin/env python3

# Go straight but turn before crashing or if an opponent is moving in front of you

from LightningBot import LightningBot
from random import randint
from pprint import pprint

bot = LightningBot(bot_name='Swerve' + '%04d' % randint(0, 9999), )

move_direction = randint(0, 3)
#turn_preference = -1 if randint(0, 1) == 0 else 1
turn_preference = -1

while bot.waitForNextTurnDirections():

    last_position = bot.game_bots[bot.bot_name]['position'][:]
    original_move_direction = move_direction

    # If next position is blocked or randomly
    if bot.positionIsBlocked(bot.getNextPosition(
            last_position, move_direction)) or randint(0, 420) == 0:
        # Swerve
        move_direction = bot.rotateMoveDirection(original_move_direction,
                                                 turn_preference)

    # If swerved position is blocked
    if bot.positionIsBlocked(bot.getNextPosition(last_position,
                                                 move_direction)):
        # Swerve the other way!
        move_direction = bot.rotateMoveDirection(original_move_direction,