Hog Contest¶
This is the leaderboard for the Hog Contest.
Setup¶
Install the dependencies in requirements.txt
. From the berkeley-cs61a
repo,
copy src/proj/hog/hog_eval.cpp
into ./main.cpp
. Run python3 main.py
to
start the Flask app.
Main¶
-
docs.hog_contest.main.
expand_semester
(short_form)[source]¶ Takes in a semester name in condensed notation (eg. sp21, fa20, su18) and expands it into a full version (eg. Spring 2021, Fall 2020, Summer 2018).
- Parameters
short_form (str) – condensed notation for a semester
- Returns
expanded notation for semester (str)
Tournament¶
-
docs.hog_contest.tournament.
post_tournament
()[source]¶ RANKINGS and WINRATES are nonlocal variables
Connect to the database. Fetch all name and hash pairs from the CACHED_STRATEGIES table (Call this hash_lookup). Fetch all winrates from CACHED_WINRATES table (call this db_winrates).
Create a nested defaultdict for the winrate and a defaultdict for num rates.
Create a 2d array from the data in hash loopup, where each data point is a [name, hash] pair and call this new data structure ACTIVE_TEAMS.
Iterate through db_winrates and add the data into the nested WINRATE_DICT (data: h0, h1, rate) such that it follows the following convention: - WINRATE_DICT[h0][h1] = winrate - WINRATE_DICT[h1][h0] = 1 - winrate - WINRATE_DICT[h0][h0] = 0.5 - WINRATE_DICT[h1][h1] = 0.5
Have two teams play against each other. If the winrate of team0 agains team1 is greater that THRESHOLD, then add 1 win to the num_teams dict for team0.
Construct a new array for teams data consisting of [team name decoded, number of wins, and the hash].
Sort the teams by number of wins, and construct a ranking.
Create a 2-d Matrix of WINRATES of each team playing each other.
- Returns
None
-
docs.hog_contest.tournament.
build_ranking
(teams)[source]¶ Assigns rankings to the teams based on their winrates. If teams are tied, they will be assigned the same ranking as each other.
- Parameters
teams (list) – A list of teams, where each element is a list containing a team’s name and winrate (among potentially other data). This list is already sorted by num wins in descending order.
- Returns
List of teams with their rank, name, and number of wins, in ascending order of rank.
-
docs.hog_contest.tournament.
worker
(t_id, q, out, goal)[source]¶ We get each task from the queue. Score the strategies. Store the score in the OUT dictionary. Finish the task. If the size of our queue is a factor of LOG_MOD, then we log the number of matches completed.
-
docs.hog_contest.tournament.
unwrap
(strat)[source]¶ Return the hash of the strat, and load the strategy from json.
- Parameters
strat (dictionary) – data structure containing data pertaining to the strategy.
- Returns
tuple of hash and the strategy loaded from json.
-
docs.hog_contest.tournament.
run_tournament
()[source]¶ Connects to database, and fetches data from CACHED_STRATEGIES and CACHED_WINRATES. Stores the current time as START_TIME.
Store the data from CACHED_WINRATES in a dictionary called WINRATES.
Create a QUEUE for tasks.
Iterate through entry0, entry1 in the Cartesian product of ALL_STRATEGIES and ALL_STRATEGIES. If hash of entry0 is greater than or equal to the hash of entry1 move onto the next entry pair. If the tuple of the hashes of entry0 and entry1 are in the WINRATES dictionary, then add 1 to the NUM_DONE variable, and move onto the next entry pair. If neither of the former two cases are true, then call unwrap on both of the entries and put the output of both calls in a list and put this list in the tasks queue.
Create a dictionary called OUT, and a list called THREADS.
Create a THREAD where the target=worker, and pass in the arguments T_ID, the queue of TASKS, the OUT dictionary, and SIZE of the TASKS queue. Start each process. Then append to the THREADS list.
Join the TASKS structure.
Add end-of-queue markers to the TASKS structure.
Store the newly computed winrates into the CACHED_WINRATES data table.
Update the LAST_UPDATED time with the START_TIME. Call the POST_TOURNAMENT function.