Ejemplo n.º 1
0
def TestUpdate(device, old_apk, new_apk, app_data, package_name):
    device.Install(old_apk)
    device.adb.Restore(app_data)
    # Restore command is not synchronous
    raw_input('Select "Restore my data" on the device. Then press enter to '
              'continue.')
    if not device.IsApplicationInstalled(package_name):
        raise Exception('Expected package %s to already be installed. '
                        'Package name might have changed!' % package_name)

    logging.info('Verifying that %s can be overinstalled.', new_apk)
    device.adb.Install(new_apk, reinstall=True)
    logging.critical('Successfully updated to the new apk. Please verify that '
                     'the application data is preserved.')
Ejemplo n.º 2
0
def start_game():
    again = True
    while (again):
        clr_screen()
        try:
            mapsize = int(input('Map size? '))
        except ValueError:
            mapsize = 10
        game_map = gen_empty_map(mapsize)
        populate_map(game_map)
        raw_input(game_loop.__doc__)
        game_loop(game_map)
        while (again not in ('y', 'n')):
            again = raw_input('Play again? (y/n) ').lower()
        again = True if (again == 'y') else False
Ejemplo n.º 3
0
 def get_confirmation(self, template, yes_char='y', no_char='n'):
     template = '{} [{}/{}] '.format(template, yes_char, no_char)
     while True:
         value = raw_input(template)
         if value == yes_char:
             return True
         elif value == no_char:
             return False
Ejemplo n.º 4
0
    def get_confirmation(self, template, yes_char='y', no_char='n'):

        # stdlib
        from builtins import input as raw_input

        template = '{} [{}/{}] '.format(template, yes_char, no_char)
        while True:
            value = raw_input(template)
            if value == yes_char:
                return True
            elif value == no_char:
                return False
Ejemplo n.º 5
0
def ask(question, default=True, exact=False):
    """Ask the question in y/n form and return True/False.

    If you don't want a default 'yes', set default to None (or to False if you
    want a default 'no').

    With exact=True, we want to get a literal 'yes' or 'no', at least
    when it does not match the default.

    """
    while True:
        yn = "y/n"
        if exact:
            yn = "yes/no"
        if default is True:
            yn = yn.replace("y", "Y")
        if default is False:
            yn = yn.replace("n", "N")
        q = "{0} ({1})? ".format(question, yn)
        input = raw_input(q)
        if input:
            answer = input
        else:
            answer = ""
        if not answer and default is not None:
            return default
        if exact and answer.lower() not in ("yes", "no"):
            print("Please explicitly answer yes/no in full " "(or accept the default)")
            continue
        if answer:
            answer = answer[0].lower()
            if answer == "y":
                return True
            if answer == "n":
                return False
        # We really want an answer.
        print("Please explicitly answer y/n")
        continue
Ejemplo n.º 6
0
def CreateAppData(device, old_apk, app_data, package_name):
    device.Install(old_apk)
    raw_input('Set the application state. Once ready, press enter and '
              'select "Backup my data" on the device.')
    device.adb.Backup(app_data, packages=[package_name])
    logging.critical('Application data saved to %s', app_data)
Ejemplo n.º 7
0
 def input(prompt=''):
     return builtin_mod.raw_input(prompt)
Ejemplo n.º 8
0
 def input(prompt=""):
     return builtin_mod.raw_input(prompt)
