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