Example #1
0
def pick_name():
    while True:
        name = prompt('Username?')
        if name is None:
            pass
        elif name == '':
            return None
        elif not names.is_validname(name):
            print('Name must be between {} and {} characters long.'.format(
                names.MIN_LEN, names.MAX_LEN))
        elif names.has_surr_char(name):
            print('Name cannot have any of these characters: {}'.format(
                names.INVALID_CHARACTERS))
        else:
            return name
Example #2
0
    def __init__(self, name, bank=0, playertype=None):
        if names.is_validname(name):
            self.name = name
        else:
            raise ValueError('Invalid username "{}" for object!'.format(name))

        self.bank = bank

        if playertype is None:
            rnd_type = random_type()
            self.playertype = rnd_type
        else:
            self.playertype = playertype

        self.strategies = None
Example #3
0
def new_player(name):
    """ Create new player in sqlite3 database """
    if not names.is_validname(name):
        return False

    conn = sqlite3.connect(DB)
    c = conn.cursor()

    p = load_player(name)
    result = False
    if not p:
        c.execute('INSERT INTO players VALUES("{}",{})'.format(name, player.HUMAN_BANK_BITS))
        result = True

    conn.commit()
    c.close()
    conn.close()
    return result
Example #4
0
 def test_isvalidname_10char_returnsFalse(self):
     name = 'eriktheguy'
     expected = True
     result = names.is_validname(name)
     self.assertEqual(expected, result)
Example #5
0
 def test_isvalidname_21char_returnsFalse(self):
     name = 'qzqzqzqzqzqzqzqzqzqzz'
     self.assertTrue(len(name) == 21)
     expected = False
     result = names.is_validname(name)
     self.assertEqual(expected, result)
Example #6
0
 def test_isvalidname_20char_returnsTrue(self):
     name = 'qzqzqzqzqzqzqzqzqzqz'
     expected = True
     result = names.is_validname(name)
     self.assertEqual(expected, result)
Example #7
0
 def test_isvalidname_2char_returnsFalse(self):
     name = 'qz'
     expected = False
     result = names.is_validname(name)
     self.assertEqual(expected, result)