Esempio n. 1
0
    def resolve(self, board_pos):
        from reduction.component.atom import Atom

        # Each cell on the Board can only be inhabited by one atom at any given time
        # If there are two atoms in the same space, they must reduce to one

        print "Resolving position", board_pos
        atoms = list(filter(lambda a: isinstance(a, Atom), self.pieces_at(board_pos)))
        voids = list(filter(lambda a: isinstance(a, VoidTile), self.pieces_at(board_pos)))

        while len(atoms) > 1:
            if reductor.can_reduce(*atoms[0:2]):
                for x in atoms[0:2]:
                    self.remove_widget(x)
                atoms = [reductor.reduce_atoms(*atoms[0:2])] + atoms[2:]

        atom = atoms[0]
        if atom.parent is None:
            self.add_widget(atom)

        print self.level_screen
        if len(voids) == 1:
            void = voids[0]
            if void.can_be_completed_by(atom) and all((void.is_complete for void in self.voids)):
                self.parent.parent.parent.process_win()
Esempio n. 2
0
    def on_touch_up(self, touch):
        from reduction.system import reductor
        from reduction.component.board import Board

        if touch.grab_current is self and isinstance(self.parent, Board):
            board_pos = list(self.parent.coords_to_board_pos(touch.pos))

            dp = tuple(map(sub, self.board_pos, board_pos))
            if abs(dp[0]) > abs(dp[1]):
                board_pos[1] = self.board_pos[1]
            else:
                board_pos[0] = self.board_pos[0]

            atoms = list(filter(lambda x: isinstance(x, Atom), self.parent.pieces_at(board_pos)))

            if self.parent.straight_path_clear_between(self.board_pos, board_pos):
                if len(atoms) > 0:
                    print "Can atoms reduce? ", reductor.can_reduce(self, atoms[0])
                    if reductor.can_reduce(self, atoms[0]):
                        self.board_pos = board_pos
                else:
                    self.board_pos = board_pos
            touch.ungrab(self)
            return True