Exemple #1
0
    def _play_game(self):
        self._load_game(self._map)
        self._wait_for_map_load()

        Tower(self, config.HOTKEY_HERO,
              config.MAPS_POS_DARK_CASTLE_INTERSECTION_TOP, None, 'hero')

        logging.info('Starting game')
        self._start_game()

        logging.info("Waiting until round 4")
        self.wait_for(config.MAPS_ROUND_DARK_CASTLE_4)

        ninja = Tower(self, config.HOTKEY_TOWER_NINJA,
                      config.MAPS_POS_DARK_CASTLE_INTERSECTION_BOTTOM,
                      config.TOWER_NINJA_UPGRADE, 'ninja')
        ninja.upgrade(1, 1)
        ninja.upgrade(3, 1)
        ninja.upgrade(1, 3)

        logging.info("Waiting until round 20")
        self.wait_for(config.MAPS_ROUND_DARK_CASTLE_20)

        super_monkey = Tower(self, config.HOTKEY_TOWER_SUPER_MONKEY,
                             config.MAPS_POS_DARK_CASTLE_TOP_LEFT_MAIN_ROAD,
                             config.TOWER_SUPER_UPGRADE, 'super')
        super_monkey.upgrade(1, 2)
        super_monkey.upgrade(3, 2)

        self._wait_for_game_completion()
        self._game_completed()
    def place_randomly_in_range(self, board, x_min, x_max, y_min, y_max):
        tower = Tower(randrange(x_min, x_max), randrange(y_min, y_max))

        count = board._num_towers
        while not board.add_tower(tower):
            assert count == board._num_towers, "place along path False error"
            tower = Tower(randrange(0, board._width), randrange(0, board._height))
        assert count + 1 == board._num_towers, "place along path True error"
        return True
