Exemplo n.º 1
0
    def get_rand_spawn_space(self):

        (x,y) = (0,0)
        new_tank = None
        new_pixels = None
        for i in range(100):
            should_break = True
            (x,y) = random.choice(self.available_spawn_locs)
            new_pixels = Tank.three_by_three((x,y))
            for t in self.tanks:
                if len(filter(lambda x: x in new_pixels, t.get_pixel_pos())) > 0:
                    should_break = False
                    break
            if should_break:
                break
        return (x,y)
Exemplo n.º 2
0
    def __init__(self, perma_board = []):
        """ if we want walls/hospital we give them in perma_board
            perma_board should be formatted as a 64x64 2D list of pixel values """

        # the set of things on the board which never change
        # currently includes HOSPITAL and WALL
        # formatted as a 64x64 2D list of pixel values
        self.perma_board = perma_board
        if len(self.perma_board) == 0:
            for i in range(64):
                self.perma_board += [[EMPTY]*64]

        # the set of locations on the board where tanks can spawn
        # excludes HOSPITAL and WALL and anything adjacent to either
        # formatted as a 64x64 2D list of pixel values
        self.available_spawn_locs = [space for space in np.nindex(64,64)]
        self.available_spawn_locs = filter(lambda x: true_for_each(lambda y: self.perma_board[y[0],y[1]] == EMPTY, Tank.three_by_three(x)), self.available_spawn_locs)

        # purely aesthetic features which never interact
        # includes EYE for instance
        # formatted as a 64x64 2D list of pixel values
        self.ghost_board = []
        for i in range(64):
            self.ghost_board += [[EMPTY]*64]

        self.scores          = {}
        self.load_colors()
        self.tanks           = {}
        self.board           = copy.deepcopy(self.perma_board)
        self.bullets         = []
        self.t_minus         = TURN_RATE
        self.last_time_stamp = time.time()
        self.fast_forward    = False

        self.pending_tank_ids = []

        self.scomm = ServerCommunicator()