# 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.

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]))

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

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!!!

This is .

# May the points be EVER in your favor!

Current information:

Final Report Card:

greedy better       : 49450.0 points.
crab                : 49450.0 points.
random better       : 48090.0 points.
smarty              : 21715.5 points.
calculator          :   993.5 points.

TO REPEAT, THIS IS NOT A DUPE OF Smallest unique number KoTH.

• @SylvesterKruin I suggest you check the sandbox before posting "use the sandbox" comments May 14, 2022 at 14:17
• @Seggan Oops... :-) That didn't turn up in my search. I realized just now that I had searched using highest score first, not date modified, so when I searched "Greed Control" on the first page, it didn't turn up anything, and since the post on the bottom of the page was from 2014, I assumed I didn't need to turn the pages. My mistake, sorry @NumberBasher! May 14, 2022 at 15:34
• @SylvesterKruin no problem! May 15, 2022 at 0:25
• I'm voting to close this as a dupe of Smallest unique number KoTH, because although this one works a bit differently (large instead of small, and the score is divided instead of being eliminated), the most effective strategy is still going to be roughly the same (until a Crablike bot comes along and makes returning 100 the only viable strategy, of course) May 15, 2022 at 22:50
• @RadvylfPrograms There is no "large instead of small", every points is divided, so one people gets all the points if only he chose it, no matter what. May 16, 2022 at 0:17

## Crab

def crab(a,b,c,d,e):
return 100

If Crab can't get 100 points, nobody can.

Might actually be competitive, as simulationist bots will pick a lower number to maximize points and not share, and other bots probably won't go as riskily to pick 100 every time.

• Welcome to Code Golf! May 15, 2022 at 22:51

Assume most players who vote high will give the same answer given the same inputs. Run every bot and pick the highest unpicked number, while also telling later copies of ourselves to not step on our toes by giving them an upper bound, via the shared information dictionary.

currentpick = 100
try:
if "inspector" in k:
currentpick=k["inspector"]
currentpick -= 1
import inspect
from copy import copy
users = inspect.stack()[1][0].f_globals["users"]
picks = []
for u in users: