def run(): n = 4 width, height = 6, 6 model_file = os.path.join(results_dir, "zero_17_4_15:36", "policy_1450.model") try: board = Board(width=width, height=height, n_in_row=n) game = Game(board) # ############### human VS AI ################### # load the trained policy_value_net in either Theano/Lasagne, PyTorch or TensorFlow best_policy = PolicyValueNet(width, height, model_file=model_file) mcts_player = MCTSPlayer(best_policy.policy_value_fn, c_puct=5, n_playout=400) # uncomment the following line to play with pure MCTS (it's much weaker even with a larger n_playout) # mcts_player = MCTS_Pure(c_puct=5, n_playout=1000) # human player, input your move in the format: 2 3 human = Human() # set start_player=0 for human first game.start_play(human, mcts_player, start_player=1, is_shown=1) except KeyboardInterrupt: print('\n\rquit')
def main(): game = Game() while game.running: game.run() game.quit()
def test_input_within_range(self): ''' Test if input is within 1 to 3 ''' game = Game() self.assertTrue(game.is_input_within_range(1, 3)) self.assertFalse(game.is_input_within_range(0, 3)) self.assertFalse(game.is_input_within_range(-3, 1000))
def setUp(self): self.player1 = Player('Evie') self.player2 = Player('Amelia') self.pg = Game() self.pg.add_player(self.player1) self.pg.add_player(self.player2) self.pg.setup_game(SETTINGS_LOCATION)
def test_game_failure_if_straight_continous_blocks(self): board = TicTacBoard(3) game = Game(board, Difficult_level.MEDIUM) board.place_position((0, 0), "O") board.place_position((0, 1), "X") board.place_position((0, 2), "O") self.assertEqual(game.is_completed_with_win(board.grid), DRAW)
def __init__(self): super().__init__() # Determine what controller type should be used num_args = len(sys.argv) self.control_type = "keyboard" if num_args > 1: self.control_type = sys.argv[1].lower() # Init control input if self.control_type == "controller": # Init pygame controller input print("Initiated controller") pygame.joystick.init() self.joystick = pygame.joystick.Joystick(0) self.joystick.init() pygame.init() elif self.control_type == "keyboard": pass else: print("INVALID CONTROL TYPE") return # Init game self.game = Game() self.canvas.add(self.game)
def test_game_over_if_reverse_diagnol_continous_block(self): board = TicTacBoard(3) game = Game(board, Difficult_level.MEDIUM) board.place_position((1, 1), "X") board.place_position((0, 2), "X") board.place_position((2, 0), "X") self.assertEqual(game.is_completed_with_win(board.grid), X_WINS)
class TestDataBase(unittest.TestCase): def setUp(self): self.data = loadDatabase("tests/sampleData") self.player1 = Player("Herbert") self.player2 = Player("Toni") self.game = Game(self.data) self.date = datetime.datetime(2020, 2, 25, 22, 22, 22) def testPunchInWrongPlayer(self): try: self.game.punchIn(self.player1, self.date) except PlayerNotFoundError: pass else: assert False def testPunchInCorrectPlayer(self): self.game.punchIn(self.player2, self.date) def testPunchInCorrectDate(self): self.game.punchIn(self.player2, self.date) date_entered = self.game.data[self.player2.name][-1] assert date_entered == self.date def testPunchInTwice(self): self.game.punchIn(self.player2, self.date) self.game.punchIn(self.player2, datetime.datetime(2020, 2, 25, 21, 20, 20)) assert len([tempdate for tempdate in self.game.data[self.player2.name] if tempdate.date() == self.date.date()]) == 1
class TestDetermineNextPlayer: @pytest.fixture(autouse=True) def setUp(self, mocker): mocker.patch('src.game.Game._get_initial_seeds', lambda x: 3) self.game = Game(player1=RandomPlayer('Player1'), player2=RandomPlayer('Player2')) self.board = self.game.board self._player_cups = { self.game.player1: self.board.player_1_cup_index, self.game.player2: self.board.player_2_cup_index, } @pytest.mark.parametrize('current_player_index,last_cup', [(0, 5), (1, 5)]) def test_no_extra_turn(self, current_player_index, last_cup): player = self.game._players[current_player_index] self.game.current_player = player self.game._determine_next_player(last_cup) assert self.game.current_player != player @pytest.mark.parametrize('current_player_index', [0, 1]) def test_extra_turn(self, current_player_index): player = self.game._players[current_player_index] self.game.current_player = player last_cup = self._player_cups[player] self.game._determine_next_player(last_cup) assert self.game.current_player == player
def main(): run = True clock = pygame.time.Clock() game = Game(WIN) SPAWNPIPE = pygame.USEREVENT pygame.time.set_timer(SPAWNPIPE, 1200) BIRDFLAP = pygame.USEREVENT + 1 pygame.time.set_timer(BIRDFLAP, 200) while run: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE and game.ACTIVE == True: Bird.BIRD_MOVE = 0 Bird.BIRD_MOVE -= 5 FLAP_SOUND.play() if event.key == pygame.K_SPACE and game.ACTIVE == False: game.reset() if event.type == SPAWNPIPE: game.create_pipe() if event.type == BIRDFLAP: game.bird_animation() game.update() pygame.quit()
def main(): pygame.init() display = pygame.display.set_mode((Config.game.width, Config.game.height)) pygame.display.set_caption(Config.game.caption) game = Game(display) game.loop()
def __init__(self, size: int = 10, parent: Optional[QWidget] = None, *args, **kwargs) -> None: super(Canvas, self).__init__(*args, **kwargs) self._qp = QPainter() self._timer = QTimer() self._timer.timeout.connect(self.redraw) self._colors = { 0: { 'cells': QColor('green'), 'background': QColor('white'), 'grid': QColor('black') }, 1: { 'cells': QColor('black'), 'background': QColor('white'), 'grid': QColor('black') }} self.next_generation_signal = GenerationUpdateSignal() self.game = Game() self.size = size self._color_scheme = self._colors[0] self._grid = [] self._rects = []
class SinglePlayer: def __init__(self): self.screen = pygame.display.set_mode( (Settings.single_screen_width, Settings.screen_height)) self.menu_button = Button( self.screen, (Settings.single_screen_width - Settings.button_width) // 2, Settings.screen_height * 0.9, 'BACK TO MENU') self.game = Game(self.screen, 0, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN, pygame.K_SPACE) def run(self): while True: for event in pygame.event.get().copy(): self.game.check_event(event) if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() if self.menu_button.rect.collidepoint(mouse): return 'menu' self.screen.blit(Settings.bg_image, (0, 0)) self.menu_button.show() self.game.refresh() pygame.display.flip()
def prepare_game(cards, players=None): if players is None: players = ["tom", "julian"] game = Game(TestChannel(), players, cards) running_game = game.game_runner() running_game.send(None) return game, running_game
def main(): display = pygame.display.set_mode( (Config['game']['width'], Config['game']['height'])) pygame.display.set_caption(Config['game']['caption']) game = Game(display) game.loop()
class GameScreen: def __init__(self): self.game = Game(0, 0) def draw(self, window): window.fill((255, 255, 255)) self.game.draw(window) def update(self, events): self.game.update(events) @staticmethod def screen_loop(window, highscore_handler): global SCORE screen = GameScreen() while True: events = pg.event.get() for event in events: if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE): option = PausePopup.popup_loop(window) if option != States.RETURN: return option if screen.game.lost(): screen.game.snake.move() SCORE = screen.game.score highscore_handler.add_highscore(SCORE) return RetryPopup.popup_loop(window) screen.update(events) screen.draw(window) pg.display.update()
def test_handle_input_exception(self): self.config['game']['levels'] = 3 game = Game(self.config, []) game.hero.x = 5 game.hero.y = 5 game.level.tiles[4][5].set_type('floor') game.player = GameInputController(game) self.assertEqual(None, game.handle_input(None))
def play_move(self, game_state, statcache): """Play a move in game.""" first_moving = Game.player_with_priority(game_state) == 0 move = self.get_play(statcache) old_gs = game_state game_state = Game.apply_move(game_state, move) statcache.past_states.append(game_state) return move, game_state
def setUp(self): table = Table(200) self.player = MartingalePlayer(table) self.player.stake = 100 wheel = Wheel(NonRandom()) # bin_builder = BinBuilder() # bin_builder.build_bins(wheel) self.game = Game(wheel, table)
def test_initMap(self): game = Game() map = game.setGrid(10) self.assertEqual(10, len(map)) for row in map: self.assertEqual(10, len(row)) for cel in row: self.assertEqual(0, cel)
def main(): game = Game(scale=2) while game.running: game.on_event() game.on_update() game.on_render() game.close()
def main(): game = Game({ "cellSize" : 30 , "boardWidth" : 30 , "boardHeight" : 20 , "speed" : 2 , "snakeLength" : 4 }) game.run()
def main(): start = (0, 1) goal = (2, 3) game = Game(5, start=start, goal=goal, action_cost=-1) val_func = game.calculate_value_function() visualize_val_function(val_func) visualize_reward_shaping(val_func) visualize_optimal_policy(val_func)
def main(): menu = Menu() menu.run() if not menu.config.start_game: exit(0) game = Game(config=menu.config) new_game = game.run() if new_game: main()
def build(self): global game #FIXME: THIS IS MOST CERTAINLY NOT THE WAY TO DO IT, BUT HOW ELSE ?!?!? game = Game() self.config = MainConfig() Config.set('graphics', 'width', self.config.windowWidth) #this has to be done before calling super() Config.set('graphics', 'height', self.config.windowHeight) self.screen = Screen(game=game) game.screen = self.screen return self.screen
def test_get_player(self): # Resetting game pieces Player._game_pieces = ['battleship', 'dog', 'iron', 'shoe', 'thimble', 'top hat', 'wheelbarrow'] self.game = Game(3) self.game.players[0].game_piece = 'test' player = self.game.get_player('test') self.assertEqual(player.game_piece, 'test', 'Game Piece should be test')
def main(): pygame.init() pygame.font.init() width = 1000 height = 800 game = Game(width, height) game.run()
def test_dealers_2nd_card_is_hidden(self): from src.game import Game testGame = Game() testGame.new_run() dealerHand = testGame.dealer.hand1 card2Status = dealerHand.hand[1].is_hidden() self.assertTrue(card2Status)
def load_level(self): game = Game( maze=self.maze, screen=self.screen, sounds_active=self.act_sound, state_active=self.act_state, agent=self.ai_agent ) game.start_game()
def test_game_play(size, expected): """ Game ends when player has 0, 1, or 1000 or over chips. """ game = Game() game.get_player().get_purse().set_size(size) actual = game.play() assert actual == expected
def setUp(self, mocker): mocker.patch('src.game.Game._get_initial_seeds', lambda x: 3) self.game = Game(player1=RandomPlayer('Player1'), player2=RandomPlayer('Player2')) self.board = self.game.board self._player_cups = { self.game.player1: self.board.player_1_cup_index, self.game.player2: self.board.player_2_cup_index, }
def test_get_rba_array(): maze = Map('classic') g = Game(maze=maze, screen=pg.display.set_mode(maze.get_map_sizes()), sounds_active=False, state_active=False) arr = g.get_rba_array() assert type(arr) is np.ndarray assert arr.shape == (456, 552, 3)
class IntegrationTest(unittest.TestCase): app = None TestUserName = "******" @classmethod def setUpClass(cls): global app app = QtGui.QApplication([]) def setUp(self): self.db = Database() self.db.createUser("testUserRealName", IntegrationTest.TestUserName, "testUserPassword0$") self.game = Game() self.game.username = IntegrationTest.TestUserName self.game.loginWidget.loggedUsername = IntegrationTest.TestUserName self.game.showBoard(1) def tearDown(self): self.db.deleteAccount(IntegrationTest.TestUserName) self.game.board_widget.stopTimers() self.game.board_widget.statusBar.destroy() self.game.board_widget.exit() self.game.board_widget.destroy() self.game.destroy() @classmethod def tearDownClass(cls): app.quit() def testKillEnemiesOnBoardUpdateDb(self): self.assertTrue(self.db.hasUser(IntegrationTest.TestUserName)) self.game.board_widget.level.clearEnemies() self.game.board_widget.setTileAt(2, 1, Tile.Balloom) self.game.board_widget.level.bomberman.curX = 1 self.game.board_widget.level.bomberman.curY = 1 self.game.board_widget.level.setBomberman() self.game.board_widget.level.setBomb() tempList = [2, 1, constant.DIRECTION_WEST, Tile.Balloom] self.game.board_widget.level.listEnemies.append(tempList) self.game.board_widget.level.numberEnemies = 1 self.game.board_widget.level.listTypeEnemies[0] = 1 self.game.board_widget.level.bomberman.rangeOfBombs = 3 self.game.board_widget.detonateBomb() self.assertEqual(self.game.board_widget.tileAt(2, 1), Tile.Empty, "Bomb detonation did not kill enemy") self.assertEqual(0, self.game.board_widget.level.numberEnemies, "Enemy was not removed from map") self.assertEqual(self.db.getUserAccount(IntegrationTest.TestUserName)['cumulativeScore'], 100)
class TestGameUi(unittest.TestCase): def setUp(self): self.ui = UiMock() self.game = Game(self.ui, SETTINGS) def testGamePromptsWelcome(self): self.game.start_game() self.assertEqual(True, self.game.ui.prompted_welcome) def testGamePromptsGoodBye(self): self.game.end_game() self.assertEqual(True, self.game.ui.prompted_good_bye) def testGamePromptsForMove(self): self.game.make_move() self.assertEqual(True, self.game.ui.prompted_user_for_move) def testGamePrintsBoard(self): self.game.make_move() self.assertEqual(True, self.game.ui.prompted_board)
def setUp(self): self.db = Database() self.db.createUser("testUserRealName", IntegrationTest.TestUserName, "testUserPassword0$") self.game = Game() self.game.username = IntegrationTest.TestUserName self.game.loginWidget.loggedUsername = IntegrationTest.TestUserName self.game.showBoard(1)
class TestGameplay(unittest.TestCase): app = None @classmethod def setUpClass(cls): global app app = QtGui.QApplication([]) def setUp(self): self.game = Game() self.level = Level("testUser", 1) self.board = Board(self.level, self.game) self.clearBricks() self.board.start() def tearDown(self): self.board.destroy() self.game.destroy() @classmethod def tearDownClass(cls): app.quit() def testInitializeBoardWithConcreteWalls(self): self.assertEqual(self.board.level.board[0][0].peek(), Tile.Concrete, "Corner tile should be Concrete, board not initialized properly") def testInitializeBoardWithExactlyOneBomberman(self): numberOfBombermanOnTheBoard = 0 board = self.board.level.board for i in range(len(board)): for j in range(len(board[i])): if board[i][j].peek() == Tile.Bomberman: numberOfBombermanOnTheBoard += 1 self.assertEqual(numberOfBombermanOnTheBoard, 1, "Did not see exactly one level on the board") def testSetTileAt(self): self.assertEqual(self.board.level.board[1][1].peek(), Tile.Empty) self.board.setTileAt(1, 1, Tile.Brick) self.assertEqual(self.board.level.board[1][1].peek(), Tile.Brick) def testTileAt(self): for i in range(len(self.board.level.board)): for j in range(len(self.board.level.board[i])): self.assertEqual(self.board.tileAt(j, i), self.board.level.board[i][j].peek()) def testSetBomberman(self): self.assertNotEqual(self.board.tileAt(1, 2), Tile.Bomberman) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 2 self.board.level.setBomberman() self.assertEqual(self.board.tileAt(1, 2), Tile.Bomberman) def testSetBomb(self): self.assertNotEqual(self.board.tileAt(1, 2), Tile.Bomb) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 2 self.board.level.setBomberman() #level should be here already self.board.level.setBomb() self.assertEqual(len(self.board.level.bombQueue), 1, "Bomb did not get enqueued") self.assertEqual(self.board.level.bombQueue.pop(), (1, 2, constant.TIME_BOMB), "Bomb's coordinates are wrong") self.assertEqual(self.board.tileAt(1, 2), Tile.Bomberman, "Bomberman is not on top of a bomb") self.board.popTileAt(1, 2) self.assertEqual(self.board.tileAt(1, 2), Tile.Bomb, "There is no bomb underneath Bomberman") def testDetonateBomb(self): self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.detonateBomb() self.board.popTileAt(1, 1) #pop Bomberman self.assertNotEqual(self.board.tileAt(1, 1), Tile.Bomb, "Bomb did not explode") def testDetonateBombHasNoEffectOnConcrete(self): self.board.curX = 1 self.board.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.detonateBomb() self.board.popTileAt(1, 1) #pop Bomberman self.assertEqual(self.board.tileAt(1, 0), Tile.Concrete, "Concrete got destroyed by bomb") def testDetonateBombDestroysBrick(self): self.board.setTileAt(1, 2, Tile.Brick) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.level.bomberman.rangeOfBombs = 3 self.board.detonateBomb() self.assertEqual(self.board.tileAt(1, 2), Tile.Empty, "Brick did not get destroyed by bomb") def testDetonateBombDestroysOnlyClosestBrickInTheSameDirection(self): self.board.setTileAt(1, 2, Tile.Brick) self.board.setTileAt(1, 3, Tile.Brick) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.level.bomberman.rangeOfBombs = 3 self.board.detonateBomb() self.assertEqual(self.board.tileAt(1, 2), Tile.Empty, "Closer Brick did not get destroyed by bomb") self.assertEqual(self.board.tileAt(1, 3), Tile.Brick, "Further Brick got destroyed by bomb") def testDetonateBombDestroysMultipleBricks(self): self.board.setTileAt(1, 2, Tile.Brick) self.board.setTileAt(2, 1, Tile.Brick) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.level.bomberman.rangeOfBombs = 3 self.board.detonateBomb() self.assertEqual(self.board.tileAt(1, 2), Tile.Empty, "One of the Bricks did not get destroyed by bomb") self.assertEqual(self.board.tileAt(2, 1), Tile.Empty, "One of the Bricks did not get destroyed by bomb") def testDetonateBombKillsEnemies(self): self.level.clearEnemies() self.board.setTileAt(2, 1, Tile.Balloom) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() tempList = [2, 1, constant.DIRECTION_WEST, Tile.Balloom] self.level.listEnemies.append(tempList) self.level.numberEnemies = 1 self.level.listTypeEnemies[0] = 1 self.board.level.bomberman.rangeOfBombs = 3 self.board.tryMove(1, 2) self.board.detonateBomb() self.assertEqual(self.board.tileAt(2, 1), Tile.Empty, "Bomb detonation did not kill enemy") self.assertEqual(0, self.level.numberEnemies, "Enemy was not removed from map") def testDetonateBombSpawnsEnemiesWhenExitIsHit(self): self.board.setTileAt(1, 2, Tile.Exit) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.level.bomberman.rangeOfBombs = 3 self.board.detonateBomb() count = 0 for i in range(self.level.numberEnemies): if (self.level.listTypeEnemies[i] != 0): count += 1 self.assertEqual(count, 1, "Not all enemies are the same type when the exit is hit") self.assertEqual(len(self.level.listEnemies), 8, "The number of enemies when the exit is hit is not 8") def testDetonateBombSpawnsEnemiesWhenPowerupIsHit(self): self.board.setTileAt(1, 2, Tile.Powerup) self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.level.bomberman.rangeOfBombs = 3 self.board.detonateBomb() count = 0 for i in range(self.level.numberEnemies): if (self.level.listTypeEnemies[i] != 0): count += 1 self.assertEqual(count, 1, "Not all enemies are the same type when the powerup is hit") self.assertEqual(len(self.level.listEnemies), 8, "The number of enemies when the powerup is hit is not 8") def testTimeRunsOut(self): self.level.timeLeft = 0 self.level.timeDone = False self.board.timeoutEvent() check = False for i in range(7): if (self.level.listTypeEnemies[i] != 0): check = True self.assertEqual(self.level.numberEnemies, 8, "Number of enemies is not equal to 8") self.assertFalse(check, "At least one enemy is not a Pontan") def testTryMoveToConcrete(self): self.board.setTileAt(0, 0, Tile.Concrete) self.assertFalse(self.board.tryMove(0, 0), "Was able to move to a concrete tile") def testTryMoveToBrick(self): self.board.setTileAt(1, 1, Tile.Brick) self.assertFalse(self.board.tryMove(1, 1), "Was able to move to a brick tile") def testTryMoveToBrick(self): self.board.setTileAt(2, 2, Tile.Empty) self.assertTrue(self.board.tryMove(2, 2), "Was not able to move to an empty tile") def testMoveEnemyWithIntelligence1(self): self.level.clearEnemies() self.board.setTileAt(2, 1, Tile.Balloom) self.board.setTileAt(1, 1, Tile.Empty) tempList = [2, 1, constant.DIRECTION_WEST, Tile.Balloom] self.level.listEnemies.append(tempList) self.level.numberEnemies = 1 self.level.listTypeEnemies[0] = 1 self.board.moveEnemy(constant.SPEED_SLOW) self.assertEqual(self.board.tileAt(1, 1), Tile.Balloom, "Enemy did not move") def testMoveEnemyWithIntelligence2(self): self.level.clearEnemies() self.board.setTileAt(2, 1, Tile.Oneal) self.board.setTileAt(1, 1, Tile.Empty) self.board.setTileAt(3, 1, Tile.Empty) self.board.setTileAt(2, 0, Tile.Empty) self.board.setTileAt(2, 2, Tile.Empty) tempList = [2, 1, constant.DIRECTION_WEST, Tile.Oneal] self.level.listEnemies.append(tempList) self.level.numberEnemies = 1 self.level.listTypeEnemies[0] = 1 self.board.moveEnemy(constant.SPEED_NORMAL) check = False if (self.board.tileAt(1, 1) == Tile.Oneal or self.board.tileAt(3, 1) == Tile.Oneal or self.board.tileAt(2, 0) == Tile.Oneal or self.board.tileAt(2, 2) == Tile.Oneal): check = True self.assertTrue(check, "Enemy did not move") def testMoveEnemyWithIntelligence3(self): self.level.clearEnemies() self.board.setTileAt(2, 1, Tile.Kondoria) self.board.setTileAt(1, 1, Tile.Empty) self.board.setTileAt(3, 1, Tile.Empty) self.board.setTileAt(2, 0, Tile.Empty) self.board.setTileAt(2, 2, Tile.Empty) tempList = [2, 1, constant.DIRECTION_WEST, Tile.Kondoria] self.level.listEnemies.append(tempList) self.level.numberEnemies = 1 self.level.listTypeEnemies[0] = 1 self.board.moveEnemy(constant.SPEED_SLOWEST) check = False if (self.board.tileAt(1, 1) == Tile.Kondoria or self.board.tileAt(3, 1) == Tile.Kondoria or self.board.tileAt(2, 0) == Tile.Kondoria or self.board.tileAt(2, 2) == Tile.Kondoria): check = True self.assertTrue(check, "Enemy did not move") def testDetonateBombKillsBomberman(self): self.level.lives = 3 self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.level.setBomb() self.board.tryMove(1, 2) self.board.detonateBomb() self.assertEqual(2, self.level.bomberman.lives, "Bomberman did not lose a life when hit by a bomb") def testDeathWhenEnemyMovesToBomberman(self): self.level.lives = 3 self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.level.clearEnemies() self.board.setTileAt(2, 1, Tile.Balloom) self.level.numberEnemies = 1 tempList = [2, 1, constant.DIRECTION_WEST, Tile.Balloom] self.level.listEnemies.append(tempList) self.level.listTypeEnemies[0] = 1 self.board.moveEnemy(constant.SPEED_SLOW) self.assertEqual(2, self.level.bomberman.lives, "Bomberman did not lose a life when an enemy moves into him") def testDeathWhenBombermanMovesToEnemy(self): self.level.lives = 3 self.board.level.bomberman.curX = 1 self.board.level.bomberman.curY = 1 self.board.level.setBomberman() self.board.setTileAt(1, 2, Tile.Balloom) self.board.tryMove(1, 2) self.assertEqual(2, self.level.bomberman.lives, "Bomberman did not lose a life when he moves into an enemy") def testGetScoreOfKilledEnemies(self): # No enemies: enemies = [[], [], []] self.assertEquals(self.board.getScoreOfKilledEnemies(enemies), 0) # 1 enemy at distance 1, with bomb range 1 enemies = [[Tile.Balloom]] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points']) # 1 enemy at distance 1, with bomb range >1 enemies = [[Tile.Balloom], [], []] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points']) # 1 enemy at distance >1 enemies = [[], [Tile.Balloom], []] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points']) # 2 enemies at different distance enemies = [[Tile.Balloom], [], [Tile.Doll]] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'] + 2*Enemy.getEnemy(Tile.Doll)['points']) # 2 enemies at same distance enemies = [[Tile.Doll, Tile.Balloom], [], []] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'] + 2*Enemy.getEnemy(Tile.Doll)['points']) # multiple enemies at multiple distances enemies = [[Tile.Doll, Tile.Balloom, Tile.Doll], [], [Tile.Ovapi, Tile.Ovapi], [Tile.Pontan]] self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'] + 2*Enemy.getEnemy(Tile.Doll)['points'] + 4*Enemy.getEnemy(Tile.Doll)['points'] + 8*Enemy.getEnemy(Tile.Ovapi)['points'] + 16*Enemy.getEnemy(Tile.Ovapi)['points'] + 32*Enemy.getEnemy(Tile.Pontan)['points']) def clearBricks(self): for x in range(constant.BOARD_WIDTH): for y in range(constant.BOARD_HEIGHT): if self.board.tileAt(x, y) == Tile.Brick: self.board.popTileAt(x, y)
def setUp(self): self.game = Game() self.level = Level("testUser", 1) self.board = Board(self.level, self.game) self.clearBricks() self.board.start()
def test_shoot_and_game_over(self): game = Game() game.shoot() self.assertTrue(game.is_game_over())
from src.game import Game g1 = Game() g1.mainloop()
def test_winner(self): game = Game() game.shoot() self.assertEqual(game.winner(), 1)
from src.game import Game from src.logger import Logger if __name__ == '__main__': language = "" game = Game(Logger()) while not game.set_language(language): language = input("Input language(ru, en) ") game.run()
def setUp(self): self.ui = UiMock() self.game = Game(self.ui, SETTINGS)
def setUp(self): self.game = Game()
def main(): print('Welcome to Ants!') game = Game() game.run()
from src.game import Game from src.console_io import ConsoleIo from src.game_engine import GameEngine from src.board_analyzer import BoardAnalyzer from src.negamax_ai import NegamaxAi io = ConsoleIo() ai = NegamaxAi() board_analyzer = BoardAnalyzer() engine = GameEngine(io, ai, board_analyzer) game = Game(io, engine) game.begin()
def on_menu_game(self): game = Game(self) game.win = self.win game.lose = self.lose self.context = game game.start()
from src.player import Player from src.game import Game game = Game() game.setUp() while game.hasWinner() is False: for player in game.players: player.turn(game) if game.hasWinner() is True: break
class TestGameSetters(unittest.TestCase): def setUp(self): self.game = Game() def test_increasing_cannon_angle(self): index = self.game.get_cannon_turn() angle = self.game.get_cannon_angle(index) self.game.increase_cannon_angle() self.assertEqual(self.game.get_cannon_angle(index), angle - 1) def test_decreasing_cannon_angle(self): index = self.game.get_cannon_turn() angle = self.game.get_cannon_angle(index) self.game.increase_cannon_angle() self.assertEqual(self.game.get_cannon_angle(index), angle - 1) def test_increasing_cannon_initial_speed(self): index = self.game.get_cannon_turn() speed = self.game.get_cannon_initial_speed(index) self.game.increase_cannon_initial_speed() self.assertEqual(self.game.get_cannon_initial_speed(index), speed + 1) def test_decreasing_cannon_initial_speed(self): index = self.game.get_cannon_turn() speed = self.game.get_cannon_initial_speed(index) self.game.decrease_cannon_initial_speed() self.assertEqual(self.game.get_cannon_initial_speed(index), speed - 1)
from src.game import Game g = Game() g.main_loop()
class TestGameGetters(unittest.TestCase): def setUp(self): self.game = Game() def test_window_width(self): self.assertEqual(self.game.get_window_width(), 1000) def test_window_height(self): self.assertEqual(self.game.get_window_height(), 768) def test_get_title(self): self.assertEqual(self.game.get_title(), 'Cannon wars') def test_get_logo(self): self.assertEqual(self.game.get_logo(), 'images/logo.png') def test_get_background_image(self): image_path = 'images/background_0.png' self.assertEqual(self.game.get_background_image(), image_path) def test_get_field_texture(self): image_path = 'images/grass1.jpg' self.assertEqual(self.game.get_field_texture(), image_path) def test_get_field_coordinates(self): field_coordinates = self.game.get_field_coordinates() true_coordinates = [(0, 768), (0, 400), (300, 400), (500, 150), (600, 380), (1000, 420), (1000, 768)] field_coordinates_as_tuples = [] for coordinate in field_coordinates: x = coordinate.get_horizontal_position() y = coordinate.get_vertical_position() field_coordinates_as_tuples.append((x, y)) self.assertEqual(field_coordinates_as_tuples, true_coordinates) def test_get_cannons_count(self): self.assertEqual(self.game.get_cannons_count(), 2) def test_get_cannons_turn(self): self.assertEqual(self.game.get_cannon_turn(), 0) def test_get_cannon_texture(self): index = 0 image_path = 'images/cannon0_' + str(index) + '.png' self.assertEqual(self.game.get_cannon_texture(index), image_path) def test_get_cannon_width(self): self.assertEqual(self.game.get_cannon_width(0), 150) def test_get_cannon_height(self): self.assertEqual(self.game.get_cannon_height(0), 92) def test_get_cannon_x(self): self.assertEqual(self.game.get_cannon_horizontal_position(0), 0) def test_get_cannon_y(self): self.assertEqual(self.game.get_cannon_vertical_position(1), 395) def test_get_cannon_angle(self): self.assertEqual(self.game.get_cannon_angle(1), 65) def test_get_projectile_image(self): image_path = 'images/projectile0.png' self.assertEqual(self.game.get_projectile_image(0), image_path) def test_projectile_trajectory(self): coordinates = self.game.get_projectile_trajectory() first_coordinate = [210., 330.] medium_coordinate = [548.09460939, 569.45122963] last_coordinate = [886.18921879, -172.09754074] self.assertAlmostEqual(list(coordinates[0]), first_coordinate, places=3) self.assertAlmostEqual(coordinates[int(len(coordinates) / 2)][0], medium_coordinate[0], places=3) self.assertAlmostEqual(coordinates[int(len(coordinates) / 2)][1], medium_coordinate[1], places=3) self.assertAlmostEqual(coordinates[-1][0], last_coordinate[0], places=3) self.assertAlmostEqual(coordinates[-1][1], last_coordinate[1], places=3)
__author__ = 'jkamuda' from src.game import Game if __name__ == "__main__": game = Game() game.run()
def start(): db = start_db() game = Game(db) game.start()