Beispiel #1
0
 def get(self):
     s = header();
     s += validate_form(1)
     s += """
     <table>
     <form action=/bbs/new onSubmit='return valid()' method=post>
     <tr><td align=left>
     <input type=text size=120 name=title title='title'>
     <input type=text name=author title='author'>
     <input type=submit value='start a new thread'>
     </td></tr>
     </form>
     </table>
     <p>
     <table>
     <th width=15%>from</th><th>topic</th><th width=15%>date</th>
     """
     for b in tron_db.BulletinThread.all():
         s += "<tr><td width=15%>" + b.author + ": </td><td><a href=/bbs/thread?id=" + str(b.key().id())+">" + b.title + "</a></td><td width=15%>" + str(b.date) + "</td></tr>\n"
     s += """
     </form>
     </table>
     """
     s += footer()
     self.response.out.write( s )
Beispiel #2
0
 def get(self):
     id = self.request.get("id")
     b = tron_db.BulletinThread.get_by_id(int(id))
     s = header();
     s += validate_form(1)
     s += "<table><th width=15%>"+b.author+":</th><th>"+b.title+"</th><th width=15%>"+str(b.date)+"</th>\n"
     for t in tron_db.BulletinEntry.all().filter('ref =',int(id)):
         s += "<tr><td width=15%>" + t.author + ": </td><td>" + t.text + "</td><td width=15%>" + str(t.date) + "</td></tr>\n"
     s += """
     </table>
     <p>
     <table>
     <tr><td>
     <form action=/bbs/add onSubmit='return valid()' method=post>
     <textarea name=text rows=2 cols=100></textarea></td><td>
     <input type=hidden name=ref value="""+str(id)+""">
     <input type=text name=author title='author'>
     <input type=submit value='add an entry'>
     </form>
     </td>
     </tr>
     </table>
     """
     s += footer()
     self.response.out.write( s )
Beispiel #3
0
 def get(self):          
     map_name = self.request.get("maps")
     player1 = self.request.get("player1")
     player2 = self.request.get("player2")
     player_code = self.request.get("code").replace('\r','')
     if not player_code: 
         player_code = "def turn(b,r,c):"+'\n'+"  return 'E'";
     self.response.out.write( header() )
     pl = tron_db.Program.all().fetch(50)
     mp = tron_db.Map.all().fetch(50)
     s = "<b>play an (unranked) match. it's you against the machine, or bot vs bot</b><p>"
     s += "<form action=/play>"
     s += "<textarea rows=10 cols=90 name=code>"+player_code+"</textarea><br>"
     s += "<select name=player1 title=player1>"
     if player1:
         s += "<option>" + player1 + "</option>\n"
     s += "<option> ME </option>\n"
     for p in pl:
         s += "<option>" + p.name + "</option>\n"
     s += "</select>"
     s += "<select name=player2 title=player2 >"
     if player2:
         s += "<option>" + player2 + "</option>\n"
     for p in pl:
         s += "<option>" + p.name + "</option>\n"
     s += "<option> ME </option>\n"
     s += "</select>"
     s += "<select name=maps title=map>"
     if map_name:
         s += "<option>" + map_name + "</option>\n"
     for m in mp:
         g,r,c,p = tron.parse_map(m.text)
         if p == 2:
             s += "<option>" + str(m.key().name()) + "</option>\n"
     s += "</select>&nbsp;&nbsp;"
     s += "<input type=submit value='play a game'>"
     s += "</form>"
     if map_name and player1 and player2:
         map = tron_db.Map.get_by_key_name(map_name)
         if player1=="ME" and player_code: 
             pl1 = tron_db.Program(text=player_code,name=player1)
         else: 
             pl1 = tron_db.Program.all().filter("name",player1).get()
             
         if player2=="ME" and player_code: 
             pl2 = tron_db.Program(text=player_code,name=player2)
         else: 
             pl2 = tron_db.Program.all().filter("name",player2).get()
         if map and pl1 and pl2:
             g = tron.Game()
             playgame(g,[pl1,pl2],map.text, map_name)
             plan = [player1,player2]
             hist = [g.players[0]['hist'],g.players[1]['hist']]
             rank = [g.players[0]['score'],g.players[1]['score']]
             s += drawReplay(42,plan,hist,g.errors,rank,map_name,map.text,g.turn )
         else:
             logging.warn("invalid setup " + str(map) + " " + str(pl1) + " " + str(pl2))
     self.response.out.write( s )
     self.response.out.write( footer() )
Beispiel #4
0
 def get(self):          
     offs = get_offset(self.request)
     query = tron_db.Program.all().order('rank')
     count = query.count()
     self.response.out.write(  header() )
     self.response.out.write( "<p><table>" )
     self.response.out.write( tron_db.Program_head )
     for i,r in enumerate(query.fetch(TABSIZE,offs)):
         self.response.out.write( r.html() )
     self.response.out.write( "</table>" + "<p>" + table_pager("/bots/",count) + "<p>" )
     self.response.out.write( footer() )
