Example #1
0
    def find_gap_for_moveable(self, moveable):
        moveable_card = self.card_at(moveable)
        if moveable_card.rank == Ranks.TWO:
            gaps = [g for g in self.find_gaps() if g[1] == 0]
            return gaps[0]
        else:
            target_loc = self.find_card(Card(moveable_card.suit,
                    Ranks.lower_rank(moveable_card.rank)))

            target_loc = (target_loc[0], target_loc[1]+1)
            return target_loc
Example #2
0
    def find_moveable_for_gap(self, gap):
        if gap[1] == 0:
            twos = [pos for pos in self.find_by_rank(Ranks.TWO) if pos[1] > 0]
            return twos[0]

        neighbour = self.card_at((gap[0], gap[1]-1))
        loc = None
        if neighbour != None and neighbour.rank != Ranks.KING:
            loc = self.find_card(Card(neighbour.suit,
                Ranks.higher_rank(neighbour.rank)))
        return loc
Example #3
0
 def find_moveable(self):
     gaps = self.find_gaps()
     moveable = []
     for g in gaps:
         if g[1] == 0:
             twos = self.find_by_rank(Ranks.TWO)
             for two in twos:
                 if not two[1] == 0:
                     moveable.append(two)
         else:
             neighbour = self.card_at((g[0], g[1]-1))
             if neighbour != None and neighbour.rank != Ranks.KING:
                 next_rank = Ranks.higher_rank(neighbour.rank)
                 moveable_card = Card(neighbour.suit, next_rank)
                 moveable_loc = self.find_card(moveable_card)
                 moveable.append(moveable_loc)
     return moveable