Skip to content

Instantly share code, notes, and snippets.

View audhiaprilliant's full-sized avatar
🎯
Focusing

Audhi Aprilliant audhiaprilliant

🎯
Focusing
View GitHub Profile
@audhiaprilliant
audhiaprilliant / monopoly-simulation.ipynb
Created May 6, 2023 12:35
Creating a Monopoly Game Board Simulation with Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@audhiaprilliant
audhiaprilliant / monopoly-simulation-7.py
Created April 16, 2023 16:02
Creating a Monopoly Game Board Simulation with Python
# Monopoly simulation
def monopoly_simulation(
num_player: int,
iteration: int,
card: bool
):
# String of players
player_str = ['Player ' + str(i) for i in range(1, num_player + 1)]
# A dictionary for players
@audhiaprilliant
audhiaprilliant / monopoly-simulation-6.py
Created April 16, 2023 16:01
Creating a Monopoly Game Board Simulation with Python
# Player(s) movement
def move_spaces(
dict_latest: dict,
dices: int,
subiteration: int,
three_times: bool,
card: bool,
data_card: dict,
data_space: dict
):
@audhiaprilliant
audhiaprilliant / monopoly-simulation-5.py
Created April 16, 2023 16:00
Creating a Monopoly Game Board Simulation with Python
# Rounds on Monopoly board
def round_spaces(
dict_spaces: dict
):
# Latest round
latest_round = dict_spaces['round']
# Update status
updated_status = False
# After-before spaces
@audhiaprilliant
audhiaprilliant / monopoly-simulation-4.py
Created April 16, 2023 16:00
Creating a Monopoly Game Board Simulation with Python
# Select a card and show the result
def take_cards(
subiteration_dict: dict,
card: bool,
chance_card: bool,
data_card: dict,
data_space: dict
):
# Card status
card_status = card
@audhiaprilliant
audhiaprilliant / monopoly-simulation-3.py
Created April 16, 2023 15:59
Creating a Monopoly Game Board Simulation with Python
# Find the shortest spaces for spaces in circular list
def shortest_space(
source: int,
targets: list,
data_space: dict
):
# Create a dictionary
d_targets = {key: None for key in targets}
# Loop the targets
@audhiaprilliant
audhiaprilliant / monopoly-simulation-2.py
Created April 16, 2023 15:59
Creating a Monopoly Game Board Simulation with Python
# Find the shortest spaces in circular list
def distance_space(
data_space: dict,
first_index: int,
second_index: int
):
# Update the data space
data_space_update = (data_space[first_index - 1:] + data_space[:first_index - 1])
# Calculate the distance
@audhiaprilliant
audhiaprilliant / monopoly-simulation-1.py
Created April 16, 2023 15:58
Creating a Monopoly Game Board Simulation with Python
# Update spaces
def update_space(
last_move: int,
dices: list,
data_space: dict
):
# Updated board based latest move
l_board = (data_space[last_move - 1:] + data_space[:last_move - 1])
# Current space
d_current_space = [l_board[np.sum(dices) % len(l_board)]]
@audhiaprilliant
audhiaprilliant / matplotlib-102-subplot-5.py
Created November 11, 2022 17:04
Matplotlib 102 - Basic Introduction to Multiplot, Subplot and Gridspec
# ---------- SUBPLOT WITH GRIDSPEC ----------
# Figure size
fig = plt.figure(figsize = (10, 8))
# Create a grid for plots (2 rows & 3 columns)
gs = gridspec.GridSpec(nrows = 2, ncols = 3, figure = fig)
ax1 = fig.add_subplot(gs[0, :]);
ax1.set_title('# Customer by payment method');
@audhiaprilliant
audhiaprilliant / matplotlib-102-subplot-4.py
Created November 11, 2022 17:03
Matplotlib 102 - Basic Introduction to Multiplot, Subplot and Gridspec
# ---------- SUBPLOT (2 ROWS, 2 COLUMNS) ----------
# Create a grid for plots (2 rows & 2 columns)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows = 2, ncols = 2, figsize = (10, 6))
# Bar plot - 1
ax1.bar(
x = 'gender',
height = 'customerID',
data = df_group_2,