def _parse_delta(self, ind, val=None, move=None):
        if self.last_board is None:
            raise Exception("Can't specify a delta: last board is unknown")

        ind = int(ind)
        if val is None:
            if len(self.last_tiles) > 1:
                raise Exception("Can't omit tile value: multiple possible previous tiles")
            val = list(self.last_tiles)[0]
        else:
            val = to_ind(int(val))
            if val not in self.last_tiles:
                raise Exception("New tile wasn't in previous tile set")
            
        if move is None:
            move = self.last_move

        move = movenames.index(move)
        newboard = self.last_board.copy()
        changed = do_move(newboard, move)
        line = get_lines(newboard, move)[ind-1]
        if line[-1] != 0:
            raise Exception("Incorrect changed row/col")
        line[-1] = val
        return newboard
Example #2
0
    def _parse_delta(self, ind, val=None, move=None):
        if self.last_board is None:
            raise Exception("Can't specify a delta: last board is unknown")

        ind = int(ind)
        if val is None:
            if len(self.last_tiles) > 1:
                raise Exception(
                    "Can't omit tile value: multiple possible previous tiles")
            val = list(self.last_tiles)[0]
        else:
            val = to_ind(int(val))
            if val not in self.last_tiles:
                raise Exception("New tile wasn't in previous tile set")

        if move is None:
            move = self.last_move

        move = movenames.index(move)
        newboard = self.last_board.copy()
        changed = do_move(newboard, move)
        line = get_lines(newboard, move)[ind - 1]
        if line[-1] != 0:
            raise Exception("Incorrect changed row/col")
        line[-1] = val
        return newboard
    def make_move(self, move):
        playback_gesture(self.shell, self.ident, move)

        sleeptime = 1.0
        if self.last_board is not None:
            board = self.last_board.copy()
            do_move(board, movenames.index(move))
            top = board.max()
            if sorted(self.last_board.flatten()) == sorted(board.flatten()):
                # No new tiles at all: no flipping or jumping
                sleeptime = 0.5
            elif top <= 3 or list(self.last_board.flatten()).count(top) == list(board.flatten()).count(top):
                # No new high tile created, so no jumping will occur.
                sleeptime = 0.5
            else:
                # The new high tile will jump; wait for a long time for jump animation to finish.
                sleeptime = 1.0

        time.sleep(sleeptime)
Example #4
0
    def make_move(self, move):
        playback_gesture(self.session, move)

        sleeptime = 1.0
        if self.last_board is not None:
            board = self.last_board.copy()
            do_move(board, movenames.index(move))
            top = board.max()
            if sorted(self.last_board.flatten()) == sorted(board.flatten()):
                # No new tiles at all: no flipping or jumping
                sleeptime = 0.5
            elif top <= 3 or list(
                    self.last_board.flatten()).count(top) == list(
                        board.flatten()).count(top):
                # No new high tile created, so no jumping will occur.
                sleeptime = 0.5
            else:
                # The new high tile will jump; wait for a long time for jump animation to finish.
                sleeptime = 1.0

        time.sleep(sleeptime)