Beispiel #5
0
    def get(self):          
        #~ keys =  tron_db.GameInfo.all(keys_only=True).order('-date').fetch(TABSIZE, offs)
        offs = get_offset(self.request)
        order = tron_db.GameInfo.all().order('-date')
        count = order.count()
            
        self.response.out.write(  header(title="latest games" ) )
        game_table(self.response, order.fetch(TABSIZE, offs) )

        self.response.out.write( "<p>" + table_pager( "/games/", count) + "<p>" )
        self.response.out.write( footer() )
Beispiel #6
0
 def get(self):          
     key = self.request.get("key")
     if not key:
         self.response.out.write( sorry_404("map " + key) )
         return
     m = tron_db.Map.get_by_key_name( key )
     
     self.response.out.write( header(m.key().name() + " by " + m.author) )
     self.response.out.write( "<pre>" )
     self.response.out.write( "\n" + m.text )
     self.response.out.write( "</pre>" )
     self.response.out.write( footer() )
Beispiel #7
0
 def get(self):         
     user=self.request.get("name")
     p = tron_db.Program.all().filter("name",user).get()
     if not p:
         self.response.out.write( sorry_404("botcode for " + user) )
         return
     self.response.out.write( header("SourceCode for '" + user + "'") )
     self.response.out.write( "<br><p>" )
     self.response.out.write( "<pre>" )
     self.response.out.write( p.text )
     self.response.out.write( "</pre>" )
     self.response.out.write( "<br>" )
     self.response.out.write( footer() )
Beispiel #8
0
 def post(self):          
     author = self.request.get("author")
     name = self.request.get("name")
     text = self.request.get("text")
     try:
         g,r,c,p = tron.parse_map(text)
     #~ except Exception, e:
          #~ self.response.out.write( header() + "your map was rejected("+str(e)+")" + footer() )
     except :
          self.response.out.write( header() + "your map was rejected()" + footer() )
          return
     if author and name and text:
         m = tron_db.Map(key_name=name, text=text, author=author)
         m.put()
     self.redirect("/maps/")
Beispiel #9
0
    def get(self):
        res = header("submit a bot to the competition")
        res += validate_form(1)
        res += """
        <br>
        <table width=90%><tr><td>
        <form name='upload' action='/up/load' method=post enctype='multipart/form-data' onsubmit='return valid();'>
        <!--form name='upload' action='/up/load' method=post enctype='multipart/form-data'-->
        <textarea name='text' rows='30' cols='60' title='your code goes here'>def turn(board,r,c): """+'\n    '+"""return "N"</textarea>
        <br>
        <input name='name' title='botname'> &nbsp; &nbsp; &nbsp; &nbsp;
        <input type='submit' value='  upload  your   bot  '>
        </td><td valign=top>
        <br>
        First of all: it's <a href='http://python.org'>Python</a> only, sorry for that<p>
        A single function 'turn(board,r,c)' is called in each step,<br>
        you are given the board(as a row-column grid[][]), and the position of your bot.<br>
        you return the direction of your next move, one of ["N","E","S","W"] <p>
        you'll die, if you<ul><li> hit a wall('#')<li>walk onto your own tail, or into another player('1','2','3',etc)</ul>
        note, that since your code is running in a separate namespace,<br>
        you'll have to address non-const global vars as 'global'<p>
        some snippets:
        <pre>
        // roundabout
        t = 0
        DIRS=["N","E","S","W"]       
        def turn(board,r,c):
            global t
            t += 1
            t %= 4
            return DIRS[t]
            

        STEPS={'N':[-1,0],'S':[1,0],'E':[0,-1],'W':[0,1]};       
        def walk(r,c,dir): 
           return r+STEPS[dir][0], c+STEPS[dir][1]
           
        def passable(board,r,c): 
            if r<0 or c<0 or (r >= len(board)) or (c >= len(board[0])) or board[r][c] != ' ':
                return False
           
        </pre>
        </td></tr></table><br>
        """
        res += footer()
        self.response.out.write(res)		
Beispiel #10
0
 def get(self):         
     user=self.request.get("name")
     if not user:
         self.response.out.write( sorry_404("user " + user) )
         return
     r = tron_db.Program.all().filter("name",user).get()
     self.response.out.write( header("Profile for '" + user + "'") )
     self.response.out.write( "<table>" )
     self.response.out.write( tron_db.Program_head )
     self.response.out.write( r.html() )
     self.response.out.write( "</table></div>" )
     self.response.out.write( "<br>" )
     query = tron_db.GameInfo.all().filter("players in", [user])
     offs = get_offset(self.request)
     game_table( self.response, query.order('-date').fetch(TABSIZE,offs) )
     self.response.out.write( table_pager( "/games/",query.count()) + "<p>" )
     self.response.out.write( footer() )
