chadamiller / hungergames Goto Github PK
View Code? Open in Web Editor NEWHunger Games competition from Brilliant.org
Hunger Games competition from Brilliant.org
I forked Game.py and changed it so it would keep track of eliminated players. It would use those to print a clean list with all finalists in order of food left, and all eliminated players sorted on the round they were eliminated. However, there's one problem left in my code, and I wasn't able to fix it (I'm new to Python). Should I just post a pull request so you can have a look?
I believe that the //2
here is unnecessary and causing everyone to die off too quickly due to never earning the bonus.
In the last print, some reputations seem to be screwed up. Those screwed up reps seem to have a food value, but it is different from the amount of food that player has. Quite strange.
Someone mentioned this on Brilliant's forums. The mistake is that I add the attempts in to total attempts before calculating rep, which means everyone's rep is too low.
Each round, your tribe can save some time and hunt extra food if enough people opt to hunt. Each round, a random integer m, with 0<m<P(P−1) will be chosen. If the sum of the number of times players choose to hunt is greater than or equal to m for the upcoming round, then everyone in the tribe gets 2(P−1) extra units of food after the round, which means that on average everyone gets 2 units of food per hunt. Before each round, you will find out the value of m.
However, in the code (lines 123 - 124; Game.py) :
if total_hunts >= self.m_bonus:
bonus = m
Looks like it should just be:
if total_hunts >= m:
bonus = self.m_bonus
The "food_earnings" array shoud have length (P-1)
, not P
.
It is basically the same issue that existed before with
hunt_choices(..., player_reputations)
.
From @geofflittle via email: The current implementation switches between "always hunt" and "never hunt" every round. The one in the sample code intersperses hunting and slacking with each pairing.
I don't want to remove the base class entirely. However, I've decided that my goal for this project is to set it up so that if they have a working solution, they can just copy/paste the relevant class definitions from Players.py
and have a working solution. This would also make the class file pass the verification script.
This is going to sound silly, but the only reason I didn't fix it before even posting this repo in the first place is that I didn't have a better name. I still really don't. Eventually I'll just pick something but in the meantime if someone has a better idea I'm all ears.
Correct me if I'm wrong, but in the top section of the Game.py file where it returns the payout, it appears to be returning the net payout (food recieved minus the cost of hunting or slacking). However if s1 chooses to slack and s2 chooses to hunt, it gives a net payout of 3. Is that supposed to be 1? (slacking costs 2 food, but s1 gains 3 food from s2 hunting)
The simulator doesn't seem to work?
luis@debian:/git/software$ git clone https://github.com/ChadAMiller/hungergames.git/git/software$ cd hungergames
luis@debian:
luis@debian:~/git/software/hungergames$ python app.py
Playing the game to the end:
Begin Round 1:
Traceback (most recent call last):
File "app.py", line 11, in
game.play_game()
File "/home/luis/git/software/hungergames/Game.py", line 170, in play_game
self.play_round()
File "/home/luis/git/software/hungergames/Game.py", line 121, in play_round
print ("There were {} hunts of {} needed for bonus".format(total_hunts, m))
ValueError: zero length field name in format
In hunt_outcomes(food_earnings)
, food_earnings
should be a list of earnings from each hunt but instead it is a single number. This can be fixed by changing
player[0].hunt_outcomes(food)
in Game.py to
player[0].hunt_outcomes([ result[i] + {'h':-6, 's':-2}[strat[i]] for i in range(len(result)) ])
"food_earnings: list of integers, the amount of food earned from the last round's hunts. The entries can be negative as it is possible to lose food from a hunt."
As far as I see it, you code neglects the cost of hunting/not hunting (-6/-2) and it only gives the sum of the hunting results instead of the list.
It turns out this bit:
def __repr__(self):
try:
return self.name
except AttributeError:
return NotImplemented
Doesn't do what I wanted it to. The intent was that people could set a .name
attribute on their custom classes for better printing, but that Python would fall back on a sensible default if that attribute doesn't exist. It seems like there should be a sensible way of "Call this attribute if it's defined, but do whatever you would normally do if it's not" but I don't know what that is offhand. In the meantime you can work around it by always defining self.name
in your initializers.
In this line:
player.player.hunt_outcomes(result)
Shouldn't the player herself be excluded before calling hunt_outcomes?
Not sure if you've already addressed this, but your game starts with
start_food = 300_(self.P-1)_self.P
on line 46.
Should be
start_food = 300*(self.P-1)
I believe.
Just downloaded your files and ran app.py. I get this error message after round 774 when the game completes. I'm pretty new to this so I could be just doing some wrong or it might not be designed to work out of the box. Just a heads up, thanks for the code!
Per this comment
everyone's
reputation_list
is unique to them (since they aren't in it) so it is mutable and doesn't hurt anything if they change it (except it may cause their own results to be different than they intended, though I guess it may be a useful tactic to do some in place modification of thereputation_list
).
My reputation_list
is a tuple and therefore immutable. The worse problem is that it includes the current player. play_round
currently hacks around this, but forcing the Player
subclasses to behave differently from the final answer is a problem.
if total_hunts > m
should be
if total_hunts >= m
I'm getting the error
Traceback (most recent call last):
File "D:\hungergames-master\app.py", line 27, in
game.play_game()
File "D:\hungergames-master\Game.py", line 185, in play_game
self.play_round()
File "D:\hungergames-master\Game.py", line 115, in play_round
strategy.insert(i,'s')
AttributeError: 'NoneType' object has no attribute 'insert'
This error only occurs near round range 550-700 and never happened before. Why do you think this is occuring?
posting as an issue to pressure myself into doing it tomorrow
I think it would be nice to have a default bot who makes all decisions with a fair and independent coin toss. Thanks.
I'm sorry I didn't consider this sooner, but if your hunt_choices
is returning something that isn't a list, it will probably crash the game, and if it returns a list of the long length, it will probably have nonsensical results.
I would fix this bug, but between github outages and my being stretch for time I haven't really had the opportunity to add a fix and the deadline is in less than three days. Furthermore, anything I do would almost certainly behave differently from the server, which will purportedly replace errors with "all slacking".
Rather than tinker with this further and risk a last-minute screwup or expectation mismatch, I figured I'd just post what I'd do so people can do this locally if they want the sanity check.
In Game.py
, outside of the class:
def valid_choices(L, n):
'''Sanity check for hunt_choices'''
return (type(L) == list
and len(L) == n
and all(_ == 'h' or _ == 's' for _ in L))
In Game.play_round
, after getting strategy
from a player:
if not valid_choices(strategy, self.P):
# handle errors however you want
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.