King of the Hill: Greed Control
What is Greed Control
Greed control is a multiplayer round-based
game
in which in every round, a player bet a number inside
a specific range, say 1~100. Say 2 people betted 100,
then they'd both get 100/2 which is 50
points in
the game. Basically, the players that choose the same
number split the scores evenly (no rounding) and the
total of their net score gain is the number they
chose.
After a set number of rounds, players compare scores.
The highest score generally wins the game overall.
Your challenge
Build a bot in python
, specifically, python 3
,
that when given input, discussed in the section input
,
they give the number as an integer they bet as output.
It must be afunction
.
Input
information, points, round_number, sum_of_all, user_num
.
information
is a dictionary with integer keys
in which each key's value is the number of bots
that chose that key's number last round.
points
is the list of integers you can choose from.
round_number
is the round number.
sum_of_all
is like information
, except it is
the summation of all rounds.
user_num
is the number of players playing.
We guarantee that
We guarantee that points
stay the same every round
and is strictly increasing, all integers. However,
it may not be consecutive.
Controller function
from random import choice
def random_better(information, points, round_number, sum_of_all, user_num):
return choice(points)
def greedy_better(information, points, round_number, sum_of_all, user_num):
return points[-1]
def calculator(information, points, round_number, sum_of_all, user_num):
return sorted(points, key=lambda x:x/(information[x]+0.000000000001))[0]
def smarty(information, points, round_number, sum_of_all, user_num):
return sorted(points, key=lambda x:x/(information[x]+0.000000000001))[choice(range(1,40))]
users = [random_better, greedy_better, calculator, smarty] * 10
user_names = [user.__name__.replace('_',' ') for user in users]
rounds = 1000
points = sorted(list(range(1,101)))
user_num = len(users)
bots = [user for user in users]
scores = [0.0 for user in users]
information = {i:0 for i in points}
sum_of_all = {i:0 for i in points}
print('\n'*100)
for round_number in range(rounds):
choices = [bot(information, points, round_number, sum_of_all, user_num) for bot in bots]
information = {score:choices.count(score) for score in points}
scores = [scores[index] + choices[index]/information[choices[index]] for index in range(user_num)]
print(f'\n\n\nRound #{round_number+1} Reports: ')
print('\nBots Report: ')
print('\n'.join([f'{user_names[index].ljust(20)} '
f'chose {choices[index]} '
f'and got {choices[index]/information[choices[index]]} additional points, '
f'making it now have {scores[index]} points!!! ' for index in range(user_num)]))
print('\nDistribution Report: ')
print('\n'.join([f'The number of bots who chose {num} is: {information[num]}!!! ' for num in points]))
print('\nLeaderboard Report: ')
sorted_list = sorted(range(user_num), key=lambda x: -scores[x])
print(f'\n{user_names[sorted_list[0]].ljust(20)} with {scores[sorted_list[0]]} points, '
f'\n{user_names[sorted_list[1]].ljust(20)} with {scores[sorted_list[1]]} points, and'
f'\n{user_names[sorted_list[2]].ljust(20)} with {scores[sorted_list[2]]} points!!! ')
sum_of_all = {i:sum_of_all[i]+information[i] for i in points}
print('\n\n\nFinal Report Card: \n')
print('\n'.join([f'{user_names[sorted_list[index]].ljust(20)}: '
f'{scores[sorted_list[index]]} points. ' for index in range(user_num)]))
The first part is imports. You may only depend
on default python built-ins or the python standard
library. Or if you manage to hide it and I out of
coincidence have the package...
The second part is your functions. Naming your function
bot_name_with_underscores
is encouraged.
The third part are game parameters.
The number of rounds, the accessible outputs,
etc.
The fourth part is running the program!!!
An example output is as follows:
Round #1 Reports:
Bots Report:
random better chose 3 and got 1.5 additional points, making it now have 1.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 10.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 1.0 points!!!
smarty chose 3 and got 1.5 additional points, making it now have 1.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 0!!!
The number of bots who chose 3 is: 2!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 10.0 points,
random better with 1.5 points, and
smarty with 1.5 points!!!
Round #2 Reports:
Bots Report:
random better chose 7 and got 7.0 additional points, making it now have 8.5 points!!!
greedy better chose 10 and got 5.0 additional points, making it now have 15.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 2.0 points!!!
smarty chose 10 and got 5.0 additional points, making it now have 6.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 0!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 1!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 2!!!
Leaderboard Report:
greedy better with 15.0 points,
random better with 8.5 points, and
smarty with 6.5 points!!!
Round #3 Reports:
Bots Report:
random better chose 4 and got 4.0 additional points, making it now have 12.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 25.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 3.0 points!!!
smarty chose 2 and got 2.0 additional points, making it now have 8.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 1!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 1!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 25.0 points,
random better with 12.5 points, and
smarty with 8.5 points!!!
Round #4 Reports:
Bots Report:
random better chose 6 and got 6.0 additional points, making it now have 18.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 35.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 4.0 points!!!
smarty chose 2 and got 2.0 additional points, making it now have 10.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 1!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 1!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 35.0 points,
random better with 18.5 points, and
smarty with 10.5 points!!!
Round #5 Reports:
Bots Report:
random better chose 2 and got 2.0 additional points, making it now have 20.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 45.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 5.0 points!!!
smarty chose 6 and got 6.0 additional points, making it now have 16.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 1!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 1!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 45.0 points,
random better with 20.5 points, and
smarty with 16.5 points!!!
Round #6 Reports:
Bots Report:
random better chose 3 and got 3.0 additional points, making it now have 23.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 55.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 6.0 points!!!
smarty chose 2 and got 2.0 additional points, making it now have 18.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 1!!!
The number of bots who chose 3 is: 1!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 55.0 points,
random better with 23.5 points, and
smarty with 18.5 points!!!
Round #7 Reports:
Bots Report:
random better chose 8 and got 8.0 additional points, making it now have 31.5 points!!!
greedy better chose 10 and got 10.0 additional points, making it now have 65.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 7.0 points!!!
smarty chose 3 and got 3.0 additional points, making it now have 21.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 0!!!
The number of bots who chose 3 is: 1!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 1!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 1!!!
Leaderboard Report:
greedy better with 65.0 points,
random better with 31.5 points, and
smarty with 21.5 points!!!
Round #8 Reports:
Bots Report:
random better chose 1 and got 0.5 additional points, making it now have 32.0 points!!!
greedy better chose 10 and got 5.0 additional points, making it now have 70.0 points!!!
calculator chose 1 and got 0.5 additional points, making it now have 7.5 points!!!
smarty chose 10 and got 5.0 additional points, making it now have 26.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 2!!!
The number of bots who chose 2 is: 0!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 2!!!
Leaderboard Report:
greedy better with 70.0 points,
random better with 32.0 points, and
smarty with 26.5 points!!!
Round #9 Reports:
Bots Report:
random better chose 3 and got 3.0 additional points, making it now have 35.0 points!!!
greedy better chose 10 and got 5.0 additional points, making it now have 75.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 8.5 points!!!
smarty chose 10 and got 5.0 additional points, making it now have 31.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 0!!!
The number of bots who chose 3 is: 1!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 2!!!
Leaderboard Report:
greedy better with 75.0 points,
random better with 35.0 points, and
smarty with 31.5 points!!!
Round #10 Reports:
Bots Report:
random better chose 2 and got 2.0 additional points, making it now have 37.0 points!!!
greedy better chose 10 and got 5.0 additional points, making it now have 80.0 points!!!
calculator chose 1 and got 1.0 additional points, making it now have 9.5 points!!!
smarty chose 10 and got 5.0 additional points, making it now have 36.5 points!!!
Distribution Report:
The number of bots who chose 1 is: 1!!!
The number of bots who chose 2 is: 1!!!
The number of bots who chose 3 is: 0!!!
The number of bots who chose 4 is: 0!!!
The number of bots who chose 5 is: 0!!!
The number of bots who chose 6 is: 0!!!
The number of bots who chose 7 is: 0!!!
The number of bots who chose 8 is: 0!!!
The number of bots who chose 9 is: 0!!!
The number of bots who chose 10 is: 2!!!
Leaderboard Report:
greedy better with 80.0 points,
random better with 37.0 points, and
smarty with 36.5 points!!!
Final Report Card:
greedy better : 80.0 points.
random better : 37.0 points.
smarty : 36.5 points.
calculator : 9.5 points.
If any bot runs into an error,
it fails. So CHECK IT!!! Make it FOOLPROOF!!!
Winner
This is king-of-the-hill.