def load_level(): """Generates a new random level.""" GAME['level'] = Level() GAME['level'].generate_solvable(8, 12, 0.2, 0.4, 0.05, 1, 3, 3) GAME['level'].save('tmp') GAME['player'] = Player2(GAME['level']) display_all() cli.display_toolbar() cli.handle_action()
def test_parse(self): text = \ 'Invaders: pos(0,0)\n' \ '[1,1] [1,2] [1,3]\n' \ 'Bunkers:\n' \ 'pos(70,430) size(13,3)\n' \ 'pos(340,430) size(13,3)\n' level = Level(text) invaders, bunkers = level.invaders, level.bunkers expected = [[ Invader(0, 75, 42, 30, 5, 1, 1, 0), Invader(47, 75, 42, 30, 5, 1, 2, 0), Invader(94, 75, 42, 30, 5, 1, 3, 0) ]] actual = invaders.arr_invaders self.assertEqual(expected, actual)
def optimize_menu(): cli.add_action("1", start_value_iteration) cli.add_action("2", start_policy_iteration) cli.add_action("3", start_qlearning) cli.clear_status() cli.add_status("Press (1) to start Value Iteration algorithm.") cli.add_status("Press (2) to start Policy Iteration algorithm.") cli.add_status("Press (3) to start QLearning algorithm.") display_all() cli.wait_for_action('1', '2', '3', 'e') if __name__ == "__main__": cli = get_cli() cli.add_action('exit', quit_app, toolbar=True) cli.add_action('load level', load_level, toolbar=True) cli.add_action('play', user_play, toolbar=True) cli.add_action('optimize', optimize_menu, toolbar=True) GAME['level'] = Level() GAME['level'].load("instances/lvl-n8-0") GAME['player'] = Player2(GAME['level']) display_all() cli.display_toolbar() cli.wait_for_action('e', 'l', 'p', 'o')
def test_incorrect_format_exception(self): text = \ 'Invaders: pos(0,0)\n' \ '{1,1] [1,2] [1,3]\n' with self.assertRaises(IncorrectFormatLevelsFile): Level(text)
def OnInit(self): self.level = self.add(Level()) self.level.newPize()