mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
LateNightDoubleFeature
* golfsim * masterMind New Games!
This commit is contained in:
@@ -54,6 +54,8 @@ Any messages that are over 160 characters are chunked into 160 message bytes to
|
||||
- `dopewars` plays the classic drug trader
|
||||
- `blackjack` BlackJack, Casino 21
|
||||
- `videopoker` Video Poker, basic 5 card hold
|
||||
- `mastermind` Classic code-breaking game
|
||||
- `golfsim` Golf Simulator, 9 Hole
|
||||
|
||||
## pong_bot.sh
|
||||
Stripped-down bot, mostly around for archive purposes. The mesh-bot enhanced modules can be disabled by config to disable features.
|
||||
|
||||
@@ -66,6 +66,8 @@ dopeWars = True
|
||||
lemonade = True
|
||||
blackjack = True
|
||||
videopoker = True
|
||||
mastermind = True
|
||||
golfsim = True
|
||||
|
||||
[sentry]
|
||||
# detect anyone close to the bot
|
||||
|
||||
89
mesh_bot.py
89
mesh_bot.py
@@ -40,6 +40,8 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n
|
||||
"lemonstand": lambda: handleLemonade(message_from_id, message),
|
||||
"blackjack": lambda: handleBlackJack(message_from_id, message),
|
||||
"videopoker": lambda: handleVideoPoker(message_from_id, message),
|
||||
"mastermind": lambda: handleMmind(message_from_id, message),
|
||||
"golfsim": lambda: handleGolf(message_from_id, message),
|
||||
"globalthermonuclearwar": lambda: handle_gTnW(),
|
||||
"ask:": lambda: handle_llm(message_from_id, channel_number, deviceID, message, publicChannel),
|
||||
"askai": lambda: handle_llm(message_from_id, channel_number, deviceID, message, publicChannel),
|
||||
@@ -308,7 +310,7 @@ def handle_gTnW():
|
||||
indices = list(range(length))
|
||||
# Shuffle the indices using a convoluted method
|
||||
for i in range(length):
|
||||
swap_idx = (i * 3 + 7) % length
|
||||
swap_idx = random.randint(0, length - 1)
|
||||
indices[i], indices[swap_idx] = indices[swap_idx], indices[i]
|
||||
# Select a random response from the shuffled list. anyone enjoy the game, killerbunnies(.com)
|
||||
selected_index = random.choice(indices)
|
||||
@@ -427,6 +429,60 @@ def handleVideoPoker(nodeID, message):
|
||||
time.sleep(1.5) # short answers with long replies can cause message collision added wait
|
||||
return msg
|
||||
|
||||
def handleMmind(nodeID, message):
|
||||
global mindTracker
|
||||
msg = ''
|
||||
|
||||
if "end" in message.lower() or message.lower().startswith("e"):
|
||||
logger.debug(f"System: MasterMind: {nodeID} is leaving the game")
|
||||
msg = "You have left the Game."
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
mindTracker.pop(i)
|
||||
return msg
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
last_cmd = ""
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = mindTracker[i]['cmd']
|
||||
|
||||
if last_cmd == "":
|
||||
# create new player
|
||||
logger.debug("System: MasterMind: New Player: " + str(nodeID))
|
||||
mindTracker.append({'nodeID': nodeID, 'last_played': time.time(), 'cmd': 'new', 'secret_code': 'RYGB', 'diff': 'n', 'turns': 1})
|
||||
msg = "Welcome to 🟡🔴🔵🟢MasterMind!🧠"
|
||||
msg += "Each Guess hints to correct colors, correct position, wrong position."
|
||||
msg += "You have 10 turns to guess the code. Choose a difficulty: (N)ormal or (H)ard"
|
||||
return msg
|
||||
|
||||
msg += start_mMind(nodeID=nodeID, message=message)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(1)
|
||||
return msg
|
||||
|
||||
def handleGolf(nodeID, message):
|
||||
global golfTracker
|
||||
msg = ''
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
last_cmd = ""
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = golfTracker[i]['cmd']
|
||||
|
||||
if last_cmd == "":
|
||||
# create new player
|
||||
logger.debug("System: GolfSim: New Player: " + str(nodeID))
|
||||
golfTracker.append({'nodeID': nodeID, 'last_played': time.time(), 'cmd': 'new', 'hole': 1, 'distance_remaining': 0, 'hole_shots': 0, 'hole_strokes': 0, 'hole_to_par': 0, 'total_strokes': 0, 'total_to_par': 0})
|
||||
msg = "Welcome to 🏌️GolfSim⛳️"
|
||||
msg += f"Clubs: (D)river, (H)igh Iron, (M)id Iron, (L)ow Iron, (G)ap Wedge, Lob (W)edge\n"
|
||||
|
||||
msg += playGolf(nodeID=nodeID, message=message)
|
||||
# wait a second to keep from message collision
|
||||
time.sleep(1)
|
||||
return msg
|
||||
|
||||
def handle_wxc(message_from_id, deviceID, cmd):
|
||||
location = get_node_location(message_from_id, deviceID)
|
||||
if use_meteo_wxApi and not "wxc" in cmd and not use_metric:
|
||||
@@ -701,6 +757,37 @@ def checkPlayingGame(message_from_id, message_string, rxNode, channel_number):
|
||||
else:
|
||||
# pop if the time exceeds 8 hours
|
||||
jackTracker.pop(i)
|
||||
|
||||
for i in range(0, len(mindTracker)):
|
||||
if mindTracker[i].get('nodeID') == message_from_id:
|
||||
# check if the player has played in the last 8 hours
|
||||
if mindTracker[i].get('last_played') > (time.time() - GAMEDELAY):
|
||||
playingGame = True
|
||||
game = "MasterMind"
|
||||
if llm_enabled:
|
||||
logger.debug(f"System: LLM Disabled for {message_from_id} for duration of MasterMind")
|
||||
|
||||
# play the game
|
||||
send_message(handleMmind(message_from_id, message_string), channel_number, message_from_id, rxNode)
|
||||
else:
|
||||
# pop if the time exceeds 8 hours
|
||||
mindTracker.pop(i)
|
||||
|
||||
for i in range(0, len(golfTracker)):
|
||||
if golfTracker[i].get('nodeID') == message_from_id:
|
||||
# check if the player has played in the last 8 hours
|
||||
if golfTracker[i].get('last_played') > (time.time() - GAMEDELAY):
|
||||
playingGame = True
|
||||
game = "GolfSim"
|
||||
if llm_enabled:
|
||||
logger.debug(f"System: LLM Disabled for {message_from_id} for duration of GolfSim")
|
||||
|
||||
# play the game
|
||||
send_message(handleGolf(message_from_id, message_string), channel_number, message_from_id, rxNode)
|
||||
else:
|
||||
# pop if the time exceeds 8 hours
|
||||
golfTracker.pop(i)
|
||||
|
||||
#logger.debug(f"System: {message_from_id} is playing {game}")
|
||||
return playingGame
|
||||
|
||||
|
||||
289
modules/golfsim.py
Normal file
289
modules/golfsim.py
Normal file
@@ -0,0 +1,289 @@
|
||||
# https://github.com/danfriedman30/pythongame
|
||||
# Adapted for Meshtastic mesh-bot by K7MHI Kelly Keeton 2024
|
||||
|
||||
import random
|
||||
import time
|
||||
from modules.log import *
|
||||
|
||||
# Clubs setup
|
||||
driver_distances = list(range(230, 280, 5))
|
||||
low_distances = list(range(185, 215, 5))
|
||||
mid_distances = list(range(130, 185, 5))
|
||||
high_distances = list(range(90, 135, 5))
|
||||
gap_wedge_distances = list(range(50, 85, 5))
|
||||
lob_wedge_distances = list(range(10, 50, 5))
|
||||
putt_outcomes = [1, 2, 3]
|
||||
|
||||
# Hole/Course Setup
|
||||
full_hole_range = list(range(130, 520, 5))
|
||||
par3_range = list(range(130, 255, 5))
|
||||
par4_range = list(range(255, 445, 5))
|
||||
par5_range = list(range(445, 520, 5))
|
||||
par3_4_range = par3_range + par4_range
|
||||
par3_5_range = par3_range + par5_range
|
||||
par4_5_range = par4_range + par5_range
|
||||
|
||||
# Player setup
|
||||
playingHole = False
|
||||
golfTracker = [{'nodeID': 0, 'last_played': time.time(), 'cmd': '', 'hole': 0, 'distance_remaining': 0, 'hole_shots': 0, 'hole_strokes': 0, 'hole_to_par': 0, 'total_strokes': 0, 'total_to_par': 0}]
|
||||
|
||||
# Club functions
|
||||
def hit_driver():
|
||||
club_distance = random.choice(driver_distances)
|
||||
return club_distance
|
||||
|
||||
def hit_low_iron():
|
||||
club_distance = random.choice(low_distances)
|
||||
return club_distance
|
||||
|
||||
def hit_mid_iron():
|
||||
club_distance = random.choice(mid_distances)
|
||||
return club_distance
|
||||
|
||||
def hit_high_iron():
|
||||
club_distance = random.choice(high_distances)
|
||||
return club_distance
|
||||
|
||||
def hit_gap_wedge():
|
||||
club_distance = random.choice(gap_wedge_distances)
|
||||
return club_distance
|
||||
|
||||
def hit_lob_wedge():
|
||||
club_distance = random.choice(lob_wedge_distances)
|
||||
return club_distance
|
||||
|
||||
def finish_hole():
|
||||
finish = random.choice(putt_outcomes)
|
||||
return finish
|
||||
|
||||
# Main game loop
|
||||
def playGolf(nodeID, message):
|
||||
msg = ''
|
||||
global golfTracker
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
last_cmd = ""
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = golfTracker[i]['cmd']
|
||||
hole = golfTracker[i]['hole']
|
||||
|
||||
if last_cmd == "" or last_cmd == "new":
|
||||
par3_count = 0
|
||||
par4_count = 0
|
||||
par5_count = 0
|
||||
# Scorecard setup
|
||||
total_strokes = 0
|
||||
total_to_par = 0
|
||||
|
||||
if hole <= 9:
|
||||
# Set up hole count restrictions on par
|
||||
if par3_count < 2 and par4_count < 5 and par5_count < 2:
|
||||
hole_length = random.choice(full_hole_range)
|
||||
if par3_count >= 2 and par4_count < 5 and par5_count < 2:
|
||||
hole_length = random.choice(par4_5_range)
|
||||
if par3_count >= 2 and par4_count < 5 and par5_count >= 2:
|
||||
hole_length = random.choice(par4_range)
|
||||
if par3_count < 2 and par4_count < 5 and par5_count >= 2:
|
||||
hole_length = random.choice(par3_4_range)
|
||||
if par3_count < 2 and par4_count >= 5 and par5_count >= 2:
|
||||
hole_length = random.choice(par3_range)
|
||||
if par3_count >= 2 and par4_count >= 5 and par5_count < 2:
|
||||
hole_length = random.choice(par5_range)
|
||||
if par3_count < 2 and par4_count >= 5 and par5_count < 2:
|
||||
hole_length = random.choice(par3_5_range)
|
||||
|
||||
# Set up par for the hole
|
||||
if hole_length <= 250:
|
||||
par = 3
|
||||
par3_count += 1
|
||||
elif hole_length > 250 and hole_length <= 440:
|
||||
par = 4
|
||||
par4_count += 1
|
||||
elif hole_length > 440:
|
||||
par = 5
|
||||
par5_count += 1
|
||||
|
||||
# Set initial parameters before starting a hole
|
||||
distance_remaining = hole_length
|
||||
hole_shots = 0
|
||||
|
||||
# save player's current game state
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
golfTracker[i]['distance_remaining'] = distance_remaining
|
||||
golfTracker[i]['cmd'] = 'stroking'
|
||||
golfTracker[i]['par'] = par
|
||||
golfTracker[i]['total_strokes'] = total_strokes
|
||||
golfTracker[i]['total_to_par'] = total_to_par
|
||||
|
||||
# Show player the hole information
|
||||
msg += "⛳️#" + str(hole) + " is a " + str(hole_length) + "-yard Par " + str(par) + "."
|
||||
# add weather conditions with random choice from list
|
||||
msg += " Cond:" + random.choice(["Calm", "Breezy", "Calm", "Calm", "Gusty", "Windy", "Calm"]) + "."
|
||||
msg += f"\nChoose your club."
|
||||
|
||||
return msg
|
||||
|
||||
if last_cmd == 'stroking':
|
||||
|
||||
# Get player's current game state
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
distance_remaining = golfTracker[i]['distance_remaining']
|
||||
hole = golfTracker[i]['hole']
|
||||
hole_shots = golfTracker[i]['hole_shots']
|
||||
par = golfTracker[i]['par']
|
||||
total_strokes = golfTracker[i]['total_strokes']
|
||||
total_to_par = golfTracker[i]['total_to_par']
|
||||
|
||||
# Start loop to be able to choose clubs while at least 20 yards away
|
||||
if distance_remaining >= 20:
|
||||
msg = ""
|
||||
club = message.lower()
|
||||
shot_distance = 0
|
||||
|
||||
pin_distance = distance_remaining
|
||||
|
||||
if club == "driver" or club.startswith("d"):
|
||||
shot_distance = hit_driver()
|
||||
msg += "You hit your Driver " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
elif "low" in club or club.startswith("l"):
|
||||
shot_distance = hit_low_iron()
|
||||
msg += "You hit your Low Iron " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
elif "mid" in club or club.startswith("m"):
|
||||
shot_distance = hit_mid_iron()
|
||||
msg += "You hit your Mid Iron " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
elif "high" in club or club.startswith("h"):
|
||||
shot_distance = hit_high_iron()
|
||||
msg += "You hit your High Iron " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
elif "gap" in club or club.startswith("g"):
|
||||
shot_distance = hit_gap_wedge()
|
||||
msg += "You hit your Gap Wedge " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
elif "wedge" in club or club.startswith("w"):
|
||||
shot_distance = hit_lob_wedge()
|
||||
msg += "You hit your Lob Wedge " + str(shot_distance) + " yards."
|
||||
distance_remaining = abs(distance_remaining - shot_distance)
|
||||
hole_shots += 1
|
||||
|
||||
if distance_remaining - pin_distance > pin_distance or shot_distance > pin_distance:
|
||||
msg += "You've hit it past the hole!😖"
|
||||
|
||||
if distance_remaining == 0:
|
||||
msg += "💰Perfect shot! "
|
||||
last_cmd = 'putt'
|
||||
elif distance_remaining < 20:
|
||||
# Roll Dice
|
||||
hole_in_one_chance = random.randint(1, 100)
|
||||
wind_factor = random.randint(1, 10)
|
||||
skill_factor = random.randint(1, 10)
|
||||
critter_factor = random.randint(1, 50)
|
||||
# Check for hole in one
|
||||
if hole_in_one_chance <= 5 and wind_factor > 7 and skill_factor > 8:
|
||||
distance_remaining = 0
|
||||
# Check for critters
|
||||
if skill_factor > 8 and critter_factor < 40 and wind_factor > 2 and hole_in_one_chance > 5:
|
||||
msg += random.choice["A 🐿️ steals your ball!😡","You Hit a 🦅 soring past"]
|
||||
distance_remaining = -1
|
||||
|
||||
# Send to putting
|
||||
last_cmd = 'putt'
|
||||
else:
|
||||
msg += "You have " + str(distance_remaining) + " yards left."
|
||||
msg += "Club?[D, H, M, L, G, W]🏌️"
|
||||
|
||||
# save player's current game state, keep stroking
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
golfTracker[i]['distance_remaining'] = distance_remaining
|
||||
golfTracker[i]['hole_shots'] = hole_shots
|
||||
golfTracker[i]['cmd'] = 'stroking'
|
||||
|
||||
return msg
|
||||
|
||||
if last_cmd == 'putt':
|
||||
# Finish the hole by putting
|
||||
critter = False
|
||||
if distance_remaining < 20:
|
||||
if distance_remaining == 0:
|
||||
putts = 0
|
||||
elif distance_remaining == -1:
|
||||
putts = 0
|
||||
critter = True
|
||||
else:
|
||||
putts = finish_hole()
|
||||
|
||||
if not critter:
|
||||
# Calculate hole and round scores
|
||||
hole_strokes = hole_shots + putts
|
||||
hole_to_par = hole_strokes - par
|
||||
total_strokes += hole_strokes
|
||||
total_to_par += hole_to_par
|
||||
|
||||
# Show player hole/round scoring info
|
||||
if putts == 0 and hole_strokes == 1:
|
||||
msg += "🎯Hole in one!⛳️"
|
||||
elif putts == 0:
|
||||
msg += "You're in the hole at " + str(hole_strokes) + " strokes!"
|
||||
else:
|
||||
msg += "You're on the green! After " + str(putts) + " putt(s), you're in for " + str(hole_strokes) + " strokes."
|
||||
|
||||
if hole_to_par > 0:
|
||||
msg += "Your score for the hole is +" + str(hole_to_par) + " to par."
|
||||
elif hole_to_par == 0:
|
||||
msg += "Your score for the hole is even to par."
|
||||
else:
|
||||
msg += "Your score for the hole is " + str(hole_to_par) + " to par."
|
||||
|
||||
msg += "You've hit a total of " + str(total_strokes) + " strokes so far."
|
||||
if total_to_par > 0:
|
||||
msg += "Your score for the round is +" + str(total_to_par) + " to par."
|
||||
elif total_to_par == 0:
|
||||
msg += "Your score for the round is even to par."
|
||||
else:
|
||||
msg += "Your score for the round is " + str(total_to_par) + " to par."
|
||||
|
||||
# Move to next hole
|
||||
hole += 1
|
||||
else:
|
||||
msg += "🐿️ you ran to the pro-shop to get a new ball, they put you back at the same hole"
|
||||
|
||||
# Save player's current game state
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
golfTracker[i]['hole_strokes'] = hole_strokes
|
||||
golfTracker[i]['hole_to_par'] = hole_to_par
|
||||
golfTracker[i]['total_strokes'] = total_strokes
|
||||
golfTracker[i]['total_to_par'] = total_to_par
|
||||
golfTracker[i]['hole'] = hole
|
||||
golfTracker[i]['cmd'] = 'new'
|
||||
|
||||
if hole >= 9:
|
||||
# Final score messages & exit prompt
|
||||
msg += f"\n🎉Finished 9-hole round⛳️"
|
||||
msg += "Total strokes " + str(total_strokes) + "."
|
||||
if total_to_par > 0:
|
||||
msg += "Your score for the day is +" + str(total_to_par) + " to par."
|
||||
elif total_to_par == 0:
|
||||
msg += "Your score for the day is even to par."
|
||||
else:
|
||||
msg += "Your score for the day is " + str(total_to_par) + " to par."
|
||||
# pop player from tracker
|
||||
for i in range(len(golfTracker)):
|
||||
if golfTracker[i]['nodeID'] == nodeID:
|
||||
golfTracker.pop(i)
|
||||
logger.debug("System: GolfSim: Player " + str(nodeID) + " has finished their round.")
|
||||
else:
|
||||
msg += "⛳️#" + str(hole) + " is next, keep playing? or (E)nd the round."
|
||||
|
||||
return msg
|
||||
216
modules/mmind.py
Normal file
216
modules/mmind.py
Normal file
@@ -0,0 +1,216 @@
|
||||
# https://github.com/pwdkramer/pythonMastermind/blob/main/main.py
|
||||
# Adapted for Meshtastic mesh-bot by K7MHI Kelly Keeton 2024
|
||||
|
||||
import random
|
||||
import time
|
||||
from modules.log import *
|
||||
|
||||
mindTracker = [{'nodeID': 0, 'last_played': time.time(), 'cmd': '', 'secret_code': '', 'diff': 'n', 'turns': 1}]
|
||||
|
||||
def chooseDifficultyMMind(message):
|
||||
usrInput = message.lower()
|
||||
msg = ''
|
||||
valid_colorsMMind = "RYGB"
|
||||
|
||||
if not usrInput.startswith("n") and not usrInput.startswith("h"):
|
||||
msg += "Please enter either '(N)ormal' or '(H)ard'"
|
||||
|
||||
if usrInput == "n":
|
||||
msg += "The colors to choose from are: R🔴, Y🟡, G🟢, B🔵"
|
||||
elif usrInput == "h":
|
||||
valid_colorsMMind += "OP"
|
||||
msg += "The colors to choose from are R🔴, Y🟡, G🟢, B🔵, O🟠, P🟣"
|
||||
return msg
|
||||
|
||||
|
||||
#possible colors on nomral: Red, Yellow, Green, Blue
|
||||
#added colors on hard: Orange, Purple
|
||||
def makeCodeMMind(diff):
|
||||
secret_code = ""
|
||||
for i in range(4):
|
||||
if diff == "n":
|
||||
roll = random.randrange(1, 5)
|
||||
elif diff == "h":
|
||||
roll = random.randrange(1,7)
|
||||
else:
|
||||
print("Difficulty error in makeCode()")
|
||||
if roll == 1:
|
||||
secret_code += "R"
|
||||
elif roll == 2:
|
||||
secret_code += "Y"
|
||||
elif roll == 3:
|
||||
secret_code += "G"
|
||||
elif roll == 4:
|
||||
secret_code += "B"
|
||||
elif roll == 5:
|
||||
secret_code += "O"
|
||||
elif roll == 6:
|
||||
secret_code += "P"
|
||||
else:
|
||||
print("Error with range of roll in makeCode()")
|
||||
return secret_code
|
||||
|
||||
#get guess from user
|
||||
def getGuessMMind(diff, guess):
|
||||
msg = ''
|
||||
if diff == "n":
|
||||
valid_colorsMMind = "RYGB"
|
||||
elif diff == "h":
|
||||
valid_colorsMMind = "RYGBOP"
|
||||
|
||||
user_guess = guess.upper()
|
||||
valid_guess = True
|
||||
if len(user_guess) != 4:
|
||||
valid_guess = False
|
||||
for i in range(len(user_guess)):
|
||||
if user_guess[i] not in valid_colorsMMind:
|
||||
valid_guess = False
|
||||
if valid_guess == False:
|
||||
user_guess = "XXXX"
|
||||
return user_guess
|
||||
|
||||
def getEmojiMMind(secret_code):
|
||||
# for each letter in the secret code, convert to emoji for display
|
||||
secret_code = secret_code.upper()
|
||||
secret_code_emoji = ""
|
||||
for i in range(len(secret_code)):
|
||||
if secret_code[i] == "R":
|
||||
secret_code_emoji += "🔴"
|
||||
elif secret_code[i] == "Y":
|
||||
secret_code_emoji += "🟡"
|
||||
elif secret_code[i] == "G":
|
||||
secret_code_emoji += "🟢"
|
||||
elif secret_code[i] == "B":
|
||||
secret_code_emoji += "🔵"
|
||||
elif secret_code[i] == "O":
|
||||
secret_code_emoji += "🟠"
|
||||
elif secret_code[i] == "P":
|
||||
secret_code_emoji += "🟣"
|
||||
return secret_code_emoji
|
||||
|
||||
#compare userGuess with secret code and provide feedback
|
||||
def compareCodeMMind(secret_code, user_guess):
|
||||
game_won = False
|
||||
perfect_pins = 0
|
||||
wrong_position = 0
|
||||
msg = ''
|
||||
if secret_code == user_guess: #correct guess, user wins
|
||||
perfect_pins = 4
|
||||
else: #provide feedback on guess
|
||||
temp_code = []
|
||||
temp_guess = []
|
||||
for i in range(len(user_guess)): #check for perfect pins
|
||||
if user_guess[i] == secret_code[i]:
|
||||
perfect_pins += 1
|
||||
else:
|
||||
temp_code.append(secret_code[i])
|
||||
temp_guess.append(user_guess[i])
|
||||
for i in range(len(temp_guess)): #check for right color wrong position
|
||||
for j in range(len(temp_code)):
|
||||
if temp_guess[i] == temp_code[j]:
|
||||
wrong_position += 1
|
||||
temp_code[j] = "0"
|
||||
break
|
||||
msg += "Guess:{}\n".format(getEmojiMMind(user_guess))
|
||||
if perfect_pins > 0:
|
||||
msg += "✅ color ✅ position: {}\n".format(perfect_pins)
|
||||
if wrong_position > 0:
|
||||
msg += "✅ color 🚫 position: {}".format(wrong_position)
|
||||
|
||||
if "✅" not in msg:
|
||||
msg += "🚫No correct pins in your guess.😿"
|
||||
|
||||
return msg
|
||||
|
||||
#game loop with turn counter
|
||||
def playGameMMind(diff, secret_code, turn_count, nodeID, message):
|
||||
msg = ''
|
||||
if turn_count <= 10:
|
||||
user_guess = getGuessMMind(diff, message)
|
||||
if user_guess == "XXXX":
|
||||
msg += "Invalid guess. Please enter 4 valid colors."
|
||||
return msg
|
||||
check_guess = compareCodeMMind(secret_code, user_guess)
|
||||
|
||||
if "✅ position: 4" in check_guess:
|
||||
won = True
|
||||
else:
|
||||
won = False
|
||||
|
||||
msg += "Turn {}:".format(turn_count)
|
||||
msg += check_guess
|
||||
if won == True:
|
||||
msg += "\n🎉🧠 You guessed the code! {}".format(getEmojiMMind(secret_code))
|
||||
endGameMMind(nodeID)
|
||||
elif turn_count >= 11 and won == False:
|
||||
msg += "\nGame Over! The code was: {}".format(getEmojiMMind(secret_code))
|
||||
endGameMMind(nodeID)
|
||||
turn_count += 1
|
||||
# store turn count in tracker
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
mindTracker[i]['turns'] = turn_count
|
||||
return msg
|
||||
|
||||
def endGameMMind(nodeID):
|
||||
global mindTracker
|
||||
# remove player from tracker
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
del mindTracker[i]
|
||||
logger.debug("System: MasterMind: Player removed: " + str(nodeID))
|
||||
break
|
||||
|
||||
#main game
|
||||
def start_mMind(nodeID, message):
|
||||
global mindTracker
|
||||
last_cmd = ""
|
||||
msg = ''
|
||||
|
||||
# get player's last command from tracker if not new player
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
last_cmd = mindTracker[i]['cmd']
|
||||
|
||||
logger.debug("System: MasterMind: last_cmd: " + str(last_cmd))
|
||||
|
||||
if last_cmd == "new":
|
||||
if message.lower().startswith("n") or message.lower().startswith("h"):
|
||||
diff = message.lower()[0]
|
||||
else:
|
||||
diff = "n"
|
||||
|
||||
# set player's last command to makeCode
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
mindTracker[i]['cmd'] = 'makeCode'
|
||||
mindTracker[i]['diff'] = diff
|
||||
# Return color message to player
|
||||
msg += chooseDifficultyMMind(message.lower()[0])
|
||||
return msg
|
||||
|
||||
if last_cmd == "makeCode":
|
||||
# get difficulty from tracker
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
diff = mindTracker[i]['diff']
|
||||
|
||||
secret_code = makeCodeMMind(diff)
|
||||
last_cmd = "playGame"
|
||||
# set player's last command to playGame
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
mindTracker[i]['cmd'] = 'playGame'
|
||||
mindTracker[i]['secret_code'] = secret_code
|
||||
|
||||
if last_cmd == "playGame":
|
||||
# get difficulty, secret code, and turn count from tracker
|
||||
for i in range(len(mindTracker)):
|
||||
if mindTracker[i]['nodeID'] == nodeID:
|
||||
diff = mindTracker[i]['diff']
|
||||
secret_code = mindTracker[i]['secret_code']
|
||||
turn_count = mindTracker[i]['turns']
|
||||
|
||||
msg += playGameMMind(diff, secret_code, turn_count, nodeID=nodeID, message=message)
|
||||
|
||||
return msg
|
||||
@@ -155,6 +155,8 @@ try:
|
||||
lemonade_enabled = config['games'].getboolean('lemonade', True)
|
||||
blackjack_enabled = config['games'].getboolean('blackjack', True)
|
||||
videoPoker_enabled = config['games'].getboolean('videoPoker', True)
|
||||
mastermind_enabled = config['games'].getboolean('mastermind', True)
|
||||
golfSim_enabled = config['games'].getboolean('golfSim', True)
|
||||
|
||||
# messaging settings
|
||||
responseDelay = config['messagingSettings'].getfloat('responseDelay', 0.7) # default 0.7
|
||||
|
||||
@@ -117,6 +117,16 @@ if videoPoker_enabled:
|
||||
from modules.videopoker import * # from the spudgunman/meshing-around repo
|
||||
trap_list = trap_list + ("videopoker",)
|
||||
games_enabled = True
|
||||
|
||||
if mastermind_enabled:
|
||||
from modules.mmind import * # from the spudgunman/meshing-around repo
|
||||
trap_list = trap_list + ("mastermind",)
|
||||
games_enabled = True
|
||||
|
||||
if golfSim_enabled:
|
||||
from modules.golfsim import * # from the spudgunman/meshing-around repo
|
||||
trap_list = trap_list + ("golfsim",)
|
||||
games_enabled = True
|
||||
|
||||
# Games Configuration
|
||||
if games_enabled is True:
|
||||
@@ -125,15 +135,19 @@ if games_enabled is True:
|
||||
gTnW_enabled = True
|
||||
gamesCmdList = "Play via DM🕹️ CMD: "
|
||||
if dopewars_enabled:
|
||||
gamesCmdList += "DopeWars, "
|
||||
gamesCmdList += "dopeWars, "
|
||||
if lemonade_enabled:
|
||||
gamesCmdList += "LemonStand, "
|
||||
gamesCmdList += "lemonStand, "
|
||||
if gTnW_enabled:
|
||||
trap_list = trap_list + ("globalthermonuclearwar",)
|
||||
if blackjack_enabled:
|
||||
gamesCmdList += "BlackJack, "
|
||||
gamesCmdList += "blackJack, "
|
||||
if videoPoker_enabled:
|
||||
gamesCmdList += "VideoPoker, "
|
||||
gamesCmdList += "videoPoker, "
|
||||
if mastermind_enabled:
|
||||
gamesCmdList += "masterMind, "
|
||||
if golfSim_enabled:
|
||||
gamesCmdList += "golfSim, "
|
||||
gamesCmdList = gamesCmdList[:-2] # remove the last comma
|
||||
else:
|
||||
gamesCmdList = ""
|
||||
|
||||
Reference in New Issue
Block a user