philRG

Tron - dictionnaires récalcitrants :(

Apr 10th, 2021 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. import random
  2. import sys
  3. import math
  4.  
  5. WIDTH = 30
  6. HEIGHT = 20
  7.  
  8.  
  9. dirs = {'UP': (0, -1), 'RIGHT': (1, 0), 'DOWN': (0, 1), 'LEFT': (-1, 0)}
  10.  
  11. def idebug(*args):
  12.     # return
  13.     print(*args, file=sys.stderr)
  14.  
  15.  
  16. def debug(*args):
  17.     # return
  18.     print(*args, file=sys.stderr)
  19.  
  20. def get_moves(x, y):
  21.     moves = []
  22.     for move, (dx, dy) in dirs.items():
  23.         if (x + dx, y + dy) not in lights and 0 <= x + dx < WIDTH and 0 <= y + dy < HEIGHT:
  24.             moves.append(move)
  25.     debug(f'moves: {moves}')
  26.     return moves
  27.  
  28. cars = {}
  29. lights = []
  30. # game loop
  31. while True:
  32.     # n: total number of players (2 to 4).
  33.     # p: your player number (0 to 3).
  34.     n, p = [int(i) for i in input().split()]
  35.     idebug(n, p)
  36.     for i in range(n):
  37.         # x0: starting X coordinate of lightcycle (or -1)
  38.         # y0: starting Y coordinate of lightcycle (or -1)
  39.         # x1: starting X coordinate of lightcycle (can be the same as X0 if you play before this player)
  40.         # y1: starting Y coordinate of lightcycle (can be the same as Y0 if you play before this player)
  41.         x0, y0, x1, y1 = [int(j) for j in input().split()]
  42.         idebug(x0, y0, x1, y1)
  43.         if cars.get(i):
  44.             cars.get(i).append((x1, y1))
  45.         else:
  46.             cars[i] = [(x1, y1)]
  47.    
  48.     debug(f'cars: {cars}')
  49.  
  50.     lights = []
  51.     for c in cars.values():
  52.         lights += c
  53.     lights = set(lights)
  54.     debug(f'lights: {lights}')
  55.     debug(f'cars: {cars}')
  56.     my_car = cars[0]
  57.     debug(f'my car: {my_car}')
  58.     my_pos = my_car.pop()
  59.     debug(f'my_pos: {my_pos}')
  60.     move = random.choice(get_moves(*my_pos))
  61.  
  62.     # A single line with UP, DOWN, LEFT or RIGHT
  63.     print(move)
  64.  
Add Comment
Please, Sign In to add comment