mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-08-06 17:03:04 +02:00
casinoHighScores
I got a really good score its a shame it was wasted
This commit is contained in:
@@ -11,7 +11,7 @@ except Exception as e:
|
||||
with open('bbsdb.pkl', 'rb') as f:
|
||||
bbs_messages = pickle.load(f)
|
||||
except Exception as e:
|
||||
print ("\nSystem: bbsdb.pkl not found")
|
||||
bbs_messages = "System: bbsdb.pkl not found"
|
||||
|
||||
try:
|
||||
with open('../bbsdm.pkl', 'rb') as f:
|
||||
@@ -21,7 +21,7 @@ except Exception as e:
|
||||
with open('bbsdm.pkl', 'rb') as f:
|
||||
bbs_dm = pickle.load(f)
|
||||
except Exception as e:
|
||||
print ("\nSystem: bbsdm.pkl not found")
|
||||
bbs_dm = "System: bbsdm.pkl not found"
|
||||
|
||||
# Game HS tables
|
||||
try:
|
||||
@@ -32,7 +32,7 @@ except Exception as e:
|
||||
with open('lemonade_hs.pkl', 'rb') as f:
|
||||
lemon_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
print ("\nSystem: lemonade_hs.pkl not found")
|
||||
lemon_score = "System: lemonade_hs.pkl not found"
|
||||
|
||||
try:
|
||||
with open('../dopewar_hs.pkl', 'rb') as f:
|
||||
@@ -42,13 +42,36 @@ except Exception as e:
|
||||
with open('dopewar_hs.pkl', 'rb') as f:
|
||||
dopewar_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
print ("\nSystem: dopewar_hs.pkl not found")
|
||||
dopewar_score = "System: dopewar_hs.pkl not found"
|
||||
|
||||
try:
|
||||
with open('../blackjack_hs.pkl', 'rb') as f:
|
||||
blackjack_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
try:
|
||||
with open('blackjack_hs.pkl', 'rb') as f:
|
||||
blackjack_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
blackjack_score = "System: blackjack_hs.pkl not found"
|
||||
|
||||
print ("\nSystem: bbs_messages")
|
||||
try:
|
||||
with open('../videopoker_hs.pkl', 'rb') as f:
|
||||
videopoker_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
try:
|
||||
with open('videopoker_hs.pkl', 'rb') as f:
|
||||
videopoker_score = pickle.load(f)
|
||||
except Exception as e:
|
||||
videopoker_score = "System: videopoker_hs.pkl not found"
|
||||
|
||||
print ("\n Meshing-Around Database Admin Tool\n")
|
||||
print ("System: bbs_messages")
|
||||
print (bbs_messages)
|
||||
print ("\nSystem: bbs_dm")
|
||||
print ("System: bbs_dm")
|
||||
print (bbs_dm)
|
||||
print ("Game HS tables")
|
||||
print (f"\n\nGame HS tables\n")
|
||||
print (f"lemon:{lemon_score}")
|
||||
print (f"dopewar:{dopewar_score}")
|
||||
print (f"dopewar:{dopewar_score}")
|
||||
print (f"blackjack:{blackjack_score}")
|
||||
print (f"videopoker:{videopoker_score}")
|
||||
print ("\n")
|
||||
+9
-20
@@ -367,14 +367,6 @@ def handleBlackJack(nodeID, message):
|
||||
jackTracker[i]['d_hand'] = []
|
||||
return msg
|
||||
|
||||
# # Save the game state to pickle
|
||||
# try:
|
||||
# with open('blackjack_hs.pkl', 'wb') as file:
|
||||
# pickle.dump(jackTracker, file)
|
||||
# except FileNotFoundError:
|
||||
# logger.debug("System: BlackJack: Creating new blackjack_hs.pkl file")
|
||||
# with open('blackjack_hs.pkl', 'wb') as file:
|
||||
# pickle.dump(jackTracker, file)
|
||||
else:
|
||||
# find higest dollar amount in tracker for high score
|
||||
if last_cmd == "new":
|
||||
@@ -384,8 +376,11 @@ def handleBlackJack(nodeID, message):
|
||||
high_score = int(jackTracker[i]['cash'])
|
||||
user = jackTracker[i]['nodeID']
|
||||
if user != 0:
|
||||
msg += f" Ranking🥇:{get_name_from_number(user)} with {high_score} chips. "
|
||||
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
highScore = loadHSJack()
|
||||
if highScore['nodeID'] != 0:
|
||||
msg += f" Ranking🥇:{get_name_from_number(highScore['nodeID'])} with {highScore['highScore']} chips. "
|
||||
|
||||
# Play BlackJack
|
||||
msg = playBlackJack(nodeID=nodeID, message=message)
|
||||
|
||||
@@ -427,16 +422,10 @@ def handleVideoPoker(nodeID, message):
|
||||
high_score = vpTracker[i]['highScore']
|
||||
user = vpTracker[i]['nodeID']
|
||||
if user != 0:
|
||||
msg += f"\nHigh Score: {high_score} by {get_name_from_number(user)}"
|
||||
|
||||
# # Save the game high_score to pickle
|
||||
# try:
|
||||
# with open('videopoker_hs.pkl', 'wb') as file:
|
||||
# pickle.dump(high_score, file)
|
||||
# except FileNotFoundError:
|
||||
# logger.debug("System: BlackJack: Creating new videopoker_hs.pkl file")
|
||||
# with open('videopoker_hs.pkl', 'wb') as file:
|
||||
# pickle.dump(high_score, file)
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
highScore = loadHSVp()
|
||||
if high_score['nodeID'] != 0:
|
||||
msg += f" Ranking🥇:{get_name_from_number(highScore['nodeID'])} with {highScore['highScore']} chips. "
|
||||
|
||||
if last_cmd != "":
|
||||
logger.debug(f"System: VideoPoker: {nodeID} last command: {last_cmd}")
|
||||
|
||||
+50
-29
@@ -4,6 +4,7 @@
|
||||
from random import choices, shuffle
|
||||
from modules.log import *
|
||||
import time
|
||||
import pickle
|
||||
|
||||
jack_starting_cash = 100 # Replace 100 with your desired starting cash value
|
||||
jackTracker= [{'nodeID': 0, 'cmd': 'new', 'time': time.time(), 'cash': jack_starting_cash,\
|
||||
@@ -113,15 +114,6 @@ class jackChips:
|
||||
self.total -= self.bet
|
||||
self.winnings -= 1
|
||||
|
||||
def take_bet(bet_amount, player_money):
|
||||
try:
|
||||
if bet_amount >= player_money or bet_amount <= 0:
|
||||
return f"Enter a bet amount between 1 and {player_money}"
|
||||
return bet_amount
|
||||
|
||||
except TypeError:
|
||||
return "Invalid bet amount"
|
||||
|
||||
def success_rate(card, obj_h):
|
||||
""" Calculate Success rate of 'HIT' new cards """
|
||||
msg = ""
|
||||
@@ -216,6 +208,29 @@ def setLastCmdJack(nodeID, cmd):
|
||||
return True
|
||||
return False
|
||||
|
||||
def saveHSJack(nodeID, highScore):
|
||||
# Save the game state to pickle
|
||||
highScore = {'nodeID': nodeID, 'highScore': highScore}
|
||||
try:
|
||||
with open('blackjack_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
except FileNotFoundError:
|
||||
logger.debug("System: BlackJack: Creating new blackjack_hs.pkl file")
|
||||
with open('blackjack_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
|
||||
def loadHSJack():
|
||||
try:
|
||||
with open('blackjack_hs.pkl', 'rb') as file:
|
||||
highScore = pickle.load(file)
|
||||
return highScore
|
||||
except FileNotFoundError:
|
||||
logger.debug("System: BlackJack: Creating new blackjack_hs.pkl file")
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
with open('blackjack_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
return 0
|
||||
|
||||
def playBlackJack(nodeID, message):
|
||||
# Initalize the Game
|
||||
msg, last_cmd = '', None
|
||||
@@ -243,8 +258,8 @@ def playBlackJack(nodeID, message):
|
||||
d_win = jackTracker[i]['gameStats']['d_win']
|
||||
draw = jackTracker[i]['gameStats']['draw']
|
||||
bet_money = jackTracker[i]['bet']
|
||||
p_chips.bet = bet_money
|
||||
if last_cmd == "playing":
|
||||
p_chips.bet = bet_money
|
||||
p_cards = jackTracker[i]['p_cards']
|
||||
d_cards = jackTracker[i]['d_cards']
|
||||
p_hand = jackTracker[i]['p_hand']
|
||||
@@ -262,24 +277,24 @@ def playBlackJack(nodeID, message):
|
||||
# Place Bet
|
||||
try:
|
||||
# handle B letter
|
||||
if message == "b":
|
||||
if message.lower() == "b":
|
||||
if bet_money == 0:
|
||||
bet_money = 5
|
||||
else:
|
||||
bet_money = bet_money
|
||||
else:
|
||||
bet_money = int(message)
|
||||
try:
|
||||
bet_money = int(message)
|
||||
except ValueError:
|
||||
return "Invalid Bet, please enter a valid number."
|
||||
|
||||
if bet_money <= p_chips.total or bet_money <= 1:
|
||||
p_chips.bet = take_bet(bet_money, p_chips.total)
|
||||
if bet_money <= p_chips.total and bet_money >= 1:
|
||||
p_chips.bet = bet_money
|
||||
else:
|
||||
return f"Invalid Bet, the maximum bet you can place is {p_chips.total}"
|
||||
return f"Invalid Bet, the maximum bet you can place is {p_chips.total} and the minimum bet is 1."
|
||||
except ValueError:
|
||||
return f"Invalid Bet, the maximum bet, {p_chips.total}"
|
||||
|
||||
# Show the cards
|
||||
msg += show_some(p_cards, d_cards, p_hand)
|
||||
|
||||
# check for blackjack 21 and only two cards
|
||||
if p_hand.value == 21 and len(p_hand.cards) == 2:
|
||||
msg += "Player 🎰 BLAAAACKJACKKKK 💰"
|
||||
@@ -288,7 +303,7 @@ def playBlackJack(nodeID, message):
|
||||
# Save the game state
|
||||
for i in range(len(jackTracker)):
|
||||
if jackTracker[i]['nodeID'] == nodeID:
|
||||
jackTracker[i]['cash'] = p_chips.total
|
||||
jackTracker[i]['cash'] = int(p_chips.total)
|
||||
break
|
||||
else:
|
||||
# Display the statistics
|
||||
@@ -357,11 +372,11 @@ def playBlackJack(nodeID, message):
|
||||
# Save the game state
|
||||
for i in range(len(jackTracker)):
|
||||
if jackTracker[i]['nodeID'] == nodeID:
|
||||
jackTracker[i]['cash'] = p_chips.total
|
||||
jackTracker[i]['bet'] = p_chips.bet
|
||||
jackTracker[i]['gameStats']['p_win'] = p_win
|
||||
jackTracker[i]['gameStats']['d_win'] = d_win
|
||||
jackTracker[i]['gameStats']['draw'] = draw
|
||||
jackTracker[i]['cash'] = int(p_chips.total)
|
||||
jackTracker[i]['bet'] = int(p_chips.bet)
|
||||
jackTracker[i]['gameStats']['p_win'] = int(p_win)
|
||||
jackTracker[i]['gameStats']['d_win'] = int(d_win)
|
||||
jackTracker[i]['gameStats']['draw'] = int(draw)
|
||||
jackTracker[i]['p_cards'] = p_cards
|
||||
jackTracker[i]['d_cards'] = d_cards
|
||||
jackTracker[i]['p_hand'] = p_hand
|
||||
@@ -378,10 +393,10 @@ def playBlackJack(nodeID, message):
|
||||
# recall the game state
|
||||
for i in range(len(jackTracker)):
|
||||
if jackTracker[i]['nodeID'] == nodeID:
|
||||
p_chips.total = int(jackTracker[i]['cash'])
|
||||
p_chips.bet = int(jackTracker[i]['bet'])
|
||||
p_win = int(jackTracker[i]['gameStats']['p_win'])
|
||||
d_win = int(jackTracker[i]['gameStats']['d_win'])
|
||||
p_chips.total = jackTracker[i]['cash']
|
||||
p_chips.bet = jackTracker[i]['bet']
|
||||
p_win = jackTracker[i]['gameStats']['p_win']
|
||||
d_win = jackTracker[i]['gameStats']['d_win']
|
||||
draw = jackTracker[i]['gameStats']['draw']
|
||||
p_cards = jackTracker[i]['p_cards']
|
||||
d_cards = jackTracker[i]['d_cards']
|
||||
@@ -426,7 +441,13 @@ def playBlackJack(nodeID, message):
|
||||
msg += "💸NO MORE MONEY! Game Over!"
|
||||
p_chips.total = jack_starting_cash
|
||||
else:
|
||||
msg += f"💰You have {p_chips.total} chips left"
|
||||
# check high score
|
||||
highScore = loadHSJack()
|
||||
if highScore != 0 and p_chips.total > highScore['highScore']:
|
||||
msg += f"🎉New High Score! {p_chips.total} "
|
||||
saveHSJack(nodeID, p_chips.total)
|
||||
else:
|
||||
msg += f"💰You have {p_chips.total} chips "
|
||||
|
||||
msg += "(B)et or (L)eave table."
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Adapted for Meshtastic mesh-bot by K7MHI Kelly Keeton 2024
|
||||
import random
|
||||
import time
|
||||
import pickle
|
||||
from modules.log import *
|
||||
|
||||
vpStartingCash = 20
|
||||
@@ -272,6 +273,30 @@ def setLastCmdVp(nodeID, cmd):
|
||||
if vpTracker[i]['nodeID'] == nodeID:
|
||||
vpTracker[i]['cmd'] = cmd
|
||||
|
||||
def saveHSVp(nodeID, highScore):
|
||||
# Save the game high_score to pickle
|
||||
highScore = {'nodeID': nodeID, 'highScore': highScore}
|
||||
try:
|
||||
with open('videopoker_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
except FileNotFoundError:
|
||||
logger.debug("System: BlackJack: Creating new videopoker_hs.pkl file")
|
||||
with open('videopoker_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
|
||||
def loadHSVp():
|
||||
# Load the game high_score from pickle
|
||||
try:
|
||||
with open('videopoker_hs.pkl', 'rb') as file:
|
||||
highScore = pickle.load(file)
|
||||
return highScore
|
||||
except FileNotFoundError:
|
||||
logger.debug("System: VideoPoker: Creating new videopoker_hs.pkl file")
|
||||
highScore = {'nodeID': 0, 'highScore': 0}
|
||||
with open('videopoker_hs.pkl', 'wb') as file:
|
||||
pickle.dump(highScore, file)
|
||||
return 0
|
||||
|
||||
def playVideoPoker(nodeID, message):
|
||||
msg = ""
|
||||
|
||||
@@ -406,6 +431,8 @@ def playVideoPoker(nodeID, message):
|
||||
elif player.bankroll > vpTracker[i]['highScore']:
|
||||
vpTracker[i]['highScore'] = player.bankroll
|
||||
msg += " 🎉HighScore!"
|
||||
# save high score
|
||||
saveHSVp(nodeID, vpTracker[i]['highScore'])
|
||||
|
||||
msg += f"\nPlace your Bet, 'L' to leave the game."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user