guess package

Submodules

guess.ai_logic module

Module for ai rolling logic.

class guess.ai_logic.AiLogic

Bases: object

Halloj.

anton_ai_difficulty(npc_score, player_score)

Halloj.

end_turn_or_keep_going()

Halloj.

increment_turn_score(score)

Halloj.

johan_ai_difficulty(npc_score, player_score)

Halloj.

liam_ai_difficulty(npc_score, player_score)

Halloj.

rasmus_ai_difficulty(npc_score, player_score)

Halloj.

reset_turn_score()

Halloj.

should_roll(npc_score, player_score)

Halloj.

guess.data_handler module

DataHandler module.

Provides the DataHandler class to manage reading, writing, and updating user and leaderboard data in JSON format.

class guess.data_handler.DataHandler(dir_path='./guess/GameData')

Bases: object

Handles game’s data.

guess.dice module

This module defines a Dice class to simulate rolling dice.

class guess.dice.Dice(sides=6)

Bases: object

Represents a dice object that can be rolled.

get_last_roll()

Return the value of the last roll.

roll_dice()

Roll the dice and generate a random integer between 1 and the number of sides.

guess.dice_hand module

This module defines a hand in order to engage with a dice

class guess.dice_hand.DiceHand

Bases: object

Represents a dice hand

get_last_roll()

Return the value of the last die throw

get_roll_history()

Return all rolls from current session

roll_dice()

Roll the dice in hand

guess.game module

This module defines a game module in which the game is initialized from

class guess.game.Game(leaderboard=None, dir_path='./guess/GameData')

Bases: object

Represents the game object

evaluate(value)

Determine if player may continue or not

game_status()

Monitor if game is finished or not

npc_turn()

Npc takes turn, sends result to the intelligence class.

player_turn(player)

Player(s) takes turn rolling dice

start(players, test_mode=False)

Decide which player starts first

guess.json_file_handler module

Handles Json data.

class guess.json_file_handler.JSONFileHandler(file_path, dir_path='./guess/GameData')

Bases: object

Handles writing user data to JSON file.

is_missing_or_empty()

Check for missing file or invalid content.

read()

Read user data file and returns.

write(data)

Write user data to file.

guess.leaderboard_data_handler module

Module for handling LeaderboardData.

Handles LeaderboardData.

class guess.leaderboard_data_handler.LeaderboardDataHandler(file_path, dir_path)

Bases: JSONFileHandler

Handle writing leaderboard data to JSON file.

guess.main module

Lets play a game of “Pig, Dice Game”.

Your goal is to beat the opposing player by reaching the target points before them!

During your turn, you can roll the dice as many times as you’d like, however, if exactly ONE of your dice roll a ‘1’, all your points during that turn are lost. If you happen to roll two ‘1’s’, all of you points will be reset to 0, including points acquired from previous turns.

Play carefully, and don’t be a PIG!

guess.main.main()

Execute the main program.

guess.player module

Module for the Player object representing a player in the game.

class guess.player.Player(username, user_id)

Bases: object

Represent a player in the game.

get_user_id()

Return the player’s user ID.

get_username()

Return the player’s username.

set_username(new_username)

Set the player’s username.

guess.shell module

Using the cmd module to create a shell for the main program.

You can read about the cmd module in the docs:

cmd — support for line-oriented command interpreters https://docs.python.org/3/library/cmd.html

class guess.shell.Shell

Bases: Cmd

Classes that handle the terminal’s user inputs

do_EOF(arg)

Leave the game.

do_cheat(_)

This will cheat the game towards the end of it for testing purposes

do_exit(_)

Leave the game.

do_namechange(args)

Will perform a namechange

do_q(arg)

Leave the game.

do_quit(arg)

Leave the game.

do_roll(_)

Decide to to roll the dice

do_rules(_)

Will explain the rules once again

do_start(mode)

Start a game versus the computer

help_namechange()
intro = 'Welcome to the PIG Game!. Type help or ? to list available commands.\n'
prompt = '(Game) '

guess.user_data_handler module

Module for handling UserData.

Handles user data.

class guess.user_data_handler.UserDataHandler(file_path, dir_path)

Bases: JSONFileHandler

Handles writing user data to JSON file.

add_user(username)

Add a new user if username is unique.

get_user_id(username)

Return user id based on username.

update_username(current_username, new_username)

Update the username for an existing user.

Module contents

A guessing game.