def test_brew_middle_recursive(self): witch = Witch((3, 2, 2, 1), 0) brew_action, score, brew_id = witch.recursive_find_best_action( ALL_ACTIONS, 1) self.assertEqual(69, brew_action.action_id) self.assertEqual(13, score) self.assertEqual(69, brew_id)
def test_find_cast_deep_4(self): witch = Witch((3, 0, 0, 0), 0) all_actions = { "BREW": POTIONS + [BrewAction((0, 0, 0, -1), 100, 1)], "CAST": SORTS, } cast_action, score, brew_id = witch.recursive_find_best_action( all_actions, 4) self.assertEqual(79, cast_action.action_id) self.assertEqual(1, brew_id)
def test_choose_sort_3_avoid_too_much_of_1_ingredient(self): witch_state = Witch((3, 0, 0, 0), 0) sorts = [ CastAction((-1, 4, 0, 0), 0, 1, 0, 0, True, True), CastAction((-1, 1, 1, 1), 0, 2, 0, 0, True, True), ] potions = [ BrewAction((1, 1, 1, 1), 0, 5, 0, 0, True, True), ] sort = witch_state.find_best_cast(sorts, potions) self.assertEqual(2, sort.action_id) sort = witch_state.find_best_cast(sorts[::-1], potions) self.assertEqual(2, sort.action_id)
def test_choose_sort_max_10(self): witch_state = Witch((3, 0, 0, 0), 0) sorts = [ CastAction((-1, 10, 0, 0), 0, 1, 0, 0, True, True), CastAction((-1, 2, 0, 0), 0, 2, 0, 0, True, True), ] potions = [ BrewAction((1, 1, 1, 1), 0, 5, 0, 0, True, True), ] sort = witch_state.find_best_cast(sorts, potions) self.assertEqual(2, sort.action_id) sort = witch_state.find_best_cast(sorts[::-1], potions) self.assertEqual(2, sort.action_id)
def main(): while True: start = time() all_actions = read_actions() me = Witch.read_input() other = Witch.read_input() best_action, score, brew_id = me.recursive_find_best_action( all_actions, 6) if best_action: best_action.doit(round(time() - start, 2), brew_id) else: best_action = me.heuristique_find_best_action(all_actions) if best_action is None: print("REST", time() - start) else: best_action.doit(round(time() - start, 2), "heuristic")
def test_brew_middle_heuristic(self): witch = Witch((3, 2, 2, 1), 0) brew_action = witch.heuristique_find_best_action(ALL_ACTIONS) self.assertEqual(69, brew_action.action_id)