def test_check_stats(self): rc = True x = gamecore.GameCore('nonce') for key in x.stats.keys(): if x.stats[key] != 0: rc = False self.assertTrue(rc)
def test_clear_stats(self): rc = True x = gamecore.GameCore('nonce') x.incr_stat('win') x.clear_stats() for key in x.stats.keys(): if x.stats[key] != 0: rc = False self.assertTrue(rc)
def main(args): # load our air hockey board board = cv.imread('assests/board.png') # initiallize game state state = {} state['delta_t'] = 1/30 state['board_shape'] = board.shape state['goal_size'] = 0.45 state['puck_radius'] = int(round(state['board_shape'][0] * 3.25 / 51.25)) # Use standard measures state['paddle_radius'] = int(round(state['board_shape'][0] * 3.25 / 51.25)) # Use standard measures x_offset = 0.25 if random.uniform(-1, 1) < 0 else 0.75 state['puck_pos'] = {'x': board.shape[1] * x_offset, 'y': random.uniform(0 + state['puck_radius'], board.shape[0] - state['puck_radius'])} state['puck_speed'] = {'x': 0, 'y': 500} state['paddle1_pos'] = {'x': board.shape[0]*state['goal_size']/2+1, 'y': board.shape[0]/2} state['paddle2_pos'] = {'x': board.shape[1] - board.shape[0]*state['goal_size']/2-1, 'y': board.shape[0]/2} state['paddle1_speed'] = {'x': 0, 'y': 0} state['paddle2_speed'] = {'x': 0, 'y': 0} state['paddle_max_speed'] = 150 state['goals'] = {'left': 0, 'right': 0} state['is_goal_move'] = None epsilon = 1 # initiallize gui core if 'video_file' in args: gui_core = guicore.GUICore(board, args.show_window == 'True', True, args.video_file) else: gui_core = guicore.GUICore(board) # dinamically import Player classes for both players player1_module = importlib.import_module(args.player1) player2_module = importlib.import_module(args.player2) # create player instances player1 = player1_module.Player(state['paddle1_pos'], 'left') player2 = player2_module.Player(state['paddle2_pos'], 'right') # create game with given players game_core = gamecore.GameCore(player1, player2, board, state, epsilon, gui_core) # run game result = game_core.begin_game() # prepare output # convert exception data types to string for k, v in result.items(): if isinstance(v, Exception): result[k] = str(type(v).__name__) + ': ' + str(v) result['display_names'] = {'left': player1.my_display_name, 'right': player2.my_display_name} result = json.dumps(result, skipkeys=True) return result
def __init__(self): """__init__ """ self.game = gamecore.GameCore('') self.unhappy = unhappy.Unhappy() self.userinput = userinput.UserInput() # TODO: move to configuration or such.. self.wordselection = wordselection.WordSelection('../data/nouns.txt') self.wordselection.read_file() self.word_group = (self.wordselection.pick_word_group()) self.wordselection.create_word_structure() self.ingame = True
def test_creation(self): x = gamecore.GameCore('nonce') self.assertNotEqual(x, None)
def test_incr_good_stat(self): x = gamecore.GameCore('nonce') x.incr_stat('win') self.assertEqual(x.stats['win'], 1)
def test_incr_bad_stat(self): x = gamecore.GameCore('nonce') with self.assertRaises(ValueError) as context: x.incr_stat('unknown') self.assertTrue(context.exception)