Live data from Hacker News

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

robotgame.org

81–90 of 102 posts

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

#81
post #9

Similar to crobots ( http://en.wikipedia.org/wiki/Crobots ).

So, has anyone compiled a list of these types of software?

Because it feels like there's some space for i) Something that can run on RPi for youth to learn programming and ii) a bi-monthly competition for HN, with rankings (most victories, smallest code with at least one win etc).

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

#82
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'll post to link to it on HN probably tomorrow (theoretically will be finished then...).

The main difference is you write the AI for one of your units, but that AI is applied to many units, so you must write an AI that can interact with itself.

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

#83
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…

Seattle[1] includes an attempt to sandbox Python. No idea if it's 100% covered, but they try.

[1]: https://seattle.poly.edu/wiki

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

#85
post #18

Brandon - what methods are you using to run untrusted Python code in a secure sandbox?

Right now what I'm doing is: 1. search code for double underscores (to block magic methods) 2. replace `__builtins__` with a whitelisted version 3. hook `__import__` to only allow a whitelist 4. hook `getattr` to reject any key containing double underscores

You might also want to consider using a sandbox/jail such as AppArmor, to prevent the Python (sub)process itself from accessing any resources should those methods fail.

I came across a project called CodeJail, which seems to help configure Python (or other scripting languages) nicely with AppArmor, to help execute untrusted code in a safe(r) manner: https://github.com/edx/codejail

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

#87
post #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.

Not at all.

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

#89
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?

The Google AI challenges had the bots communicate over stdin and stdout with the game server meaning they could be programmed in any language.

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

#90
I've been working on a similar concept off and on for a few years. To avoid all the security problems you're having, I've written a virtual machine that emulates a CPU and 64k of RAM. Instead of submitting code, you submit a 64k memory image of robot byte code.

Every turn of the game involves running a single cycle of the virtual CPU for every robot. Conceptually, the robots have radios and weapons that are controlled via memory-mapped IO in the virtual machine.

Things are slightly more complex than that because you don't want to give the first robot in the cycle an advantage (especially if they're firing lasers at each other), so you have to do each turn in multiple stages (run cycle, resolve real-world effects, update robot sensor state)

I'd LOVE to collaborate with a group of people to get something like this going because I think this would be a great way to introduce kids to programming at a machine level/electrical engineering. If anyone is interested, please send me an email. You can find my address in my profile.

Post reply on HN