def match_random_policy(parties: Tuple[Party, Party]) -> int: field = Field([copy.deepcopy(parties[0]), copy.deepcopy(parties[1])]) field.rng = GameRNGRandom() field.rng.set_field(field) field.put_record = lambda record: None winner = -1 next_phase = FieldPhase.BEGIN while True: actions = [] for p in range(2): legals = field.get_legal_actions(p) if len(legals) == 0: actions.append(None) else: actions.append(random.choice(legals)) if next_phase is FieldPhase.BEGIN: field.actions_begin = actions elif next_phase is FieldPhase.FAINT_CHANGE: field.actions_faint_change = actions next_phase = field.step() if next_phase is FieldPhase.GAME_END: winner = field.winner break if field.turn_number >= 64: break return winner
def test_faint_change(self): """ 瀕死状態での交代 :return: """ # H:152,A:101,B:101,C:117,S:97 pokest_0_0 = PokeStatic.create(Dexno.BULBASAUR, [Move.TACKLE, Move.SWORDSDANCE]) # H:162,A:102,B:97,C:187,S:172 pokest_0_1 = PokeStatic.create(Dexno.ALAKAZAM, [Move.WATERGUN, Move.ROCKTHROW]) # H:185,A:136,B:130,C:137,S:152 pokest_1_0 = PokeStatic.create(Dexno.CHARIZARD, [Move.FIREBLAST, Move.CONFUSERAY, Move.EARTHQUAKE]) # H:267,A:162,B:117,C:117,S:82 # カビゴン pokest_1_1 = PokeStatic.create(Dexno.SNORLAX, [Move.BODYSLAM]) field = Field([Party([pokest_0_0, pokest_0_1]), Party([pokest_1_0, pokest_1_1])]) rng = GameRNGFixed() field.rng = rng field.rng.set_field(field) self.assertEqual(field.parties[0].get().hp, 152) self.assertEqual(field.parties[1].get().hp, 185) field.actions_begin = [FieldAction(FieldActionType.MOVE, move_idx=0), FieldAction(FieldActionType.MOVE, move_idx=0)] self.assertEqual(field.step(), FieldPhase.FAINT_CHANGE) # CHARIZARD -> BULBASAUR : ダメージ188 self.assertEqual(field.parties[0].get().hp, 0) # BULBASAUR -> CHARMANDER: 攻撃機会なし self.assertEqual(field.parties[1].get().hp, 185) field.actions_faint_change = [FieldAction(FieldActionType.FAINT_CHANGE, faint_change_idx=1), None] self.assertEqual(field.step(), FieldPhase.BEGIN) self.assertEqual(field.parties[0].get().hp, 162) self.assertEqual(field.parties[1].get().hp, 185)