Beispiel #11
0
 def get(self):           
     key = self.request.get("key")
     try:
         w = self.request.get("w")
         h = self.request.get("h")
     except:
         pass
     if not w : w=400
     if not h : h=400
     game = tron_db.GameInfo.get_by_id(int(key))
     if not game:
         self.response.out.write( sorry_404( "game " + key ) )
         return
         
     s  = header()
     map = tron_db.Map.get_by_key_name(game.mapname)
     s += drawReplay(key,game.players,game.history,game.errors,game.rank,game.mapname,map.text,game.turn,w,h)
     s += footer()
     self.response.out.write( s )
Beispiel #12
0
 def get(self):           
     s = header();
     name = self.request.get("name")
     if not name : return
     res = tron_db.Program.all().filter("name >=",name).filter("name <", name + u'\ufffd')
     #~ res = tron_db.Program.all().filter("name =",name)
     nr = res.count()
     if nr == 1:
         z = res.get()
         self.redirect( "/bots?name="+z.name)
         return
     elif nr > 1:
         s += "found " + str(nr) + " bots named like '" + name + "'.<ul>"
         for z in res:
             s += "<li><a href=/bots?name="+z.name+"> " + z.name + " </a><br>"                
         s += "</ul>"
     else:
         s += "sorry, there is no bot named '" + name + "\'."
     s += footer()
     self.response.out.write( s )
Beispiel #13
0
 def get(self):   
     s = header();
     s += """
     <br><p><h3>Welcome to <a href='https://github.com/berak/tron-gae/' title='da source'>Tron reloaded</a>!</h3>
     It's a small programming competition for bots written in <a href='http://python.org'>Python</a>,<br>
     inspired by the <a href ='http://csclub.uwaterloo.ca/contest'>google ai tron contest</a>,
     and the <a href='http://www.rpscontest.com'>rock-paper-scissors competition</a>.<p>
     Just <a href='/up/form'>submit your bot</a> to the competition, or <a href=/play> code live </a> against the bots on this server.<br>
     You can update (or submit another bot) as often as you like. <br>
     Bots that caused more than 50 crashes or timeouts will see their source code exposed,<br>
     whenever you update though, your bot will start from scratch.<p><br><br>
     Watch the latest game:&nbsp;
     """
     
     game = tron_db.GameInfo.all().order("-date").get()
     map = tron_db.Map.get_by_key_name(game.mapname)
     s += "<a href=/viz?key="+str(game.key().id())+">"+str(game.key().id()) +"</a><div  onBlur='javascript:stop()'>"
     s += drawNaked(game.players,game.history,map.text,game.turn,200,200 )
     s += "</div>"
     s += footer()
     self.response.out.write( s )
Beispiel #14
0
 def get(self):          
     s  = header( "maps" )
     s += validate_form(1)
     s += """
     <form action=/maps/up method=post enctype='multipart/form-data' onSubmit="return valid()">
     <table>
     <tr>
     <td width=20%>
     Map Author <br>
     <input type=text name='author' title='author'> <br><br>
     Map Name <br>
     <input type=text name='name' title='name'> <br><br><br><br><br>
     <input type=submit value='upload another map'>
     </td>
     <td halign=top>
     <textarea name='text' rows=10 cols=60 title='paste your map here'></textarea>
     </td>
     <td> 
     only the following chars are allowed:
     <pre>
     wall char  : '#' 
     free space : ' ' 
     players    : ['1','2','3','4'] 
     </pre>
     maps can have up to 500 walkable fields(the max size of the history for a player).<br>
     please come up with something symmetric, that gives equal chances for each player.<br>
     </td>
     </table >
     </form>
     <table border=0 width=90%>
     """
     for m in tron_db.Map.all():
         s += m.html()
     s += "</table>"
     s += footer()
     self.response.out.write( s )
Beispiel #15
0
    def post(self):
        s = header();

        name = self.request.get("name")
        text  = self.request.get("text").replace('\r\n','\n')
        py = tron_db.Program.all().filter("name", name).get()
        if not py: 
            py = tron_db.Program( name=name )
        py.text = text
        py.reset(worker.TS_MU)
        
        try :
            #~ compile(py.code,py.title,'exec')
            game = tron.Game()
            game.readmap(test_map)
            game.add_player( py.text, py.name )
            game.run()
            if not game.errors[0]:
                py.put()
                s += "SUCCESS ! "+py.name+" is going to play soon !"
            else:
                s += "FAIL! "+py.name+" caused an error:&nbsp;&nbsp;&nbsp; '" + game.errors[0] + "\'"
        except Exception, e:
            s += "FAIL! "+py.name+" caused an exception:&nbsp;&nbsp;&nbsp; '" + str(e) + "\'"
Beispiel #16
0
 def post(self):
     s = header();
     b = tron_db.BulletinThread( title=self.request.get("title"), author=self.request.get("author"))
     b.put()
     self.redirect( "/bbs/thread?id="+str(b.key().id()) )
Beispiel #17
0
 def post(self):
     s = header();
     ref=self.request.get("ref")
     e = tron_db.BulletinEntry( ref=int(ref), text=self.request.get("text"), author=self.request.get("author"))
     e.put()
     self.redirect( "/bbs/thread?id="+str(ref) )