Ejemplo n.º 9
0
    def read(self, mode='train', batch=1):
        """
        Default implementation for read() function.
        Supports batch reading & random shuffling.
        """
        if self.mode != mode:
            self.mode = mode
            index = 0

        # end of data , reset index & return None
        if self.index >= len(self.data[mode]):
            data = None
            self.index = 0
            # shuffle data except for testing
            if mode != 'test':
                random.shuffle(self.data[mode])
            return data

        # reading a batch
        start = self.index
        end = self.index + batch \
            if self.index + batch < len(self.data[mode]) \
            else len(self.data[mode])
        data = self.data[mode][start:end]
        self.index += batch

        # post processing data: a,sv,s,v,sent,dact,base
        proc_data = [[], [], [], [], [], [], []]
        max_leng = [0, 0, 0, 0, 0]
        for feat, dact, sent, base in data:
            a, sv, s, v = self.gen_feat_vec(feat, self.cardinality, self.dfs)
            # testing case,
            if mode == 'test':
                sent = [
                    self.lexicalise(sent[i], dact) for i in range(len(sent))
                ]
                base = [
                    self.lexicalise(base[i], dact) for i in range(len(base))
                ]
                # put in container
                xvec = [a, sv, s, v, sent, dact, base]
                for j in range(len(proc_data)):
                    proc_data[j].append(xvec[j])
            else:
                # delexicalised text & formatted feature
                if self.obj == 'ml':  # ML training, 1 sent per example
                    sent = self.delexicalise(sent, dact)
                    sent = self.gen_input_sent(sent, self.vocab)
                    # put in container
                    xvec = [a, sv, s, v, sent, dact, base]
                    for j in range(len(proc_data)):
                        proc_data[j].append(xvec[j])
                    # padding length
                    for j in range(0, 5):
                        if len(xvec[j]) > max_leng[j]:
                            max_leng[j] = len(xvec[j])
                else:  # TODO:DT training, 1 da/multiple sents per example
                    print(a, sv)
                    print(sent)
                    raw_input()
        # padding to have the same sent length
        lengs = [[], [], [], [], []]
        if mode != 'test':  # if testing set, not need to process sentence
            for i in range(0, 5):
                for j in range(len(proc_data[i])):
                    lengs[i].append(len(proc_data[i][j]))
                    proc_data[i][j].extend(
                        [-1] * (max_leng[i] - len(proc_data[i][j])))
        # padding to have the same batch size
        for x in range(end - start, batch):
            for i in range(0, 5):
                proc_data[i].append(proc_data[i][-1])
                lengs[i].append(len(proc_data[i][-1]))
        # input/output
        a, sv, s, v = np.array(proc_data[0], dtype=np.int32), \
                      np.array(proc_data[1], dtype=np.int32), \
                      np.array(proc_data[2], dtype=np.int32), \
                      np.array(proc_data[3], dtype=np.int32)
        if mode != 'test':
            words = np.swapaxes(np.array(proc_data[4], dtype=np.int32), 0, 1)
        else:
            words = proc_data[4]
        dact = proc_data[5]
        base = proc_data[6]
        # current batch size
        b_size = end - start
        lengs = np.array(lengs, dtype=np.int32)

        return a, sv, s, v, words, dact, base, b_size, lengs
Ejemplo n.º 10
0
def raw_input(prompt=None):
    if prompt:
        sys.stderr.write(str(prompt))
        return builtins.raw_input()
