def test_initializes_correctly(): #testing for damage dealing moves scratch = Move("scratch") assert scratch.name == "Scratch" assert scratch.type == "normal" assert scratch.power == 40 assert scratch.accuracy == 100 ember = Move("ember") assert ember.name == "Ember" assert ember.type == "fire" assert ember.power == 40 assert ember.accuracy == 100 #testing for move with spaces and upper case jumpKick = Move("Jump Kick") assert jumpKick.name == "Jump Kick" assert jumpKick.type == "fighting" assert jumpKick.power == 100 assert jumpKick.accuracy == 95 #testing for non-valid moves blank = Move("") assert blank.name == "" assert blank.type == "normal" assert blank.power == 0 assert blank.accuracy == 0 fake = Move("fake") assert fake.name == "Struggle" assert fake.type == "normal" assert fake.power == 50 assert fake.accuracy == None
def test_move_effectiveness_function(): battler = PokemonBattler() #half damage test ember = Move("ember") flambi = Pokemon("Flambi", "Flareon", ["fire", ""]) assert battler.moveTypeModifier(ember, flambi) == 0.5 #double damage test with two moves iceBeam = Move("ice beam") pidgey = Pokemon("Pipi", "Pidgey", ["normal", "flying"]) assert battler.moveTypeModifier(iceBeam, pidgey) == 2 #no damage test thunderBolt = Move("thunderbolt") phanpy = Pokemon("Cheerio", "Phanpy", ["ground", ""]) assert battler.moveTypeModifier(thunderBolt, phanpy) == 0 #quadrouble damage test rockBlast = Move("rock blast") butterfree = Pokemon("Flutter", "Butterfree", ["bug", "flying"]) assert battler.moveTypeModifier(rockBlast, butterfree) == 4 #quarter damage test #reuses ember move from above kingdra = Pokemon("King", "Kingdra", ["water", "dragon"]) assert battler.moveTypeModifier(ember, kingdra) == 0.25
def test_equals_overload_works(): scratch1 = Move("scratch") scratch2 = Move("scratch") ember = Move("ember") assert scratch1 == scratch2 assert not (scratch1 == ember)
class Moves_list(Enum): ######################## # Grass TYPE MOVES # ######################## petal_dance = Move("petal dance", "grass", 120) vine_whip = Move("vine whip", "grass", 45) razor_leaf = Move("razor leaf", "grass", 55)
def valid_moves(self): moves = [ Move([self.hole_row, self.hole_col + 1]), Move([self.hole_row, self.hole_col - 1]), Move([self.hole_row + 1, self.hole_col]), Move([self.hole_row - 1, self.hole_col]) ] return [move for move in moves if self.can_move(move)]
def _generate_plays(board): moves = [] for card in board.current_player().hand: if card.is_construct(): moves.append(Move("play", card.name, None)) else: target_sets = _generate_target_sets_for_card(board, card) moves.extend([Move("play", card.name, targets) for targets in target_sets]) return moves
def __init__(self): self.name = 'Wizard' fireball = Move('Fireball', 0.85, lambda: randint(5, 8), 2, '5 - 8') lightningSpray = Move('Lightning Spray', 0.25, lambda: randint(11, 14), 1, '11 - 14') shield = mageShield(1.00, 5, 'N/A') ult = ('Meteor (Ult)', 1, lambda: randint(25, 35), 6, '25 - 35') self.moves = [punch, fireball, shield, lightningSpray] self.ult = ult self.HP = 43
def create_entry(self): trainer_name = input('What is your name? ') trainer_age = input('How old are you? ') trainer_city = input('What city are you from? ') trainer = Trainer(trainer_name, trainer_age, trainer_city) pokemon_name = input('What is the name of your pokemon? ') pokemon_type = input('What type is your pokemon? ') pokemon = Pokemon(pokemon_name, pokemon_type) move_name = input('Enter its signature move: ') move_type = input('Enter the move type: ') move = Move(move_name, move_type) pokemon.add_moves(move_name) print('Thank you for your information!') print('Here is your entry: ') #creates list of trainer attributes trainer_list = [ 'Name: ' + trainer_name, 'Age: ' + trainer_age, 'City: ' + trainer_city ] for i in trainer_list: print(i) #creates list for pokemon attributes pokemon_list = [ 'Pokemon: ' + pokemon_name, 'Type: ' + pokemon_type, 'Signature Move: ' + move_name, 'Move Type: ' + move_type ] for i in pokemon_list: print(i)
def move(self): left = self.get_my_left() right = self.get_my_right() if left == right: if left == 0: return Move.LEFT_TO_LEFT else: return Move.RIGHT_TO_LEFT return Move.SWITCH(right, left)
def __init__(self): self.name = 'Goose' honk = Move('HONK', 0.5, lambda: randint(255, 255), 4, '255') ult = Ult('NOOT NOOT (Ult)', 1, lambda: randint(511, 511), 6, '511') self.moves = [honk, honk, honk, honk] self.ult = ult self.HP = 7
def is_check_mate(self, white): opposite = 0 if white else 1 for spot in self.board[opposite]: for move in self.board[opposite][spot].get_moves( spot[0], spot[1], self.board[opposite], self.board[white]): board = Board(copy.deepcopy(self.board)) board.move(Move(opposite, spot, move)) if not board.is_check(white): return False return True
def __init__(self): self.name = 'Cleric' smite = Move('Smite', 0.70, lambda: randint(8, 10), 2, '8 - 10') healMove = heal(0.95, lambda: randint(5, 8), 4, '5 - 8') ult = Ult('God Blow (Ult)', 1, lambda: randint(23, 25), 6, '23 - 25') self.moves = [punch, smite, healMove, block] self.ult = ult self.HP = 40
def _generate_activates(board): legal_constructs = [card for card in board.current_player().constructs if board.current_player().can_activate_construct(card.name)] moves = [] for card in legal_constructs: target_sets = _generate_target_sets_for_card(board, card) moves.extend([Move("activate", card.name, targets) for targets in target_sets]) return moves
def __init__(self): self.name = 'Bard' rock = Move('Rock', 0.65, lambda: randint(8, 11), 2, '8 - 11') heavyMetal = recoil('Heavy Metal', 0.20, lambda: randint(18, 22), 1, '18 - 22') ult = Ult('Wonderwall(Ult)', 1, lambda: randint(28, 32), 6, '28 - 32') self.moves = [punch, rock, block, heavyMetal] self.ult = ult self.HP = 38
def __init__(self): self.name = 'Ranger' arrow = Move('Arrow', 0.80, lambda: randint(4, 12), 2, '4 - 12') boomArrow = recoil('Explosive Arrow', 0.20, lambda: randint(16, 24), 1, '16 - 24') ult = Ult('Headshot (Ult)', 1, lambda: randint(22, 35), 6, '22 - 35') self.moves = [punch, arrow, block, boomArrow] self.ult = ult self.HP = 39
def __init__(self): self.name = 'Bard' kick = Move('Kick', 0.70, lambda: randint(7, 9), 2, '7 - 9') headbutt = recoil('Headbutt', 0.25, lambda: randint(15, 20), 1, '15, 20') ult = Ult('Ki Strike (Ult)', 1, lambda: randint(25, 30), 6, '25 - 30') self.moves = [punch, kick, block, headbutt] self.ult = ult self.HP = 40
def __init__(self): self.name('F*** off, I win.') hammer = Move('HAMMER OF GOD', 1.00, lambda: randint(30, 34), 2, '30 - 34') forceWin = recoil('Power Abuse', 1.00, lambda: randint(9999, 9999), 6, '9999') ult = Ult('ForceWin.exe', 1.00, lambda: randint(99999, 99999), 6, '99999') self.moves = [punch, hammer, block, forceWin] self.ult = ult self.HP = 9999
def _generate_acquires(board): card_names = [] runes = board.current_player().runes_remaining if board.mystics > 0 and runes >= 3: card_names.append("Mystic") if board.heavy > 0 and runes >= 2: card_names.append("Heavy Infantry") for card in board.center: if not card.is_monster() and board.current_player().can_acquire_card(card): card_names.append(card.name) return [Move("acquire", card_name, None) for card_name in card_names]
def changeMove(self, moveNum, newMoveName): moveNum = moveNum - 1 newMove = Move(newMoveName) #if this isn't a real move, return false and don't change the move if newMove.name == "Struggle" or newMove.name == "": return False #if it is a real move if moveNum >= len(self.moves): #and the slot doesn't have a move in it self.moves.append(newMove) #add the mvoe as a new move else: #and the slot already has a move in it self.moves[moveNum] = newMove #replace the old move with the new one return True
def _generate_defeats(board): GAIN_HONOR_EFFECT = 4 card_name_target_tuples = [] power = board.current_player().power_remaining if power >= 2: card_name_target_tuples.append(("Cultist", {GAIN_HONOR_EFFECT: ()})) for card in board.center: if card.is_monster() and card.cost <= power: for targets in _generate_target_sets_for_card(board, card): card_name_target_tuples.append((card.name, targets)) return [Move("defeat", card_name, targets) for card_name, targets in card_name_target_tuples]
def play(self, spot): if not self.check_mate: if self.move_start: if spot in self.move_array: move = Move(self.turn, self.move_start, spot) pawn_promotion = self.board.move(move) self.moves.append(move) if pawn_promotion: self.move_start = spot self.move_array = self.board.get_move_array( spot[0], spot[1], self.turn) return self.board.get_board(self.move_array) self.check = self.board.is_check(self.turn) if self.check: self.check_mate = self.board.is_check_mate(self.turn) self.turn = 0 if self.turn else 1 self.__prep_move() else: if self.board.isPiece(spot[0], spot[1], self.turn): self.move_start = spot self.move_array = self.board.get_move_array( spot[0], spot[1], self.turn) return self.board.get_board(self.move_array)
if self.is_alive() == False and opponent.is_alive() == False: print(f"\nDouble KO") return f"Double KO" def hobby(self): print(f"{self._name} likes to eat Poke-Puffs") if __name__ == "__main__": ##################### # LIST OF MOVES # ##################### # moves for Venusaur petal_dance = Move("petal dance", "grass", 120) vine_whip = Move("vine whip", "grass", 45) razor_leaf = Move("razor leaf", "grass", 55) double_edge = Move("double edge", "normal", 120) # mvoes for charizard flame_thrower = Move("flame thrower", "fire", 90) dragon_breath = Move("dragon breath", "dragon", 60) ember = Move("ember", "fire", 40) fire_spin = Move("fire spin", "fire", 35) # moves for balstoise flash_cannon = Move("flash cannon", "steel", 80) rapid_spin = Move("rapid spin", "normal", 50) aqua_tail = Move("aqua tail", "water", 90) hydro_pump = Move("hydro pump", "water", 110)
def _createMovesList(self, namesList): movesList = [] for name in namesList: movesList.append(Move(name)) return movesList
super().__init__(name, types, weakness) self.advantage = "grass" def get_weaknesses(self): print( f"{self._name} is strong against {self.advantage} and weak against {self._weakness}" ) def hobby(self): print(f"{self._name} likes to fly high above the clouds.") if __name__ == "__main__": # List of moves flame_thrower = Move("flame thrower", "fire", 90) dragon_breath = Move("dragon breath", "dragon", 60) ember = Move("ember", "fire", 40) fire_spin = Move("fire spin", "fire", 35) # creating pokemon charizard = Charizard("Charizard") charizard.setEVs(100, 40, 20) charizard.addMove(flame_thrower) charizard.addMove(ember) # charizard.use( fire_spin ) lilChar = Charizard("lil Char") lilChar.setEVs(100, 50, 180) lilChar.addMove(flame_thrower) lilChar.addMove(dragon_breath)
import unittest from unittest import mock from pokemon import Pokemon from moves import Move pound = Move("Pound", "Deals damage with no additional effect.", "Normal", "Physical", 40, 100, 35) leer = Move("Leer", "Lowers the target's Defense by 1 stage.", "Normal", "Status", 0, 100, 30) sing = Move("Sing", "Puts the target to sleep.", "Normal", "Status", 0, 55, 15) supersonic = Move("Supersonic", "Confuses the target.", "Normal", "Status", 0, 55, 20) example_moves = [pound, leer, sing, supersonic] class TestDetermineStats(unittest.TestCase): def test_each_stat_correctly_divided(self): # Example Pokémon (from bulbapedia.bulbagarden.net/wiki/Statistic) garchomp = Pokemon("Garchomp", "Male", 78, example_moves, "Adamant", [24, 12, 30, 16, 23, 5], [74, 190, 91, 48, 84, 23]) self.assertEqual(garchomp.hp, 289) self.assertEqual(garchomp.attack, 278) self.assertEqual(garchomp.defense, 193) self.assertEqual(garchomp.spatk, 135) self.assertEqual(garchomp.spdef, 171) self.assertEqual(garchomp.speed, 171) class TestCalculateEffectiveness(unittest.TestCase): def test_correct_eff_dict_creation(self): # Example Pokémon Litleo (Fire/Normal) and Misdreavus (Ghost)
def do_move(self, acting_player: PlayerType, move: Move) -> None: if acting_player != self.next_player: raise InvalidMoveError(f"It's {self.next_player}'s turn") # switch to opponent stones if still in the initial move sequence player = acting_player if not self.initial_moves else get_opponent( acting_player) if isinstance(move, PlaceStone): self.place_stone(player, *move.get_xy(), move.stoneType) if isinstance(move, MoveStack): x, y = move.get_xy() start_stack = self.get_stack(x, y) top_stone = start_stack[-1] if len(start_stack) > 0 else None if not top_stone: raise InvalidMoveError(f"There is no stack on {x}/{y} to move") if top_stone.player != player: raise InvalidMoveError( f"Stack on {x}/{y} belongs to {top_stone.player} and not to {player}" ) # If no stack was defined, pick up as much as the carry limit allows pickup = move.pickup if move.pickup else min( len(start_stack), self.board_size) if pickup > self.board_size: raise InvalidMoveError( f"The carry limit is {self.board_size} (tried to pick up {move.pickup})" ) if pickup > len(start_stack): raise InvalidMoveError( f"Stack on {x}/{y} has only {len(start_stack)} pieces (tried to pick up {move.pickup})" ) carried_stones = start_stack[-pickup:] for _ in range(pickup): # remove stones from stack start_stack.pop() # If no droppings were defined, drop all at once droppings = move.droppings if move.droppings else [pickup] if pickup != sum(droppings): raise InvalidMoveError( f"Cannot pickup {pickup} stones and drop a total of {droppings}" ) dropped_stones = split_by_counts(carried_stones, droppings) drop_reach = len( droppings) # number of fields stones will be dropped on drop_stacks = self.get_stacks(x, y, move.direction, drop_reach) for stack, stones in zip(drop_stacks, dropped_stones): top_stone = stack[-1] if len(stack) > 0 else None dropping_capstone_only = stones[0].type == StoneType.CAPSTONE if top_stone and top_stone.type == StoneType.CAPSTONE: raise InvalidMoveError( "Can't drop stones on a {top_stone.stoneType}") if top_stone and top_stone.type == StoneType.STANDING: if dropping_capstone_only: stack[-1] = top_stone.flatten() else: raise InvalidMoveError( "Standing stones can only be flattened with a capstone alone" ) stack.extend(stones) if self.initial_moves and acting_player == PlayerType.BLACK: self.initial_moves = False self.next_player = get_opponent(self.next_player)
super().__init__(name, types, weakness) self.advantage = "fire" def get_weaknesses(self): print( f"{self._name} is strong against {self.advantage} and weak against {self._weakness}" ) def hobby(self): print(f"{self._name} likes to nap inside of his shell.") if __name__ == "__main__": # List of moves flash_cannon = Move("flash cannon", "steel", 80) rapid_spin = Move("rapid spin", "normal", 50) aqua_tail = Move("aqua tail", "water", 90) hydro_pump = Move("hydro pump", "water", 110) # creating pokemon blastoise = Blastoise("Blastoise") blastoise.setEVs(100, 25, 200) blastoise.addMove(flash_cannon) blastoise.addMove(hydro_pump) shell_shucker = Blastoise("Shell Shucker") shell_shucker.setEVs(100, 25, 200) shell_shucker.addMove(flash_cannon) shell_shucker.addMove(hydro_pump) shell_shucker.addMove(aqua_tail)
from random import randint from moves import Move, Block, recoil, Ult, heal, mageShield global punch global block global baseUlt punch = Move('Punch', 1.00, lambda: randint(3, 6), 3, '3 - 6') block = Block(1.00, 5, 'N/A') baseUlt = Ult('Ultimate', 1, lambda: randint(18, 26), 6, '18 - 26') class Character: def __init__(self, moveList, name, ult): self.moves = moveList self.name = name self.ult = ult class Monk(Character): def __init__(self): self.name = 'Bard' kick = Move('Kick', 0.70, lambda: randint(7, 9), 2, '7 - 9') headbutt = recoil('Headbutt', 0.25, lambda: randint(15, 20), 1, '15, 20') ult = Ult('Ki Strike (Ult)', 1, lambda: randint(25, 30), 6, '25 - 30') self.moves = [punch, kick, block, headbutt] self.ult = ult self.HP = 40