Optimize some set operations

This commit is contained in:
Petr Viktorin 2011-04-27 04:34:29 +03:00
parent b2e54ca1ea
commit 0de03e864f

View file

@ -1040,8 +1040,7 @@ class PokemonNode(Node, Facade, namedtuple('PokemonNode',
def expand_forget(self):
cost = self.search.costs['forget']
for move in self.moves_:
if move not in self.search.goal_moves:
for move in self.moves_.difference(self.search.goal_moves):
yield cost, ForgetAction(self.search, move), self._replace(
moves_=self.moves_.difference([move]), new_level=False)
@ -1135,8 +1134,8 @@ class PokemonNode(Node, Facade, namedtuple('PokemonNode',
def expand_sketch(self):
moves = self.moves_
for sketch in moves:
if sketch == self.search.sketch:
sketch = self.search.sketch
if sketch in moves:
for sketched in sorted(self.search.goal_moves):
if sketched in self.search.unsketchable:
continue
@ -1163,12 +1162,6 @@ class PokemonNode(Node, Facade, namedtuple('PokemonNode',
if trade_cost is None:
trade_cost = search.costs['trade'] * 2
return trade_cost
evo_chain = search.evolution_chains[self.pokemon_]
if evo_chain == search.goal_evolution_chain:
breed_cost = 0
else:
breed_cost = search.costs['breed']
return trade_cost + breed_cost
class BaseBreedNode(Node):
"""Breed node