Live data from Hacker News

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

robotgame.org

91–100 of 102 posts

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

#91
post #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 controlle…

That sounds like the much more fully developed version of what I have that I'd like to get to someday. I'm down for that collaboration thing. Let's get a group started.

The radios you mentioned are something I'd like to have someday. I think what makes games like these cool is the fact that your code controls an army of robots. It's more fun than just having two robots duel it out.

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

#92
post #91
post #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 controlle…

That sounds like the much more fully developed version of what I have that I'd like to get to someday. I'm down for that collaboration thing. Let's get a group started. The radios you mentioned are something I'd like to have someday. I think what makes games like these cool is the fact that your code controls an army of robots. It's more fun than just having two robots duel it out.

That's what I was thinking too; instead of a one-on-one, what if you could have 10-100 bots that operated with different strategies and worked together? I think it would so cool to have multiple teams of players all competing at once.

Sort of a programmable MMO/RTS, where the fun would be the strategy development and extra-game political aspects.

Where I'm getting hung up is on the exact game mechanics; I want to make it so the simulation runs for a long time, but I don't want a single player or team able to develop an insurmountable advantage. I'm thinking to start you get a robot in a sandbox world where it would gather resources and you could test strategies, and when you're ready you can transport the bot to the real world to compete.

I was writing this in C++ so the memory overhead per robot was just barely over 64k. A server with 8gigs of RAM could run a simulation in memory with about 100,000 bots, periodically saving the game state to disk in case of a failure.

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

#93
post #18

Earlier quoted context omitted.

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

Is this python 2 or 3? Your description said that you didn't allow underscores, but if this is python 2, people would still be able to run threads (threads were renamed _thread in python 3).

Same question here. I am a total novice to Python, so it might be a stupid question. When I launch with python2.6 it does not find the RestrictedPython package. If I launch with Python 3.2 then it complains about the "print" syntax.

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

#94
post #12
post #7

interesting! Question regarding the security restrictions - why disable built-ins such as `all`, `set`, `list`, `enumerate`, `min`, `sum`, `sorted`, etc?

To be honest I copied it from `safe_builtins` from RestrictedPython: https://pypi.python.org/pypi/RestrictedPython I realize this is annoying, and ideally I shouldn't even be doing this. It was just a quick hack for the version 1. I'll probably try to run user scripts in something like Docker. Any suggestions would be appreciated.

Docker is a bit overkill; just use what it's built on, Linux containers. `sudo lxc-unshare -s "NETWORK|PID" sudo -u nobody python script.py` will do the trick for you. (all one command--the first sudo to make you root, so you can create a new container; the second sudo to make the user inside the container unprivileged)

You'll need to communicate with the Python script using IPC.

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

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

Id run in docker containers or zerovm. You _cannot_ sandbox Python.

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

#96
post #12

Earlier quoted context omitted.

To be honest I copied it from `safe_builtins` from RestrictedPython: https://pypi.python.org/pypi/RestrictedPython I realize this is annoying, and ideally I shouldn't even be doing this. It was just a quick hack for the version 1. I'll probably try to run user scripts in something like Docker. Any suggestions would be appreciated.

Docker is a bit overkill; just use what it's built on, Linux containers. `sudo lxc-unshare -s "NETWORK|PID" sudo -u nobody python script.py` will do the trick for you. (all one command--the first sudo to make you root, so you can create a new container; the second sudo to make the user inside the container unprivileged) You'll need to communicate with the Python script using IPC.

Docker is lxc.

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

#97
post #96

Earlier quoted context omitted.

Docker is a bit overkill; just use what it's built on, Linux containers. `sudo lxc-unshare -s "NETWORK|PID" sudo -u nobody python script.py` will do the trick for you. (all one command--the first sudo to make you root, so you can create a new container; the second sudo to make the user inside the container unprivileged) You'll need to communicate with the Python script using IPC.

Docker is lxc.

Docker is not lxc. See http://stackoverflow.com/questions/17989306/what-does-docker...

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

#98
post #11

Any suggestions for the language? The game and site are written in Python so that seemed most natural, plus it's a high-level language with a simple syntax. I could add more if people wanted though.

Make it language neutral - communicate by HTTP. That would also greatly reduce security concerns.

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

#99
post #97
post #96

Earlier quoted context omitted.

Docker is lxc.

Docker is not lxc. See http://stackoverflow.com/questions/17989306/what-does-docker...

Docker is a clean and thin layer on top of lxc. Not managing lxc instances without it seems like a mistake given portability/reproducability of container management.

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

#100
post #99
post #97

Earlier quoted context omitted.

Docker is not lxc. See http://stackoverflow.com/questions/17989306/what-does-docker...

Docker is a clean and thin layer on top of lxc. Not managing lxc instances without it seems like a mistake given portability/reproducability of container management.

I stand by what I wrote.

- Portability: it's just as portable as lxc, so if you meant portability in the sense of 'well he could use it on FreeBSD if he wants to switch from Linux' I don't think there's a win there. If you mean that his containers won't depend on the environment used to spawn them, I guess I don't think that's so important. I always make sure my environments are easily reproducible, and I am happy to reap the reward of that--the reward being that I can do 'unportable' things and not have to worry. Instead of running the environment you want in a container, why not just run it normally and skip that step?

- Reproducibility: see last point. If he wants reproducibility, he can shove that one-liner in a script somewhere and call it.

All he wants to do is isolate a process. You don't need a chroot for that, or service discovery, or lifecycle managment, or a Dockerfile, or whatever else. It's like if someone advocated the use of a 'grep manager' instead of just running grep. The simplest possible thing to do is unshare the namespaces he wants to isolate from harm. So I suggested exactly that.

EDIT: also re portability, it sounds like the rest of his environment depends on these Python scripts anyway, so I don't think he'd gain anything from being able to use them in a different environment.

Post reply on HN