Live data from Hacker News

Show HN: Game where you write Python robots to fight other players

robotgame.org

71–80 of 102 posts

Re: Show HN: Game where you write Python robots to fight other players

#71
post #60
post #56

I was looking through the code and saw someone submitted this but didn't run it: def x(): g = yield yield g.gi_frame.f_back.f_back g = x() g.next() frame = g.send(g) player_id = frame.f_locals['player_id'] globals = frame.f_back.f_globals CODE = """ class Game: def _""" """_init_""" """_(self, *players): pass def run_turn(self): pass def get_game_history(self): return '' def get_scores(self): scores = [0, 0] scores[p…

As pointed out in another subthread, Python code is practically impossible to sandbox. Most competition isolate player code by running it in a separate process which has the additional benefit of easily allowing different implementation languages. Making sure the process doesn't use your network to spread malware is not 100% trivial but still easier than sandboxing Python code within Python. Good luck with your proje…

Seccomp might be a possibility here, but will require one process per live robot (and Linux). With seccomp your process can do nothing but read/write from its file descriptors (so you have to make sure they are safe) but can do nothing more (thus you cannot import modules). So you can exchange messages via file descriptors and otherwise use any Python (or even any other language at all features). Here's one recent article about it: http://pythonsweetness.tumblr.com/post/65442885019/secure-lo...

RestrictedPython, used in zope, is nice too. However it cuts you out of many Python features that it cannot statically validate.

Re: Show HN: Game where you write Python robots to fight other players

#72
post #22

Earlier quoted context omitted.

Or, more notably, Robocode ( http://en.wikipedia.org/wiki/Robocode )

Which was inspired by Robot Battle, in turn inspired by Robot Wars on the Apple II.

I started with Robot Arena (by SPA Publishing) on the RM 380Z in the late 80s. Where's my last comment about this? Ah:-

https://news.ycombinator.com/item?id=4726828

Exactly a year ago! (And no progress at all on that github repository!)

Re: Show HN: Game where you write Python robots to fight other players

#73
post #60
post #56

I was looking through the code and saw someone submitted this but didn't run it: def x(): g = yield yield g.gi_frame.f_back.f_back g = x() g.next() frame = g.send(g) player_id = frame.f_locals['player_id'] globals = frame.f_back.f_globals CODE = """ class Game: def _""" """_init_""" """_(self, *players): pass def run_turn(self): pass def get_game_history(self): return '' def get_scores(self): scores = [0, 0] scores[p…

As pointed out in another subthread, Python code is practically impossible to sandbox. Most competition isolate player code by running it in a separate process which has the additional benefit of easily allowing different implementation languages. Making sure the process doesn't use your network to spread malware is not 100% trivial but still easier than sandboxing Python code within Python. Good luck with your proje…

Another option might be running PyPy within your CPython only for the user scripting parts and switching everything off you don't want.

Re: Show HN: Game where you write Python robots to fight other players

#74
I'm having a lot of fun with this. I'll submit something soon. You swallow all exceptions and make the robot guard instead. This is nice, but it makes it hard to develop, because you can't see what went wrong. Here's a way you can modify it to have your exception and eat it too:

from http://docs.python.org/2/library/traceback.html#traceback-ex...

In game.py, at the top, put

    import sys, traceback
and around line 285, replace this:

    except Exception:
        next_action = ['guard']
with this:

    except Exception:
        print "The robot at (%s, %s) raised an exception:" % robot.location
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60
        next_action = ['guard']

That makes your robot a lot easier to debug. Awesome game, have you thought about putting it on github so people can submit patches?

Re: Show HN: Game where you write Python robots to fight other players

#75
post #64
post #61

Earlier quoted context omitted.

What does this code do?

The problem is that he managed to essentially bypass my jail. He could've wiped my server if he'd wanted.

jailbreaker:jailbreaker

turning down your server is not as much fun as cheating.

shameless plug, I have just worked out a JavaScript class loader[1] of Robocode a few week ago. you don't have to turn security off with this class loader, unlike some approaches suggested on RoboWiki[2]. I'm currently trying to get Jython work with Robocode.

[1]: https://github.com/xiazheteng/robocode-classloaders [2]: http://robowiki.net/wiki/Other_JVM_Languages

Re: Show HN: Game where you write Python robots to fight other players

#77

I'm having a lot of fun with this. I'll submit something soon. You swallow all exceptions and make the robot guard instead. This is nice, but it makes it hard to develop, because you can't see what went wrong. Here's a way you can modify it to have your exception and eat it too: from http://docs.python.org/2/library/traceback.html#traceback-ex... In game.py, at the top, put import sys, traceback and around line 285,…

Wow, great work. Mind if I steal this? And yeah, I'll open-source it pretty soon.

Re: Show HN: Game where you write Python robots to fight other players

#78
post #48

I am working on a marginally similar concept (interface in browser, battles on server) game, but I chose Lua as the scripting language since it is much easier to sandbox. I could not find an effective way to sandbox python for sure, and I am still not 100% on Lua.

Yeah, I considered Lua but I was stubbornly in love with Python. Judging by the responses on here, I seem to have made a mistake. Do you have a link to your project?

I'm not the one you ask for, but I too created a programming game. I thought you might be interested: I used Lua to sandbox the players code. My game allows updating of code during the game is running. The game is split into client/server and it provides a SDL client that can connect to a running game server to show the current state of the game. Players interface with the server using a tcp connection.

http://infon.dividuum.de/

Post reply on HN