def __update_partial_particles(self): from game_engine.game import Game self.__partial_particle_construction += ( 1 / Game.display_configuration().fps) * self.__emission_rate while self.__partial_particle_construction >= 1: Game.current_scene().add_actor(self.__construct_particle()) self.__partial_particle_construction -= 1
def test_second_column_wins(self): """ Tests a won second column does result in a game win declaration """ test = Game() test.board = [[None, '1010', None, None], [None, '1100', None, None], [None, '1000', None, None], [None, '1111', None, None]] self.assertTrue(test.has_won_game('1111'))
def __init__(self): """ The Play class constructor """ self.game = Game() # initiates a Game class instance self.players = [] # a list for players to be added to when initialised self.current_player = None # initiates current player during game play self.selected_piece = None # initiates current selected piece
def __init__(self, display): from game_engine.game import Game max_y = (math.sin(math.radians(Game.get_camera().fov / 2)) * (math.fabs(Game.get_camera().position.z))) max_x = max_y * display.ratio() self.__top_left = Point3D(-max_x, max_y, 0) self.__top_right = Point3D(max_x, max_y, 0) self.__bottom_left = Point3D(-max_x, -max_y, 0) self.__bottom_right = Point3D(max_x, -max_y, 0)
def test_horizontal_two_loses(self): """ Tests a not won horizontal does not result in a game win declaration """ test = Game() test.board = [[None, None, None, '1010'], [None, None, '0100', None], [None, '1000', None, None], ['1111', None, None, None]] self.assertFalse(test.has_won_game('1010'))
def test_horizontal_two_wins(self): """ Tests a won horizontal does result in a game win declaration """ test = Game() test.board = [[None, None, None, '1010'], [None, None, '1100', None], [None, '1000', None, None], ['1111', None, None, None]] self.assertTrue(test.has_won_game('1000'))
def test_fourth_column_loses(self): """ Tests a not won fourth column does not result in a game win declaration """ test = Game() test.board = [[None, None, None, '0010'], [None, None, None, '1100'], [None, None, None, '1000'], [None, None, None, '1111']] self.assertFalse(test.has_won_game('0010'))
def test_fourth_column_wins(self): """ Tests a won fourth column does result in a game win declaration """ test = Game() test.board = [[None, None, None, '1010'], [None, None, None, '1100'], [None, None, None, '1000'], [None, None, None, '1111']] self.assertTrue(test.has_won_game('1000'))
def test_third_column_loses(self): """ Tests a not won third column does not result in a game win declaration """ test = Game() test.board = [[None, None, '1010', None], [None, None, '0100', None], [None, None, '1010', None], [None, None, '1111', None]] self.assertFalse(test.has_won_game('1111'))
def setUp(self): self.fps = 60 self.scene = mock.MagicMock() Game.set_display_configuration(DisplayConfiguration(800, 600, fps=self.fps)) Game.set_scene(self.scene) self.game = Game self.an_actor = Actor() self.test_emitter = ParticleEmitterComponent(OneSecondLifespanParticle, emission_rate=1, emission_vector=Vector3D(1, 0, 0)) self.an_actor.add_component(self.test_emitter)
def test_goblin_vs_orc(self): # this means hp rolls, initiative rolls, to hit roll and damage rolls until one dead set_values([3, 3, 4, 4, 20, 10, 10, 3, 10, 8]) with patch('game_engine.dice._random_int', side_effect=value): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) game = Game([f1, f2]) winner = game.play() self.assertEqual(winner.get_name(), 'Orcs')
def test_third_row_loses(self): """ Tests a not won third row does not result in a game win declaration """ test = Game() test.board = [[None, None, None, None], [None, None, None, None], ['0000', '1000', '0101', '0010'], [None, None, None, None]] self.assertFalse(test.has_won_game('0101'))
def test_third_row_wins(self): """ Tests a won third row does result in a game win declaration """ test = Game() test.board = [[None, None, None, None], [None, None, None, None], ['0000', '1000', '0100', '0010'], [None, None, None, None]] self.assertTrue(test.has_won_game('0000'))
def test_most_pieces_loses(self): """ Tests a mostly full board does not result in a game win declaration """ test = Game() test.board = [['0001', '1000', None, '0100'], ['1110', '0001', '0010', '0111'], ['1001', None, '1110', '1011'], ['0100', '0110', '0011', '1111']] self.assertFalse(test.has_won_game('1111'))
def test_actor_position_changes_on_tick_notification_when_on_move_vector_is_not_zero_normalized_with_the_fps( self): Game.set_display_configuration(DisplayConfiguration(800, 600, 30)) an_actor = Actor() an_actor.position = Point3D(5, 5, 5) an_actor.move_vector = Vector3D(15, -15, 30) an_actor.end_tick() assert an_actor.position == Point3D(5.5, 4.5, 6)
def start_engine_poc(): display_config = DisplayConfiguration(width_px=800, height_px=600, fps=60, scaled=True) camera = Camera(Point3D(0, 0, -50), Rotation(0, 0, 0), 45, 0.1, 100.0) initial_scene = scene.Scene Game.initialize(display_config, camera, initial_scene) __add_some_actors(Game.current_scene()) Game.run()
def __update_fps_string(self): if '_print_fps_start_ns' not in self.__dict__: setattr(self, '_print_fps_start_ns', 0) if self.elapsed_ticks % Game.display_configuration().fps == 0: fps = int( Game.display_configuration().fps / ((self.time.perf_counter_ns() - self._print_fps_start_ns) / 1000000000)) fps_string = f'{fps} FPS' self._print_fps_start_ns = self.time.perf_counter_ns() self.__text_component.text.set_string(fps_string)
def test_fourth_column(self): """ Tests the number of similarities between pieces for each characteristic along the fourth column of pieces is the expected number of similarities """ test = Game() test.board = [[None, '1000', '0001', None], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] self.assertEqual([1, 2, 3, 1], test.bin_count('0110', 0, 3, 1, 0, 3))
def test_one_block(self): """ Tests the number of similarities between pieces for each characteristic along one block of pieces is the expected number of similarities """ test = Game() test.board = [[None, '1000', '0001', None], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] self.assertEqual([1, 0, 0, 1], test.bin_count('0110', 0, 0, 1, 1, 1))
def test_third_row(self): """ Tests the number of similarities between pieces for each characteristic along the third row of pieces is the expected number of similarities """ test = Game() test.board = [[None, '1000', '0001', '0101'], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] self.assertEqual([0, 1, 2, 0], test.bin_count('0110', 2, 1, 0, 1, 3))
def test_horizontal_two(self): """ Tests the number of similarities between pieces for each characteristic along a horizontal row of pieces is the expected number of similarities """ test = Game() test.board = [[None, '1000', '0001', None], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] self.assertEqual([1, 2, 2, 2], test.bin_count('0110', 0, 0, 1, 1, 3))
def __schedule_enemies(self): current_time = Game.running_time_seconds() while self.enemy_schedule and ( current_time - self.last_scheduled_time ) >= self.enemy_schedule[0].delay_seconds: self.enemy_schedule.pop(0).callback() self.last_scheduled_time = current_time
def test_choose_piece(self): """ Tests choose_piece() method in the PlayerMediumAI class """ test = PlayerMediumAI(Game(), "Test") test.game.board = [['0000', '1000', '0001', '0101'], [None, '0010', '0111', None], ['1001', None, '0100', '1111'], ['1011', '0110', None, '1110']] test.game.pieces = { '3': '0011', '10': '1010', '12': '1100', '13': '1101' } self.assertEqual( '12', test.get_best( dict({ str(pce): test.select_best_sim_count( test.easy(test.game.pieces[pce]), False, test.game.pieces[pce]) for pce in test.game.pieces }.items()), False)) self.assertEqual( '3', test.get_best( dict({ str(pce): test.select_best_sim_count( test.hard(test.game.pieces[pce]), True, test.game.pieces[pce]) for pce in test.game.pieces }.items()), True))
def test_pieces(self): """ Tests pieces dictionary variable in Game class instance """ test = Game() expctd = { '0': '0000', '1': '0001', '2': '0010', '3': '0011', '4': '0100', '5': '0101', '6': '0110', '7': '0111', '8': '1000', '9': '1001', '10': '1010', '11': '1011', '12': '1100', '13': '1101', '14': '1110', '15': '1111' } self.assertEqual(test.pieces, expctd) expctd.pop('11') self.assertNotEqual(test.pieces, expctd) test.pieces.pop('11') self.assertEqual(test.pieces, expctd)
def test_board(self): """ Tests board multidimensional array variable in Game class instance """ test = Game() expctd = [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] self.assertEqual(test.board, expctd) expctd = [['0000', None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]] self.assertNotEqual(test.board, expctd) test.board[0][0] = '0000' self.assertEqual(test.board, expctd) expctd = [['0000', None, None, None], [None, None, None, None], [None, None, '1111', None], [None, None, None, None]] self.assertNotEqual(test.board, expctd) test.board[2][2] = '1111' self.assertEqual(test.board, expctd)
def __apply_next_pattern_node(self): if self.__shoot_pattern_node_list: self.__current_shoot_pattern_node = self.__shoot_pattern_node_list.pop( 0) self.__configure_pattern_node(self.__current_shoot_pattern_node) self.__next_node_at_tick = self.__current_tick + ( self.__current_shoot_pattern_node.duration_seconds * Game.display_configuration().fps) else: self.__current_shoot_pattern_node = None
def test_max_similarities_two(self): """ Tests the max_similarities() method with one empty board cell """ test = PlayerAI(Game(), "Test") test.game.board = [['0001', '1000', None, '0100'], ['1110', '0001', '0010', '0111'], ['1001', '1100', '1110', '1011'], ['0100', '0110', '0011', '1111']] self.assertEqual([((0, 2), 3, 1)], test.max_similarities('1101'))
def test_choose_piece(self): """ Tests choose_piece() method in the PlayerEasyAI class """ test = PlayerEasyAI(Game(), "Test") test.game.board = [['0000', '1000', '0001', '0101'], [None, '0010', '0111', None], ['1001', None, '0100', '1111'], ['1011', '0110', None, '1110']] test.game.pieces = {'3': '0011', '10': '1010', '12': '1100', '13': '1101'} self.assertEqual('3', test.choose_piece())
def test_max_similarities_one(self): """ Tests the max_similarities() method with three empty board cells """ test = PlayerAI(Game(), "Test") test.game.board = [[None, '1000', '0001', '0101'], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] self.assertEqual([((0, 0), 2, 4), ((1, 0), 2, 2), ((2, 1), 3, 2)], test.max_similarities('1100')) self.assertEqual([((0, 0), 2, 4), ((1, 0), 2, 1), ((2, 1), 3, 2)], test.max_similarities('1101')) self.assertEqual([((0, 0), 2, 4), ((1, 0), 1, 3), ((2, 1), 3, 2)], test.max_similarities('1010'))
def test_place_piece(self): """ Tests choose_piece() method in the PlayerHardAI class """ test = PlayerHardAI(Game(), "Test") test.game.board = [[None, '1000', '0001', '0101'], [None, '0000', '0010', '0111'], ['1001', None, '1111', '1011'], ['0100', '0110', '0011', '1110']] test.game.pieces = {'10': '1010', '12': '1100', '13': '1101'} test.place_piece('1010') self.assertTrue(test.game.board == [[None, '1000', '0001', '0101'], [None, '0000', '0010', '0111'], ['1001', '1010', '1111', '1011'], ['0100', '0110', '0011', '1110']] and test.game.has_won_game('1010'))