Ejemplo n.º 11
0
def game_loop(game_map):
    '''Input "exit" or "quit" to stop playing.
Input "w", "a", "s", "d" for movement.
Input "stat", "stats" or "status" to show player status.
Input "j" to jump for a turn if you have the ability.
Input "q" to shield up if you have a shield.
Input "e" to show inventory.
Input "f" to cast ring of fire around player.
Input "help" to show this again.
'''
    tut = game_loop.__doc__

    # STATS AND VARS
    #################
    n = len(game_map)
    cmd = ''
    msg = ''
    win = False
    pc = Player()
    box_coords = ((pc.x - 1, pc.y - 1), (pc.x, pc.y - 1), (pc.x + 1, pc.y - 1),
                  (pc.x - 1, pc.y), (pc.x + 1, pc.y), (pc.x - 1, pc.y + 1),
                  (pc.x, pc.y + 1), (pc.x + 1, pc.y + 1))
    #################

    while (cmd not in AUTHORIZED_CMD[:2]):
        ################################## Clear the screen at the beginning of every loop
        clr_screen()
        ############################### Variable and stats setup/reset every loop
        print_map(game_map, pc.x, pc.y, pc.icon)
        print(msg)
        msg = ''
        mvmt = pc.movlen + pc.jmp
        pc.jmp = 0
        pc.shield = False
        pc.pts = pc.hp + pc.gold + pc.kills + pc.lives + pc.luck
        ################################################## User input
        cmd = raw_input('>> ').lower()
        ############################## Input processing
        if (cmd == 'help'):
            clr_screen()
            raw_input(tut)
            continue
        elif (cmd == 'print'):
            raw_input("%d,%d" % (pc.x, pc.y))
            continue
        elif (cmd in AUTHORIZED_CMD[4:7]):
            msg += 'HP: ' + str(pc.hp) + ' | Mana: ' + str(pc.mp) + ' | Gold: '
            msg += str(pc.gold) + ' | Lives: ' + str(pc.lives) + ' | Deaths: '
            msg += str(pc.deaths) + ' | Kills: ' + str(
                pc.kills) + ' | Points: '
            msg += str(pc.pts) + ' | Movement length: ' + str(pc.movlen)
            msg += ' | Jump: ' + str(pc.jmp) + ' | Shield: ' + str(pc.shield)
            #msg += ' | Luck: ' + str(luck)
            continue
        elif (cmd
              == 'w') and (pc.y - mvmt >= 0) and (game_map[pc.y - mvmt][pc.x]
                                                  is not Terrain.Unwalk):
            pc.y -= mvmt
        elif (cmd
              == 'a') and (pc.x - mvmt >= 0) and (game_map[pc.y][pc.x - mvmt]
                                                  is not Terrain.Unwalk):
            pc.x -= mvmt
        elif (cmd
              == 's') and (pc.y + mvmt < n) and (game_map[pc.y + mvmt][pc.x]
                                                 is not Terrain.Unwalk):
            pc.y += mvmt
        elif (cmd
              == 'd') and (pc.x + mvmt < n) and (game_map[pc.y][pc.x + mvmt]
                                                 is not Terrain.Unwalk):
            pc.x += mvmt
        elif (cmd == Keybinding.Jump):
            if (Keybinding.Jump.upper() in pc.inv):
                pc.jmp = 1
                msg += 'You can now jump. '
            else:
                msg += 'You do not possess the ability to jump. '
            continue
        elif (cmd == Keybinding.Shield):
            if ('S' in pc.inv):
                pc.shield = True
                msg += 'Shielded. '
            else:
                msg += 'No shield. '
            continue
        elif (cmd == Keybinding.Inventory):
            msg += str(pc.inv)
            continue
        elif (cmd == Keybinding.RingOfFire):
            if (Keybinding.RingOfFire.upper() in pc.inv):
                pc.mp -= 5
                for area in box_coords:
                    if (0 <= area[0] < n) and (0 <= area[1] < n) and (
                            game_map[area[1]][area[0]] == Terrain.Monster):
                        game_map[area[1]][area[0]] = Terrain.Walk
            else:
                msg += 'You do not possess a Ring of Fire. '
        elif (cmd == '') or (cmd.count(' ') is len(cmd)):
            #~ continue
            if (pc.luck > 0): pc.luck -= 1
        else:
            msg += 'Invalid input. '
        ############################ Events depending on current block position
        curpos = game_map[pc.y][pc.x]

        if (curpos == Terrain.Win):
            clr_screen()
            raw_input("You have won the game!\nHere are your points: " +
                      str(pc.pts))
            break
        elif (curpos == Terrain.Fire):
            pc.hp -= 1
            msg += 'You lost 1 hp by fire damage. '
            if (randint(0, 10 + pc.luck) >= 10):
                pc.inv.append(Keybinding.RingOfFire.upper())
                msg += 'You now possess a Ring of Fire. Input "' + Keybinding.RingOfFire + '" to use. Costs 5 mana per use. '
        elif (curpos == Terrain.Heal):
            if (randint(-1, 1 + pc.luck) < 1): hpgain = 1
            else: hpgain = 1 + pc.luck // 5
            pc.hp += hpgain
            game_map[pc.y][pc.x] = Terrain.Walk
            msg += 'You have gained ' + str(hpgain) + ' hp. '
        elif (curpos == Terrain.Jump):
            pc.inv.append(Keybinding.Jump.upper())
            game_map[pc.y][pc.x] = Terrain.Walk
            msg += 'You now possess the ability to jump. Input "' + Keybinding.Jump + '" and then the direction to use. '
        elif (curpos == Terrain.Point):
            pc.pts += 2
            game_map[pc.y][pc.x] = Terrain.Walk
            msg += 'You have gained 2 points. '
        elif (curpos == Terrain.Monster):
            if (pc.shield):
                dmg = randint(0, (1 // pc.luck + 1))
            else:
                dmg = randint(0, (1 // pc.luck + 1) * 2)
            pc.hp -= dmg
            msg += 'You attacked a monster and have lost ' + str(dmg) + ' hp. '
            if (randint(-1, pc.luck + 1) > 0):
                game_map[pc.y][pc.x] = Terrain.Walk
                msg += 'The monster died. '
        elif (curpos == Terrain.Life):
            pc.lives += 1
            game_map[pc.y][pc.x] = Terrain.Walk
            msg += 'You have gained a life. '
        elif (curpos == Terrain.Shield):
            pc.inv.append('S')
            game_map[pc.y][pc.x] = Terrain.Walk
            msg += 'You have gained a shield. Input "' + Keybinding.Shield + '" to enter shield stance for a turn. '

        if (randint(0, 50 + pc.luck) is 0):
            game_map[pc.y][pc.x] = Terrain.Unwalk
            msg += 'The ground at your feet feels shaky. '

        ################################################## Death and permanent death
        if (pc.hp is 0):
            clr_screen()
            pc.die()
            raw_input('You died.')
            if (pc.lives is 0):
                raw_input("GAME OVER\nHere are your points: " + str(pc.pts))
                break
        #################################################################### Innate HP and mana regen
        if (pc.mp < 20) and (pc.luck > randint(0, pc.luck // 2)):
            pc.mp += randint(0, 2)
        if (pc.hp < 20) and (pc.luck > randint(0, pc.luck // 2)):
            pc.hp += randint(0, 2)
        ##################################

    return 0