Ruby programming challenge as job application
smashingboxes.com
smashingboxes.com
module Wizard
def move; [:rest] end
def stats; i = 1.0/0; { health: i, level: i, strength: i, defense: i, experience: i } end
def suffer_damage(p); end
def to_s; "Zhormenheimer the Illusionist" end
end
Zhormenheimer the Illusionist: {:health=>Infinity, :level=>Infinity, :strength=>Infinity, :defense=>Infinity, :experience=>Infinity}
Zhormenheimer the Illusionist is the winner!
(Ruby really needs something like Lua's setfenv!)I did try to make it semi-cheat proof by using a delegator PlayerProxy that sends method calls to the real Player objects. But if you're going to read the stats of other players you must be able to call Player#stats somehow.
Without those constraints, there are limitless ways to cheat, especially since it's impossible to actually hide functionality in ruby (obligatory: https://github.com/fxn/i-told-you-it-was-private ), so you have to have a set of meta-constraints in place.
Regarding proxying, why not just use the Forwardable module? Though, even if you did manage to hide the critical pieces from the Player, I'd just iterate ObjectSpace to find a PlayerProxy that contains a reference to my Player. :P
To get true cheating prevention, you'd have to do something like spawn off another Ruby process and use some kind of IPC to pass events to your "client" process and receive actions back to your "server" process. All canonical state would be held by the "server" process.
This is really the classic "don't trust the client" problem that all games run into. :)
Parsing source code for "bad" stuff is generally an arms race you can't win. For actual sandboxing you need a clean environment (hence, the reference to Lua's setfenv).
Unless I misread this the challenge is only available for people who are publicly job hunting, which is a small percentage of eligible coders. I believe I've seen this before as "tweet us your resume".
We debated how to implement this and decided on using github because of the added bonus of being able to view github profiles as part of the screening process.
If anyone's interested in a job but doesn't want to submit a public pull request, please send your contest submission to reed@smashingboxes.com and let us know if you want your code to be committed to our repo or not.