slot prac

This commit is contained in:
Stephen Deaton 2024-06-27 14:28:33 -04:00
parent 820b92d939
commit 9aa6b06c24

View File

@ -1,5 +1,5 @@
import random
from typing import List, Dict, Tuple
MAX_LINES = 3
MAX_BET = 100
@ -7,38 +7,63 @@ MIN_BET = 1
ROWS = 3
COLS = 3
symbol_count = {
SYMBOL_COUNT = {
"A": 2,
"B": 4,
"C": 6,
"D": 8
}
def get_slot_machine_spin(rows, cols, symbol):
SYMBOL_VALUE = {
"A": 5,
"B": 4,
"C": 3,
"D": 2
}
def check_winings(columns, bet, lines, values):
winnings = 0
winning_lines = []
for line in range(lines):
symbol = columns[0][line]
for column in columns:
symbol_to_check = column[line]
if symbol != symbol_to_check:
break
else:
winnings += values[symbol] * bet
winning_lines.append( +1)
return winnings, winning_lines
# This function will
def get_slot_machine_spin() -> List:
all_symbols = []
for symbol, symbol_count in symbol.items(): #this is so as it picks from the list it gets the values and the index
for _ in range(symbol_count): # underscore ????
# this is so as it picks from the list it gets the values and the index
for symbol, count in SYMBOL_COUNT.items():
for _ in range(count):
all_symbols.append(symbol)
columns = []
for _ in range(cols):
for col in range(COLS):
column = []
current_symbols = all_symbols[:]
for _ in range(rows):
for row in range(ROWS):
value = random.choice(current_symbols)
current_symbols.remove(value)
column.append(value)
columns.append(column)
return columns
def print_slotmachine(columns):
for row in range(len(columns[0])):
for i, column in enumerate(columns):
if i != len(columns) - 1:
print(column[row], "|")
def print_slotmachine(columns: List):
for row in range(ROWS):
for index, column in enumerate(columns):
if index != COLS - 1:
print(column[row], "| ", end='')
else:
print(column[row],)
print(column[row])
def deposit() -> int:
amount = 0
@ -64,6 +89,7 @@ def get_number_of_lines() -> int:
print(" Error: Please enter a number")
return lines
def get_bet() -> int:
bet = 0
while bet < MIN_BET or bet > MAX_BET:
@ -79,19 +105,23 @@ def get_bet() -> int:
def main():
balance = deposit()
lines = get_number_of_lines()
while True:
bet = -1
total_bet = balance + 1
while bet != 0 and total_bet > balance:
bet = get_bet()
print(f"___{bet}_{lines}")
total_bet = bet * lines
if total_bet > balance:
print(f" Error: You do not have enough to bet that amount, curent balance is: ${balance} ")
else:
break
total_bet = bet * lines
if total_bet == 0:
return
print(f"You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet} ")
slots = get_slot_machine_spin(ROWS, COLS, symbol_count)
slots = get_slot_machine_spin()
print_slotmachine(slots)
main()
winnings, winning_lines = check_winings(slots, lines, bet, SYMBOL_VALUE)
print(f"You won ${winnings}.")
print(f"You won on lines:", *winning_lines)
main()
print()
print("Thank you for playing!")