hog-calc

This contains methods used to compare strategies for Hog.

Running Locally

Create a venv and install dependencies.

$ python3 -m venv env
$ env/bin/pip install -r requirements.txt

Run env/bin/python main.py to start the Flask server, then make a POST request to http://localhost:5000/api/compare_strategies to start comparing strategies.

Main

This file compares Hog strategies and outputs strategy win rates.

Process Input

This file contains methods for validating and recording Hog strategies.

docs.hog_calc.process_input.validate_strat(received_strat)[source]

This function validates that the strategy inputted gives out a number of rolls for each pair of score values that is within the acceptable range of rolls. It then returns the strategy.

Parameters

received_strat (dict) – the strategy that was submitted by a student

Returns

list of lists with the strategy’s number of rolls for given scores

docs.hog_calc.process_input.record_strat(name, group, received_strat)[source]

This function takes in a submitted strategy and validates it, then encodes it in JSON format along with the name, a hash of the strategy, and the email of one of the users in the group, and stores it on the CS61A database.

Parameters
  • name (str) – the name of the strategy provided

  • group (list) – the group of students submitting the strategy

  • received_strat – the strategy that was submitted, which will be

evaluated and stored on the database :type received_strat: dict

Returns

the hash of the received strategy

Runner

This file contains methods for matching and scoring two given Hog strategies.

docs.hog_calc.runner.make_strat_str(strat_0, strat_1)[source]

Takes in two separate strategies and converts them both into a string separating each num_roll of dice by a newline.

Parameters
  • strat_0 (list) – the first inputted strategy

  • strat_1 (list) – the second inputted strategy

Returns

a string with number of dice rolls per score value per strategy

docs.hog_calc.runner.match(strat_0, strat_1, *, use_contest=True)[source]

Plays a match between two strategies.

Parameters
  • strat_0 (list) – the first inputted strategy

  • strat_1 (list) – the second inputted strategy

  • use_contest (bool) – determines whether bacon or bacon_proj is used

Returns

the float result of a match between two strategies

docs.hog_calc.runner.score(strat_0, strat_1, *, use_contest=True)[source]

Determine the score of a matchup between the two strategies.

Parameters
  • strat_0 (list) – the first inputted strategy

  • strat_1 (list) – the second inputted strategy

  • use_contest (bool) – determines whether bacon or bacon_proj is used

Returns

the float score of matching up two strategies