def test_move(self): move = moves.Move(1, (6, 0), (5, 0)) self.b.move(move) expected = [['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'], ['P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], ['P', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', 'P', 'P', 'P', 'P', 'P', 'P', 'P'], ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']] self.assertEqual(self.b.get_board(), expected)
def availableMoves(self): result = [] fieldPlace = self.getPlace() if not fieldPlace: return [] if fieldPlace.isGround(): availablePlaces = [ p for p in fieldPlace.getNeighboringPlaces(moves.directions8) if p and (p.isGround() or (p.isSea() and p.hasTeamShip(self.gamer.team))) ] result += [moves.Move(p.x, p.y) for p in availablePlaces] for payload in list( set([ item.className() for item in fieldPlace.getItems() if item.moveable ])): result += [ moves.Move(p.x, p.y, payload) for p in availablePlaces if p.opened or p.hasTeamShip(self.gamer.team) ] else: if fieldPlace.hasTeamShip(self.gamer.team): result += [ moves.Move(p.x, p.y) for p in [ place for place in fieldPlace.getNeighboringPlaces( moves.directions4) if place ] if p and p.isGround() ] else: result += [ moves.Move(p.x, p.y) for p in [ place for place in fieldPlace.getNeighboringPlaces( moves.directions8) if place ] if p and p.isSea() ] return list(set(result))
def test_TileCardIce(self): tile = TileCardIce() tile2 = TileCard() self.g.field.getPlaceByCoordinates(6, 1).placeTile(tile) self.g.field.getPlaceByCoordinates(6, 2).placeTile(tile2) items = self.g.items c = [item for item in items if item.className() == 'Pirate'][0] c.x = 6 c.y = 0 c.move(moves.Move(6, 1)) self.assertEqual(c.x, 6) self.assertEqual(c.y, 2) self.assertTrue(self.g.field.getPlaceByCoordinates(6, 1).opened) self.assertTrue(self.g.field.getPlaceByCoordinates(6, 2).opened) self.assertFalse(self.g.field.getPlaceByCoordinates(6, 3).opened)
def availableMoves(self): result = [] fieldPlace = self.getPlace() if not fieldPlace: return [] result += [ moves.Move(p.x, p.y) for p in [ place for place in fieldPlace.getNeighboringPlaces(moves.directions4) if place ] if p and not p.isGround() and len([ pn for pn in p.getNeighboringPlaces(moves.directions4) if pn and pn.isGround() ]) > 0 ] return list(set(result))
def __init__(self, species, level): self.species = species fn = os.path.join(settings.path, "data", globs.POKEMON) root = data.getTreeRoot(fn, "Ditto main") for sp in data.getChildren(root, "species"): if data.getAttr(sp, "id", data.D_STRING) == self.species: self.speciesNode = sp break self.nickname = None self.level = level self.exp = 0 typeNode = data.getChild(self.speciesNode, "type") self.type1 = data.getAttr(typeNode, "primary", data.D_STRING) self.type2 = data.getOptionalAttr(typeNode, "secondary", data.D_STRING, None) self.PID = random.randint(0, 4294967295) self.trainer = None self.trainerID = None self.ability = None self.gender = G_MALE self.nature = 0 self.shiny = False self.form = 0 self.happiness = 0 self.pokerus = False self.EVs = { ST_HP: 0, ST_ATTACK: 0, ST_DEFENSE: 0, ST_SPEED: 0, ST_SPATTACK: 0, ST_SPDEFENSE: 0 } self.IVs = { ST_HP: random.randint(0, 31), ST_ATTACK: random.randint(0, 31), ST_DEFENSE: random.randint(0, 31), ST_SPEED: random.randint(0, 31), ST_SPATTACK: random.randint(0, 31), ST_SPDEFENSE: random.randint(0, 31) } self.stats = {} self.calcStats() self.currentHP = self.stats[ST_HP] self.status = None self.moves = [None, None, None, None] movesNode = data.getChild(self.speciesNode, "attacks") moveNodes = sorted(data.getChildren(movesNode, "move"), key=lambda n: int(n.attrib["level"])) i = 0 for node in moveNodes[-4:]: self.moves[i] = moves.Move(data.getAttr(node, "id", data.D_STRING)) i += 1 self.ballCaughtIn = 0 self.heldItem = None