Exemple #3
0
 def test_intersects(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     creep = Creep(20, 50, game_state.world.ways[0], 2)
     tower = Tower(40, 50, 'laser')
     tower.level = 2
     self.assertEqual(game_state.intersects(tower, creep), True)
     tower = Tower(150, 300, 'freeze')
     self.assertEqual(game_state.intersects(tower, creep), False)
Exemple #4
0
 def __init__(self, num_disks):
     self.__num_of_disks = num_disks
     self.__num_of_moves = 0
     towA = Tower('A')
     for size in range(num_disks, 0, -1):
         disk = Disk(size)
         towA.append(disk)
     towB = Tower('B')
     towC = Tower('C')
     self.__towers = [towA, towB, towC]
def mainThread():
    
    table = Table()
    table.addpiece(1, 0, Pawn(1, 0, pawn_color, table.table_map))
    table.addpiece(1, 1, Pawn(1, 1, pawn_color, table.table_map))
    table.addpiece(1, 2, Pawn(1, 2, pawn_color, table.table_map))
    table.addpiece(1, 3, Pawn(1, 3, pawn_color, table.table_map))
    table.addpiece(1, 4, Pawn(1, 4, pawn_color, table.table_map))
    table.addpiece(1, 5, Pawn(1, 5, pawn_color, table.table_map))
    table.addpiece(1, 6, Pawn(1, 6, pawn_color, table.table_map))
    table.addpiece(1, 7, Pawn(1, 7, pawn_color, table.table_map))
    
    table.addpiece(0, 0, Tower(0, 0, tower_color, table.table_map))
    table.addpiece(0, 1, Horse(0, 1, horse_color, table.table_map))
    table.addpiece(0, 2, Bishop(0, 2, bishop_color, table.table_map))
    table.addpiece(0, 3, King(0, 3, king_color, table.table_map))
    table.addpiece(0, 4, Queen(0, 4, quin_color, table.table_map))
    table.addpiece(0, 5, Bishop(0, 5, bishop_color, table.table_map))
    table.addpiece(0, 6, Horse(0, 6, horse_color, table.table_map))
    table.addpiece(0, 7, Tower(0, 7, tower_color, table.table_map))
    
    
    table.addpiece(6, 0, Pawn(6, 0, pawn_color, table.table_map, True))
    table.addpiece(6, 1, Pawn(6, 1, pawn_color, table.table_map, True))
    table.addpiece(6, 2, Pawn(6, 2, pawn_color, table.table_map, True))
    table.addpiece(6, 3, Pawn(6, 3, pawn_color, table.table_map, True))
    table.addpiece(6, 4, Pawn(6, 4, pawn_color, table.table_map, True))
    table.addpiece(6, 5, Pawn(6, 5, pawn_color, table.table_map, True))
    table.addpiece(6, 6, Pawn(6, 6, pawn_color, table.table_map, True))
    table.addpiece(6, 7, Pawn(6, 7, pawn_color, table.table_map, True))
    
    table.addpiece(7, 0, Tower(7, 0, tower_color, table.table_map))
    table.addpiece(7, 1, Horse(7, 1, horse_color, table.table_map))
    table.addpiece(7, 2, Bishop(7, 2, bishop_color, table.table_map))
    table.addpiece(7, 3, King(7, 3, king_color, table.table_map))
    table.addpiece(7, 4, Queen(7, 4, quin_color, table.table_map))
    table.addpiece(7, 5, Bishop(7, 5, bishop_color, table.table_map))
    table.addpiece(7, 6, Horse(7, 6, horse_color, table.table_map))
    table.addpiece(7, 7, Tower(7, 7, tower_color, table.table_map))
    
    while True: 
        for evento in py.event.get():
            if evento.type == py.QUIT:
                py.quit()
                
        display.fill((255,255,255))
        table.render(display, py, font)
        py.display.flip()
        time.tick(64)
Exemple #6
0
def main():
    tower = Tower(join(dirname(__file__), 'tower.txt'))
    tower_example = Tower(join(dirname(__file__), 'example.txt'))

    print('Part 1')
    print('Bottom program: {}'.format(tower_example.get_bottom()))
    print('Solution to part 1: {}'.format(tower.get_bottom()))

    print()

    print('Part 2')
    solution = tower_example.weight_to_balance()
    print('Correct weight: {}'.format(solution))
    solution2 = tower.weight_to_balance()
    print('Solution to part 2: {}'.format(solution2))
def main():
    tower = Tower()
    initial_rod = "one"
    final_rod = "two"
    tower.initialise_tower(initial_rod)
    tower.print_tower()
    tower.solve(initial_rod, final_rod)
    def test_initialize_tower_with_three_rings(self):
        tower = Tower(3)

        pinOne = tower.pins[0]
        number_of_rings = len(pinOne.rings)

        self.assertEqual(number_of_rings, 3)
Exemple #9
0
def run_game():
    pygame.init()
    pygame.mixer.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.mixer.music.load('sounds/bg_music2.mp3')
    pygame.mixer.music.play()
    pygame.mixer.music.set_volume(0.5)
    pygame.display.set_caption("Perestroika")

    bracing = Bracing(screen)
    GlobalState()
    blocks = Group()
    tower = Tower()
    trucks = Group()
    record = None
    for r in Record.filter(user="******"):
        record = r
    if record is None:
        record = Record(user="******", score=0)
        record.save()
    GlobalState().record = record
    builder = Builder(screen)
    block = Block(bracing)
    block.make_static()
    button = Button(screen)
    while True:
        gf.check_events(bracing, blocks, tower, builder, block, trucks, button)
        builder.update()
        bracing.update()
        blocks.update(bracing)
        block.update(bracing)
        trucks.update()
        gf.update_screen(screen, bracing, blocks, builder, block, trucks, button)
        GlobalState().ticks += 1
Exemple #10
0
 def handle_mouse_events(self, mouse):
     for tower in self.world.towers:
         if tower.pressed(mouse) and self.world.current_tower_type == tower.type and not self.world.put_mine:
             if self.is_enough_money(self.world.upgrade_cost, self.gamer) and tower.can_be_upgraded():
                 self.gamer.money -= self.world.upgrade_cost
                 tower.upgrade()
             else:
                 pass
                 #printCostMessage()
     for cell in self.world.tower_places:
         if cell.pressed(mouse) and not self.world.put_mine:
             if self.is_enough_money(self.world.buy_cost, self.gamer):
                 self.gamer.money -= self.world.buy_cost
                 self.world.tower_places.remove(cell)
                 self.world.towers.append(Tower(cell.x, cell.y, self.world.current_tower_type))
             else:
                 pass
                 #printCostMessage()
     if self.world.put_mine:
         inter = False
         mine = Mine((mouse[0] // 32) * 32, (mouse[1] // 32) * 32)
         for tower in self.world.towers:
             if mine.intersects(tower):
                 inter = True
         for creep in self.world.creeps:
             if mine.intersects(creep):
                 inter = True
         for tow_pl in self.world.tower_places:
             if mine.intersects(tow_pl):
                 inter = True
         if not inter:
             if self.is_enough_money(20, self.gamer):
                 self.world.mines.append(mine)
                 self.gamer.money -= 20
             self.world.put_mine = False
Exemple #11
0
 def test_correct_deleting(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     cells = Unity.identifier(self.labyrinth)[0]
     way = deque(cells)
     pos = way[3]
     pos2 = way[2]
     game_state = GameState(perm_mock)
     creep2 = Creep(pos2[0], pos2[1], way, 1)
     creep = Creep(pos[0], pos[1], way, 1)
     game_state.world.creeps.append(creep)
     game_state.world.creeps.append(creep2)
     i = 0
     while i < 4:
         creep.way.popleft()
         if i < 3:
             creep2.way.popleft()
         i += 1
     game_state.world.creeps[0].health = 0
     tower = Tower(0, 32, 'laser')
     tower.is_blast = True
     tower.level = 2
     tower.attacked_creep = game_state.world.creeps[0]
     game_state.world.towers.append(tower)
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(len(game_state.world.creeps), 2)
 def test_tower_creation(self):
     new_tower = Tower(SoldiersGroup(Player('Blue')))
     print("done")
     self.assertTrue(
         new_tower.waiting_for_update is False
         and new_tower.update_time == 0 and new_tower.level == 1
         and new_tower.warriors_group == SoldiersGroup(Player('Blue')))
 def test_tower_being_attacked_with_insufficient_troops(self):
     soldiers = SoldiersGroup("Blue", 50)
     opponents = SoldiersGroup("Red", 70)
     tower = Tower(opponents)
     tower.attack(soldiers)
     self.assertTrue(tower.warriors_group == 20
                     and tower.warriors_group.team == opponents)
Exemple #14
0
 def test_stop_blast(self):
     tower = Tower(10, 20, 'laser')
     tower.attacked_creep = Creep(10, 20, [0, 0], 1)
     tower.is_blast = True
     tower.stop_blast()
     self.assertEqual(tower.is_blast, False)
     self.assertEqual(tower.attacked_creep, None)
    def test_remove_a_ring_from_the_pin_one_and_insert_into_pin_two(self):
        tower = Tower(3)

        tower.move_ring(1,2)
        pinTwo = tower.pins[1]
        number_of_rings = len(pinTwo.rings)

        self.assertEqual(number_of_rings, 1)
Exemple #16
0
 def test_blast(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     creep = Creep(50, 62, game_state.world.ways[0], 1)
     tower = Tower(50, 62, 'laser')
     game_state.blast(tower, creep)
     self.assertEqual(creep.health, 99)
Exemple #17
0
    def test_connect(self):
        tower = Tower(50, 57, 30, 1000)
        user = usr.User(1)
        tower.connect(user)

        self.assertEqual(tower.num_users(), 1)
        print(tower.users)
        self.assertTrue(tower.users[id])
Exemple #18
0
 def test_upgrade(self):
     tower = Tower(10, 20, 'freeze')
     self.assertEqual(tower.level, 1)
     self.assertEqual(tower.radius.size, 48)
     self.assertEqual(tower.damage, 1)
     tower.upgrade()
     self.assertEqual(tower.level, 2)
     self.assertEqual(tower.radius.size, 80)
     self.assertEqual(tower.damage, 2)
Exemple #19
0
 def addTower(self,x,y,ttype):
     gold = [50,100,500]
     if x < len(self.map.map) and y < len(self.map.map[0]) and self.map.map[y][x].isWall and self.isFree(x,y):
         g = gold[ttype-1]
         if self.player.gold >= g:
             self.player.getGold(-g)
             if ttype == 1:
                 # Arrow tower
                 #Tower(self,x,y,damage,trange,firerate,projSpeed,ttype):
                 newtower = Tower(x*self.squareSize,y*self.squareSize,10,200,10,20,1)
                 self.buttons[0].activated = False
             elif ttype == 2:
                 newtower = Tower(x*self.squareSize,y*self.squareSize,10,150,15,20,2)  
                 self.buttons[1].activated = False
             elif ttype == 3:
                 newtower = LaserTower(x*self.squareSize,y*self.squareSize,4,100,3)
                 self.buttons[2].activated = False
             self.towers.append(newtower)
Exemple #20
0
 def test_check_creeps(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     game_state.world.finish = [120, 150]
     creep = Creep(120, 150, game_state.world.ways[0], 2)
     tower = Tower(90, 90, 'laser')
     tower2 = Tower(50, 70, 'laser')
     tower2.attacked_creep = game_state.world.creeps[0]
     tower.attacked_creep = creep
     game_state.world.towers.append(tower)
     game_state.world.towers.append(tower2)
     game_state.world.creeps.append(creep)
     game_state.gamer.life = 10
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(game_state.gamer.life, 9)
     self.assertEqual(len(game_state.world.creeps), 1)
     self.assertEqual(game_state.world.towers[0].attacked_creep, None)
     self.assertNotEqual(game_state.world.towers[1].attacked_creep, None)
Exemple #21
0
 def add_tower(self):
     """ add a tower to the game """
     (ex, ey) = self.__MAP.get_entrance_coords(
     )  #STUB: add tower on entrance by default
     cell = self.__MAP.get_cell_from_grid((ex, ey))
     tower = Tower(self, (ex * self.__MAP.get_cell_width(),
                          ey * self.__MAP.get_cell_height()), cell)
     cell.add_tower(tower)
     self.__tower_list.append(tower)
     return
Exemple #22
0
 def test_stop_blast(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     tower = Tower(50, 62, 'laser')
     creep = Creep(50, 62, game_state.world.ways[0], 1)
     tower.attacked_creep = creep
     game_state.world.towers.append(tower)
     game_state.stop_blast(game_state.world.towers, creep)
     self.assertEqual(game_state.world.towers[0].is_blast, False)
     self.assertEqual(game_state.world.towers[0].attacked_creep, None)
Exemple #23
0
def map_sprites():

    global decorations
    decorations = pygame.sprite.Group()
    decorations.add(Pond(400, 325))
    decorations.add(Road_2(150, 0))
    decorations.add(Road_2(350, 0))
    decorations.add(Road_2(550, 0))
    decorations.add(Road_2(750, 0))
    decorations.add(Road(0, 75))
    decorations.add(Road(0, 375))
    decorations.add(Road(0, 675))
    decorations.add(Box(5, 5))
    decorations.add(Box(495, 20))
    decorations.add(Box(295, 320))
    decorations.add(Box(95, 130))
    decorations.add(Box(605, 320))
    decorations.add(Box(205, 620))
    decorations.add(Box(695, 430))
    decorations.add(Box(945, 620))
    decorations.add(Box(405, 730))
    decorations.add(Box(805, 745))
    decorations.add(Tower(0, 275))
    decorations.add(Tower(200, 125))
    decorations.add(Tower(950, 275))
    decorations.add(Tower(300, 575))
    decorations.add(Fan(700, 125))
    decorations.add(Fan(950, 125))
    decorations.add(Fan(0, 625))
    decorations.add(Fan(600, 625))
    decorations.add(Fan(300, 0))
    decorations.add(Fan(200, 750))
    decorations.add(Tree(400, 125))
    decorations.add(Tree(500, 625))
    decorations.add(Flower(405, 325))
    decorations.add(Flower(530, 325))
    decorations.add(Flower(465, 300))
    decorations.add(Flower(405, 460))
    decorations.add(Flower(530, 460))
    decorations.add(Flower(465, 480))
    decorations.add(Arrow(875, 25))
    def create_tower(self, x1, x2, y1, y2):
        """Create a tower instance for the solver

		Args:
		    x1 (int): x1 coordinate
		    x2 (int): x2 coordinate
		    y1 (int): y1 coordinate
		    y2 (int): y2 coordinate

		Returns:
		    Tower: A Tower instance
		"""
        # Argument checks are done by Tower.__init__
        return Tower(self, x1, x2, y1, y2)
Exemple #25
0
def enter():
    global soldier, space_world, soldier_bullet_team, tower, ship_bullet_team, alien_team

    space_world = Space_World()
    soldier = Soldier()
    tower = Tower()
    soldier_bullet_team = [Soldier_Bullet() for i in range(10)]
    ship_bullet_team = [Ship_Bullet() for i in range(30)]
    alien_team = [Alien() for i in range(30)]

    soldier.get_space(space_world)
    tower.get_space(space_world)

    for alien in alien_team:
        alien.get_tower(tower)
Exemple #26
0
 def newTower(self, row, col, towerButton):
     if towerButton == "Green":
         tower = GreenTower(row, col, self.board, self.cellDim)
         self.money -= tower.cost
     elif towerButton == "Red":
         tower = RedTower(row, col, self.board, self.cellDim)
         self.money -= tower.cost
     elif towerButton == "Orange":
         tower = OrangeTower(row, col, self.board, self.cellDim)
         self.money -= tower.cost
     elif towerButton == "Purple":
         tower = PurpleTower(row, col, self.board, self.cellDim)
         self.money -= tower.cost
     else:
         tower = Tower(row, col, self.board, self.cellDim)
     self.towers.towerList.append(tower)
Exemple #27
0
 def test_wave_is_over(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     game_state.world.creeps[0].rect = (20, 20, 50, 100)
     game_state.world.finish = [20, 20]
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(game_state.wave_is_over(game_state.world), True)
     creep = Creep(20, 50, game_state.world.ways[0], 2)
     tower = Tower(30, 50, 'laser')
     tower.level = 2
     creep.health = 0
     game_state.world.creeps.append(creep)
     game_state.world.towers.append(tower)
     game_state.blast_and_kill(game_state.world.creeps[0], game_state.world,
                               game_state.gamer)
     self.assertEqual(game_state.wave_is_over(game_state.world), True)
    def read_input(self, input_file):
        inputs = open(input_file)
        self.points = int(inputs.readline())
        position = 0
        for line in inputs.readlines():
            informations = line.split(' ')
            tower = Tower()
            tower.name = informations.pop(0)
            tower.cost = float(informations.pop(0))
            tower.points = sorted([int(point) for point in informations if point.isdigit()])
            tower.position = position
            position += 1

            self.append_tower(tower)
        self.__towers = sorted(self.__towers, key=lambda tower: tower.cost)
        self.__generate_distances()
        self.__generate_pheromones()
 def place_along_path(self, board):
     if len(board._units) is 0:
         return False
     paths = list(filter(lambda x: x is not None, map(lambda u: board.path_from(int(u._x), int(u._y)), board._units)))
     paths.sort(key=lambda p: len(p))
     i = 0
     while i < len(paths) and len(paths[i][1:]) is 0:
         i += 1
     if i is len(paths):
         return False
     for cell in paths[i][1:]:
         count = board._num_towers
         if not board.add_tower(Tower(cell[0], cell[1])):
             assert count == board._num_towers, "place along path False error"
             continue
         assert count + 1 == board._num_towers, "place along path True error"
         return True
     return False
Exemple #30
0
    def __init__(self, shared, L, sigma_i, sigma_f, sigma_n, device):
        super(GQN, self).__init__()

        self.shared = shared
        self.L = L
        self.tower = Tower()
        self.sigma_i = sigma_i
        self.sigma_f = sigma_f
        self.sigma_n = sigma_n
        self.device = device

        if shared:
            self.inference = Inference()
            self.generation = Generator()
        else:
            self.inference = nn.ModuleList([Inference() for _ in range(L)])
            self.generation = nn.ModuleList([Generator() for _ in range(L)])

        self.prior_net = Latent(256, 256, 5)
        self.posterior_net = Latent(256, 256, 5)
        self.img_reconstructor = ImageReconstruction(256, 3, 5, device)