Example #1
0
 def get(self):
     ''' this signup module will receive ajax call from lobby.html  '''
     # read given user id and password 
     # create User object defined in datastore.py
     # assign usr id and password and save it
     # send back success message
     print >>sys.stderr, "Sign up process start"
     namePattern = re.compile(r"[a-zA-Z][a-zA-Z0-9]{2,16}$")
     id = self.request.get('id')
     if namePattern.match(self.request.get('id'))==None:
         self.response.out.write("User name(3~16 characters) should contain only alphabets and numbers(not for the first character).")
         return
     existingUser = db.GqlQuery("SELECT * FROM User WHERE id=:1",id).get()
     if existingUser:
         self.response.out.write(id+" already exists. Try a different name please.")
         return
     user = User(key_name=id,
                 id = id,
                 email = self.request.get('email'),
                 type = 'user',
                 password = self.request.get('password'),
                 botKind = self.request.get('botKind'),
                 botName = self.request.get('botName'),
                 score = 0)            
     result = user.put()         
     print >>sys.stderr, result       
     if result:
         AI(key_name=id+"_tictactoe",
                     user = id,
                     game = "tictactoe").put()
         TicTacToe.activateBuiltInRuleByTitle(id, 'Take Random')
         self.sess = sessions.Session()
         self.sess['loggedInAs'] = user.id;
         self.response.out.write("yes")  
         return
     else: 
         self.response.out.write("no")  
         return       
Example #2
0
def initSampleData():
    clearAll()
    Game(title='tictactoe',key_name='tictactoe').put()
    Rule(title='Win',definition='takeWin',description='Take a cell completing three of my stones in a row/column/diagonal',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Block Win',definition='takeBlockWin',description='Take a cell of the opponent winning position',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Take Center',definition='takeCenter',description='Take the center cell',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Take Any Corner',definition='takeAnyCorner',description='Take any corner',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Take Any Side',definition='takeAnySide',description='Take any non-corner cells on the side.',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Take Random',definition='takeRandom',description='Take any empty cell.',author='built-in',rule_type='built-in',game='tictactoe').put()
    Rule(title='Take Opposite Corner',definition='takeOppositeCorner',description='Take a corner cell if its opposite corner is occupied by another player',author='built-in',rule_type='built-in',game='tictactoe').put()
    

    User(id='easy',password='******',type='system',botKind='bot_1',botName='easyBot',email='*****@*****.**',score=0,key_name='easy').put()
    User(id='moderate',password='******',type='system',botKind='bot_2',botName='moderateBot',email='*****@*****.**',score=0,key_name='moderate').put()
    User(id='hard',password='******',type='system',botKind='bot_3',botName='hardBot',email='*****@*****.**',score=0,key_name='hard').put()    

    AI(user='******',game='tictactoe',key_name='easy_tictactoe').put()
    AI(user='******',game='tictactoe',key_name='moderate_tictactoe').put()
    AI(user='******',game='tictactoe',key_name='hard_tictactoe').put()
    TicTacToe.activateBuiltInRuleByTitle('easy', 'Take Random')
    TicTacToe.activateBuiltInRuleByTitle('easy', 'Take Any Corner')
    TicTacToe.activateBuiltInRuleByTitle('easy', 'Win')
    TicTacToe.activateBuiltInRuleByTitle('moderate', 'Take Random')
    TicTacToe.activateBuiltInRuleByTitle('moderate', 'Take Any Corner')
    TicTacToe.activateBuiltInRuleByTitle('moderate', 'Block Win')
    TicTacToe.activateBuiltInRuleByTitle('moderate', 'Win')    
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Take Random')
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Take Any Side')
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Take Any Corner')
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Take Center')
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Block Win')
    TicTacToe.activateBuiltInRuleByTitle('hard', 'Win')
    
    TournamentWinners(winner='None').put()