This framework consists of:
-
farkle_framework.py- The main framework file containing:FarkleBot- Base class for student botsFarkleGame- Game logic for a single Farkle gameFarkleTournament- Tournament manager to run multiple games between bots- Example bots and utility functions
-
bot_template.py- A template for students to create their own bots -
run_tournament.py- Script to run tournaments
- Clone or download this repository
- Make sure you have Python 3.6+ installed
- No additional libraries are required
- Copy the
bot_template.pyfile to thebotsdirectory and rename it (e.g.,my_awesome_bot.py) - Edit the file to implement your strategy in the
make_decisionmethod - Customize the class name and add any helper methods you need
Example:
from farkle_framework import FarkleBot, BotDecision, TurnState, FarkleGame
class MyAwesomeBot(FarkleBot):
def make_decision(self, state: TurnState) -> BotDecision:
game = FarkleGame(None, None)
combos = game.find_scorable_combinations(state.current_dice)
# Your strategy here
# ...
return BotDecision(dice_to_keep, roll_again)To run a tournament with all bots in the bots directory:
python run_tournament.py tournament [games_per_match]
The optional games_per_match parameter specifies how many games to play between each pair of bots.
To see how your bot is behaving, you can run a test game against SimpleBot:
python test.py bots/my_awesome_bot.py [n]
This will run n games between the bots and display a detailed game log.
Your bot must extend this class and implement the make_decision method:
def make_decision(self, state: TurnState) -> BotDecision:
"""
Make a decision based on the current game state
Args:
state: The current turn state
Returns:
A BotDecision object with which dice to keep and whether to roll again
"""This class contains all the information your bot needs to make a decision:
current_dice- List of current dice values [1-6]remaining_dice- Number of dice left to rollturn_score- Score accumulated in this turnbanked_score- Your bot's current banked scoreopponent_score- Opponent's banked score
Your bot must return a BotDecision object with:
dice_to_keep- List of dice values to keep (must be scorable)roll_again- Boolean indicating whether to roll again (True) or end turn (False)
FarkleGame.find_scorable_combinations(dice)- Returns all valid scoring combinations for a set of diceFarkleGame.calculate_score(dice)- Calculates the score for a set of dice
The framework includes two example bots:
SimpleBot- Makes basic decisions using a fixed bank thresholdConservativeBot- Plays very conservatively, banking after any score
Study these bots to understand how to implement your own strategy.
- Test your bot thoroughly against different opponents
- Implement probability calculations for risk assessment
- Create helper methods for different aspects of your strategy
- Document your strategy decisions in code comments
- Balance aggression with security based on game state
- Consider the opponent's score and position when making decisions
Good luck, and may the best bot win!