Live data from Hacker News

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

robotgame.org

61–70 of 102 posts

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

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

What does this code do?

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

#62
post #61
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…

What does this code do?

Looks like it gives the player associated with that code a score of 2000 points and the opponent 0.

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

#63
post #61
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…

What does this code do?

It replaces the code of the entire game with a new game that gives one player 2000 points...

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

#64
post #61
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…

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.

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

#65

Is there any way to access the map in the Robot class? For the default map, I can just hardcode it, but if you do intend for a robot to be playable on multiple maps, they'll need some way of knowing which squares are obstacles and spawn points. Without preserving state between turns, there's no way to figure that information out over time, either.

You can preserve state between turns; it's the same Robot object being called. Thanks for the suggestion though, I'll try to make that a feature.

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

#66
post #65

Is there any way to access the map in the Robot class? For the default map, I can just hardcode it, but if you do intend for a robot to be playable on multiple maps, they'll need some way of knowing which squares are obstacles and spawn points. Without preserving state between turns, there's no way to figure that information out over time, either.

You can preserve state between turns; it's the same Robot object being called. Thanks for the suggestion though, I'll try to make that a feature.

Oh, I didn't realize that. Thanks!

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

#67
post #35

So did anyone else ever play Core War back in the mid '80s? http://en.wikipedia.org/wiki/Core_War I wonder whether modern virtualization techniques are secure enough to allow you to provide unrestricted access to a virtualized OS and allow people complete access to fight for control?

Hah!

I wasn't born then, but me and my friends implemented a CoreWars 88' standard microprocessor in an FPGA for a school hardware project. It was possible to write code snippets in redcode and then we compiled it and sent it through usb and the FPGA was connected to a screen so we could see the progress.

The source is fairly messy but have a peek if it interests you: https://github.com/treeman/MARC

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

#68
post #22
post #9

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

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.

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

#70
post #24
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

You may want to bear in mind that, at least last I knew, the official position of the CPython dev team is that it is not possible to sandbox CPython. If they can't do it.... At any rate it is certainly not as simple as that, and not only is it not as simple as that, it is not even close to being that simple. In fact, I recall warning people off of this exact project many years ago on comp.lang.python. This seems up-t…

Holy shit, that article was brilliant. A few of those tricks I was aware of ( __class__.__class__ ), but crafting code objects? I need to re-read this a few times to properly grok how it works.

I find things like this absolutely fascinating.

Post reply on HN