Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds a short risiko simulator #167

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/risiko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from random import randint


# Ritorna una lista che contiene 3 interi casuali da 1 a 6
def roll_dice() -> list[int]:
MIN_NUMBER = 1 # PEP8 compliant constants
MAX_NUMBER = 6
return [randint(MIN_NUMBER, MAX_NUMBER) for _ in range(3)]


# Controlla chi ha vinto, o se c'è stato una pareggio. Ritorna i risultati in una lista di stringhe
def compare_dice(red, blue) -> list[str]:
result = []
for r, b in zip(red, blue):
if r > b:
result.append("red win")
elif r < b:
result.append("blue win")
else:
result.append("draw")
return result


def print_dice(dice: list[int], labels: list[str]) -> None:
for i in range(3):
print(f"{dice[i]} ({labels[i]})")


# Visualizza i risultati, dando in input una lista di dadi rossi, una di dadi blu, e la lista di vittorie / sconfitte / pareggi
def display_results(red, blue, comparison) -> None:
# N: first highest number, M: second highest number, O: third highest number
labels = [
"N",
"M",
"O",
]
print("Red dices:")
print_dice(red, labels)

print("\nBlue dices:")
print_dice(blue, labels)

print("\n R B")
for i in range(3):
print(f"{labels[i]} {red[i]} vs {blue[i]} => {comparison[i]}")


# Simula il lancio di dadi per attaccante e difensore
red_dice = roll_dice()
blue_dice = roll_dice()

# Controlla chi ha vinto e visualizza i risultati
comparison_result = compare_dice(red_dice, blue_dice)
display_results(red_dice, blue_dice, comparison_result)
Loading