philRG

starter PacMan (CG Spring Challenge 2020) avec numpy

Mar 3rd, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.11 KB | None | 0 0
  1. import sys
  2. import math
  3. import numpy
  4.  
  5. PAC_TYPE = ['ROCK', 'PAPER', 'SCISSORS']  # [0, 1, 2]
  6. WIN_TABLE = {0: 2, 2: 1, 1: 0}  # {"ROCK": "SCISSORS", "SCISSORS": "PAPER", "PAPER": "ROCK"}
  7.  
  8. def debug(*args):
  9.     print(*args, file=sys.stderr)
  10.  
  11.  
  12. class Game:
  13.     def __init__(self):
  14.         self.walls_array = numpy.zeros(shape=(WIDTH, HEIGHT), dtype=numpy.int)
  15.         self.pacs = numpy.zeros(shape=(2, 5, 7), dtype=numpy.int)  # [team_id, [pac_id, [x, y, type_id, speed_turns_left, ability_cooldown, visible, is_dead]]]
  16.         self.pellets = numpy.zeros(shape=(WIDTH, HEIGHT), dtype=numpy.int)  # value
  17.         self.pacs_per_player = 0
  18.  
  19.     def __repr__(self):
  20.         # return f'GRID ({WIDTH},{HEIGHT}):\n{self.walls_array.T}\nPACS:\n{self.pacs}\nPELLETS:\n{self.pellets.T}\nPACS_COUNT: {self.pacs_per_player}'
  21.         return f'PELLETS:\n{self.pellets.T}'
  22.  
  23.     def update(self):
  24.         if self.pacs_per_player:
  25.             self.pacs[0, :, 5] = 0  # set not visible for enemy pacs (team_id = 0)
  26.         my_score, opponent_score = [int(i) for i in input().split()]
  27.         debug(my_score, opponent_score)
  28.         visible_pac_count = int(input())  # all your pacs and enemy pacs in sight
  29.         debug(visible_pac_count)
  30.         for i in range(visible_pac_count):
  31.             inputs = input().split()
  32.             debug(*inputs)
  33.             pac_id = int(inputs[0])  # pac number (unique within a team)
  34.             team_id = int(inputs[1])  # 1 if this pac is yours
  35.             x = int(inputs[2])  # position in the grid
  36.             y = int(inputs[3])  # position in the grid
  37.             type_id = PAC_TYPE.index(inputs[4])  # unused in wood leagues
  38.             speed_turns_left = int(inputs[5])  # unused in wood leagues
  39.             ability_cooldown = int(inputs[6])  # unused in wood leagues
  40.             self.pacs[team_id, pac_id] = numpy.array([x, y, type_id, speed_turns_left, ability_cooldown, 1, 1])  # visible, alive
  41.  
  42.         # Initialisation du nombre de pacs
  43.         if not self.pacs_per_player:
  44.             self.pacs_per_player = len(game.pacs[1])
  45.             self.pacs.resize((2, self.pacs_per_player, 7))
  46.  
  47.         visible_pellet_count = int(input())  # all pellets in sight
  48.         debug(visible_pellet_count)
  49.         for i in range(visible_pellet_count):
  50.             # value: amount of points this pellet is worth
  51.             x, y, value = [int(j) for j in input().split()]
  52.             self.pellets[x, y] = value
  53.             debug(x, y, value)
  54.  
  55.     def is_wall(self, x, y):
  56.         return self.walls_array[x, y] != 0
  57.  
  58.     def set_wall(self, x, y):
  59.         self.walls_array[x, y] = 1
  60.  
  61. # Grab the pellets as fast as you can!
  62.  
  63. # width: size of the grid
  64. # height: top left corner is (x=0, y=0)
  65. WIDTH, HEIGHT = [int(i) for i in input().split()]
  66. debug(WIDTH, HEIGHT)
  67.  
  68. game = Game()
  69.  
  70. for i in range(HEIGHT):
  71.     row = input()  # one line of the grid: space " " is floor, pound "#" is wall
  72.     debug(row)
  73.     for j, c in enumerate(row):
  74.         if c == "#":
  75.             game.set_wall(j, i)
  76.  
  77. # game loop
  78. while True:
  79.     game.update()
  80.  
  81.     debug(game)
  82.     # MOVE <pacId> <x> <y>
  83.     print("MOVE 0 15 10")
  84.  
Add Comment
Please, Sign In to add comment