def test_last_frame(self) -> None: """ Tenth frame combinations: xxx xx1 x2/ x22 2/x 2/2 """ frame = main.Frame() all_rolls = [ ([1, 2], 3), ([main.STRIKE, main.STRIKE, main.STRIKE], 30), ([main.STRIKE, main.STRIKE, 7], 27), ([main.STRIKE, 2, 3], 15), ([main.STRIKE, 8, main.SPARE], 20), ([1, main.SPARE, main.STRIKE], 20), ([4, main.SPARE, 8], 18), ] game = main.Game([]) for rolls, expected in all_rolls: frame.rolls = rolls points = game.calculate_last_frame(frame) self.assertEqual(points, expected)
def test_player1_should_have_won(self): game = main.Game() game.grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] self.assertTrue(game.has_won(1)) self.assertFalse(game.has_won(2))
def testRook(self): g = main.Game() print("Lalallalalalal") g.boardy.printBoard() self.assertRaises(pieces.MoveException, g.isMoveValid, (0, 7), (0, 5)) g.boardy['a2'] = pieces.EmptySpace() self.assertIsNone(g.isMoveValid((0, 7), (0, 5)))
def test_noone_should_have_won(self): game = main.Game() game.grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] self.assertFalse(game.has_won(1)) self.assertFalse(game.has_won(2))
def test_calc_coord(self): game = main.Game() game.size = (300, 300) sol = (0, 0) self.assertEqual(game.calc_coord(55, 13), sol) self.assertEqual(game.calc_coord(55, 310), None) self.assertEqual(game.calc_coord(310, 10), None)
def test_add_new_piece(self): print("\nadd_new_piece()") game = main.Game() old_pieces = game.pieces.copy() print(old_pieces) game.add_new_piece() new_pieces = game.pieces self.assertEqual(len(old_pieces) + 1, len(new_pieces))
def knowledge_testing_run(): game = main.Game() # A modified copy of game.run_subgame() game.active_player = 0 while game.active_player != game.board.called_cabo: game.run_turn() verify_knowledge_consistency(game)
def __init__(self, *args): super().__init__(*args) self.Table = main.Game(Settings.num_blocks_x, Settings.num_blocks_y, Settings.presetting) self.lines = [] self.draw_grid() self.set_opacity(0.3) # self.set_visible(False) self.draw_cells()
def __init__(self, handle): activity.Activity.__init__(self, handle) self.game_size = (8, 6) self.game = main.Game(self) self.build_toolbar() self._pygamecanvas = sugargame.canvas.PygameCanvas( self, main=self.game.run, modules=[pygame.display, pygame.font]) self.set_canvas(self._pygamecanvas) self._pygamecanvas.grab_focus()
def test_start_game(self): #Checks that start_game initiates successfully self.game = main.Game() self.game.start_game() try: self.game.players[1] print "Game and players initiated" except Exception, e: raise e
def test_calc_circle(self): game = main.Game() # print(game.size) game.size = (300, 300) # print(game.size) sol = (0, 0, 100, 100) self.assertEqual(game.calc_circle(0, 0), sol) sol = (100, 100, 100, 100) self.assertEqual(game.calc_circle(1, 1), sol)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.game_size = (8, 6) self.game = main.Game(self) self.build_toolbar() self._pygamecanvas = sugargame.canvas.PygameCanvas(self) self.set_canvas(self._pygamecanvas) self._pygamecanvas.grab_focus() self._pygamecanvas.run_pygame(self.game.run)
def test__on_keyboard_down(self): game = main.Game() game._on_keyboard_down(None, None, 79, None, None) self.assertEqual(game.keys, {"right"}) game._on_keyboard_down(None, None, 79, None, None) self.assertEqual(game.keys, {"right"}) game._on_keyboard_down(None, None, 80, None, None) self.assertEqual(game.keys, {"right", "left"}) game._on_keyboard_down(None, None, 80, None, None) self.assertEqual(game.keys, {"right", "left"})
def testUseItem(self, mInput): game = main.Game() player = game.player item = mock.Mock() item.name = "foo" item.getHealing.return_value = 1 player.inventory = [item] mInput.return_value = "1" game._useItem()
def eval_genomes(genomes, config): r = main.Game() g2 = random.sample(genomes, 20) for genome_id, genome in tqdm.tqdm(genomes): genome.fitness = 0.0 for genome_id2, genome2 in g2: net = neat.nn.FeedForwardNetwork.create(genome, config) net2 = neat.nn.FeedForwardNetwork.create(genome2, config) #output = net.activate(xi) genome.fitness += r.run(NeatAgent(net), NeatAgent(net2), False)[0]
def set_initial_state(self): self.game = main.Game() self.game.init_vars(ai=True) do_nothing = np.zeros(ACTIONS) do_nothing[0] = 1 x_t, reward_0, terminal = self.game.intelligence(do_nothing) x_t = cv.cvtColor(cv.resize(x_t, (80, 80)), cv.COLOR_BGR2GRAY) ret, x_t = cv.threshold(x_t, 1, 255, cv.THRESH_BINARY) s_t = np.stack((x_t, x_t, x_t, x_t), axis=2) return s_t
def setupData(self): self.main=main.Game() self.stepsize = 50 self.company_capital = None self.company_name = None self.save_game_to_load = None self.run_background_spin = True self.gui_rect = pygame.Rect(global_variables.window_size[0] / 2 - 90, global_variables.window_size[1] / 3, 180,180) self.text_receiver = None return
def test_calc_next_mob_coord(self): game = main.Game() game.all_crosses = [(0, 0)] self.assertNotEqual(game.calc_next_mob_coord(), (0, 0)) self.assertIn(game.calc_next_mob_coord(), self.all_coords) game.all_crosses = [(0, 0), (1, 1)] game.all_circles = [(1, 0)] self.assertNotIn(game.calc_next_mob_coord(), [(0, 0), (1, 1), (1, 0)]) game.all_crosses = [(1, 0), (2, 0), (0, 1), (2, 2), (1, 2)] game.all_circles = [(1, 1), (0, 2), (2, 1), (0, 0)] self.assertEqual(game.calc_next_mob_coord(), None)
def testTranslate(self): g = main.Game() g.boardy.printBoard() self.assertEqual((0, 7), g.translate("a1")) self.assertRaises( pieces.MoveException, g.translate, "99999999999999999999999") self.assertIsInstance(g.boardy["a2"], pieces.Pawn) self.assertIsInstance(g.boardy["b3"], pieces.EmptySpace) g.boardy["b3"] = pieces.Pawn(1) self.assertIsInstance(g.boardy["b3"], pieces.Pawn)
def test_calculate_stike_points(self) -> None: frame_num = 0 curr_frame = main.Frame() curr_frame.rolls = [main.STRIKE] next_frame = main.Frame() all_roles = [([1, 2], 13), ([1, main.SPARE], 20)] game = main.Game([]) for rolls, expected in all_roles: next_frame.rolls = rolls frames: List[main.Frame] = [curr_frame, next_frame] points = game.calculate_strike_points(frame_num, frames) self.assertEqual(points, expected)
def test_calc_lines(self): game = main.Game() # print(game.size) game.size = (300, 300) # print(game.size) sol = [ [100, 0, 100, 300], [200, 0, 200, 300], [0, 100, 300, 100], [0, 200, 300, 200], ] self.assertEqual(game.calc_lines(), sol)
def test_check_collisions(self): game = main.Game() game.size = [1000, 1000] game.n_tiles = 4 game.tilesize = 250 game.piece.y = 10 game.check_collisions() # vertical collisions: self.assertEqual(game.piece.y, game.piece.y) game.piece.y = -10 game.check_collisions() self.assertEqual(game.piece.y, game.height) self.assertEqual(game.pieces[-2].y, 0) # horizontal collisions: game.piece.pos = 0, 10 game.check_collisions() self.assertEqual(game.piece.pos, game.piece.pos) game.piece.pos = -10, 10 game.check_collisions() self.assertEqual(game.piece.pos, [0, 10]) # piece-piece collisions: game.pieces = [] piece = main.Piece(pos=(500, 0)) game.pieces.append(piece) game.piece = main.Piece(pos=(500, 500)) game.check_collisions() self.assertEqual(game.piece.y, 500) game.pieces = [] piece = main.Piece(pos=(500, 0)) game.pieces.append(piece) game.piece = main.Piece(pos=(500, 1)) game.pieces.append(game.piece) game.check_collisions() self.assertEqual(game.pieces[-2].y, game.piece.height) piece_size = (200, 200) piece = main.Piece(pos=[600.0, 0], size=piece_size) game.piece = main.Piece(pos=[800.0, 100.52930300000013], size=piece_size) game.pieces = [piece, game.piece] game.check_collisions() self.assertEqual(game.piece.pos, [800.0, 100.52930300000013]) game.size = [2000, 1400] piece_size = (200, 200) piece = main.Piece(pos=[1000.0, 0], size=piece_size) game.piece = main.Piece(pos=[1000.0, 150.94461800000005], size=piece_size) game.pieces = [piece, game.piece] print("\n\n\n") print([piece.pos for piece in game.pieces]) game.check_collisions() print("\n\n\n") self.assertEqual(game.pieces[-2].pos, [1000.0, 200])
def check_hovered_state(self, buttons_list): # iterates through the buttons list and checks which buttons are clicked for img in buttons_list: # check which buttons are in hovered state if img.hovered: self.click_sound.play() if img.state == RESTART: print("starting game") self.running = False GameWindow(self.player_name) elif img.state == HOME: print("BACK TO HOME SCREEN ") self.running = False main.Game(self.player_name)
def test__on_keyboard_up(self): game = main.Game() game.keys.add("right") game._on_keyboard_up(None, None, 79, None, None) self.assertEqual(game.keys, set()) game._on_keyboard_up(None, None, 79, None, None) self.assertEqual(game.keys, set()) game.keys.add("right") game.keys.add("left") game._on_keyboard_up(None, None, 79, None, None) self.assertEqual(game.keys, {"left"}) game._on_keyboard_up(None, None, 80, None, None) self.assertEqual(game.keys, set())
def testValid(self): g = main.Game() self.assertIsNone(g.isMoveValid((0, 6), (0, 4))) self.assertIsNone(g.isMoveValid((0, 6), (0, 5))) self.assertRaises(pieces.MoveException, g.isMoveValid, (0, 6), (0, 6)) self.assertIsNone(g.isMoveValid((0, 6), (0, 4))) self.assertRaises(pieces.MoveException, g.isMoveValid, (0, 6), (1, 5)) g.movePiece((0, 6), (0, 4)) g.movePiece((0, 4), (0, 3)) g.movePiece((0, 3), (0, 2)) self.assertIsNone(g.isMoveValid((0, 2), (1, 1))) g.movePiece((0, 2), (1, 1)) g.movePiece((1, 1), (0, 0)) self.assertIsInstance(g.boardy.board[0][0], pieces.Queen)
def startGame(): flag = True while flag != False: option = menuOption() optionValidate = optionValidated(option) if optionValidate == "1": #main.Tablero().Mostrar() game = main.Game(15, "H") main.main_play(game) root = main.Node(game.initial) newroot = main.makeTreeMinimax(root,game) #main.representTree(newroot, game) if optionValidate == "2": game = main.Game(15,"H") main.main_play(game) root = main.Node(game.initial) newroot = main.makeTreeAplhaBeta(root,game) if optionValidate == "3": flag = False
def test_calc_cross(self): game = main.Game() # print(game.size) game.size = (300, 300) # print(game.size) sol = [ [0, 0, 100, 100], [100, 0, 0, 100], ] self.assertEqual(game.calc_cross(0, 0), sol) sol = [ [100, 100, 200, 200], [200, 100, 100, 200], ] self.assertEqual(game.calc_cross(1, 1), sol)
def test_calculate_strike_points_multiple_strike(self) -> None: frame_num = 0 curr_frame = main.Frame() curr_frame.rolls = [main.STRIKE] all_roles = [ ([main.STRIKE, main.STRIKE], 30), ([main.STRIKE, 4], 24), ] game = main.Game([]) for rolls, expected in all_roles: frames: List[main.Frame] = [curr_frame] for roll in rolls: next_frame = main.Frame() next_frame.rolls = [roll] frames.append(next_frame) points = game.calculate_strike_points(frame_num, frames) self.assertEqual(points, expected)
def test_calc_borders(self): game = main.Game() game.size = [1000, 1000] game.n_tiles = 4 game.tilesize = 200 self.assertEqual(game.calc_borders(), [100, 900]) game.size = [1000, 1000] game.n_tiles = 4 game.tilesize = 250 self.assertEqual(game.calc_borders(), [0, 1000]) game.size = [1000, 1000] game.n_tiles = 5 game.tilesize = 200 self.assertEqual(game.calc_borders(), [0, 1000]) game.size = [100, 100] with self.assertRaises(Exception): game.calc_borders()
def test_second_player_wins(): player1 = main.Player("Alice") player2 = main.Player("Bob") player1.take_card(main.Card(main.Suit.Spades, main.Rank._2)) player1.take_card(main.Card(main.Suit.Diamonds, main.Rank._5)) player1.take_card(main.Card(main.Suit.Spades, main.Rank.King)) player2.take_card(main.Card(main.Suit.Diamonds, main.Rank._2)) player2.take_card(main.Card(main.Suit.Diamonds, main.Rank._4)) player2.take_card(main.Card(main.Suit.Spades, main.Rank.King)) game = main.Game() winner = game.how_wins(player1, player2) winner.print() assert winner == player2, "test second player wins"