From 6c27b5d5de70aecb8949757a2cbe5550bf179b29 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Mon, 6 Oct 2025 18:03:22 -0700 Subject: [PATCH] xoxo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enhance❌ --- config.template | 1 + mesh_bot.py | 8 +++++- modules/games/tictactoe.py | 59 ++++++++++++++++++++++++++++++-------- modules/settings.py | 3 +- modules/system.py | 3 +- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/config.template b/config.template index e6d4192..6505193 100644 --- a/config.template +++ b/config.template @@ -323,6 +323,7 @@ IMAP_FOLDER = inbox [games] # if hop limit for the user exceeds this value, the message will be dropped game_hop_limit = 5 +disable_emojis = False # enable or disable the games module(s) dopeWars = True lemonade = True diff --git a/mesh_bot.py b/mesh_bot.py index 1cfd8a6..67503b6 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -43,6 +43,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n "checkin": lambda: handle_checklist(message, message_from_id, deviceID), "checklist": lambda: handle_checklist(message, message_from_id, deviceID), "checkout": lambda: handle_checklist(message, message_from_id, deviceID), + "chess": lambda: handle_gTnW(chess=True), "clearsms": lambda: handle_sms(message_from_id, message), "cmd": lambda: handle_cmd(message, message_from_id, deviceID), "cq": lambda: handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, channel_number), @@ -544,12 +545,17 @@ def handleDopeWars(message, nodeID, rxNode): time.sleep(responseDelay + 1) return msg -def handle_gTnW(): +def handle_gTnW(chess = False): + chess = ["How about a nice game of chess?", "Shall we play a game of chess?", "Would you like to play a game of chess?", "f3, to e5, g4??"] response = ["The only winning move is not to play.", "What are you doing, Dave?",\ "Greetings, Professor Falken.", "Shall we play a game?", "How about a nice game of chess?",\ "You are a hard man to reach. Could not find you in Seattle and no terminal is in operation at your classified address.",\ "I should reach Defcon 1 and release my missiles in 28 hours.","T-minus thirty","Malfunction 54: Treatment pause;dose input 2", "reticulating splines"] length = len(response) + chess_length = len(chess) + if chess: + response = chess + length = chess_length indices = list(range(length)) # Shuffle the indices using a convoluted method for i in range(length): diff --git a/modules/games/tictactoe.py b/modules/games/tictactoe.py index 7f26398..fff6cdd 100644 --- a/modules/games/tictactoe.py +++ b/modules/games/tictactoe.py @@ -1,25 +1,45 @@ # Tic-Tac-Toe game for Meshtastic mesh-bot # Board positions chosen by numbers 1-9 # 2025 +from modules.log import * import random # to molly and jake, I miss you both so much. +if disable_emojis_in_games: + X = "X" + O = "O" +else: + X = "❌" + O = "⭕️" + class TicTacToe: def __init__(self): self.game = {} def new_game(self, id): + positiveThoughts = ["🚀I need to call NATO", + "🏅Going for the gold!", + "Mastering ❌TTT⭕️",] + sorryNotGoinWell = ["😭Not your day, huh?", + "📉Results here dont define you.", + "🤖WOPR would be proud."] """Start a new game""" games = won = 0 ret = "" if id in self.game: games = self.game[id]["games"] won = self.game[id]["won"] - ret += f"Games:{games} Won:{won}\n" + if games > 0: + if won / games >= 3.14159265358979323846: # win rate > pi + ret += random.choice(positiveThoughts) + "\n" + else: + ret += random.choice(sorryNotGoinWell) + "\n" + # Retain stats + ret += f"Games:{games} 🥇❌:{won}\n" self.game[id] = { "board": [" "] * 9, # 3x3 board as flat list - "player": "X", # Human is X, bot is O + "player": X, # Human is X, bot is O "games": games + 1, "won": won, "turn": "human" # whose turn it is @@ -39,13 +59,17 @@ class TicTacToe: row = "" for j in range(3): pos = i * 3 + j - cell = b[pos] if b[pos] != " " else str(pos + 1) + if disable_emojis_in_games: + cell = b[pos] if b[pos] != " " else str(pos + 1) + else: + cell = b[pos] if b[pos] != " " else f" {str(pos + 1)} " row += cell if j < 2: - row += "|" + row += " | " board_str += row if i < 2: - board_str += "\n-+-+-\n" + #board_str += "\n-+-+-\n" + board_str += "\n" return board_str + "\n" @@ -62,7 +86,7 @@ class TicTacToe: return False # Make human move - g["board"][pos] = "X" + g["board"][pos] = X return True def bot_move(self, id): @@ -70,14 +94,14 @@ class TicTacToe: g = self.game[id] # Simple AI: Try to win, block, or pick random - move = self.find_winning_move(id, "O") # Try to win + move = self.find_winning_move(id, O) # Try to win if move == -1: - move = self.find_winning_move(id, "X") # Block player + move = self.find_winning_move(id, X) # Block player if move == -1: move = self.find_random_move(id) # Random move if move != -1: - g["board"][move] = "O" + g["board"][move] = O return move def find_winning_move(self, id, player): @@ -129,10 +153,10 @@ class TicTacToe: g = self.game[id] winner = self.check_winner(id) - if winner == "X": + if winner == X: g["won"] += 1 return "🎉You won! (n)ew (e)nd" - elif winner == "O": + elif winner == X: return "🤖Bot wins! (n)ew (e)nd" else: return "🤝Tie game! (n)ew (e)nd" @@ -143,7 +167,7 @@ class TicTacToe: return self.new_game(id) # If input is just "tictactoe", show current board - if input_msg.lower().strip() == "tictactoe": + if input_msg.lower().strip() == ("tictactoe" or "tic-tac-toe"): return self.show_board(id) + "Your turn! Pick 1-9:" g = self.game[id] @@ -201,8 +225,19 @@ class TicTacToe: def end_game(self, id): """Clean up finished game but keep stats""" if id in self.game: + games = self.game[id]["games"] + won = self.game[id]["won"] # Remove game but we'll create new one on next play del self.game[id] + # Preserve stats for next game + self.game[id] = { + "board": [" "] * 9, + "player": X, + "games": games, + "won": won, + "turn": "human" + } + def end(self, id): """End game completely (called by 'end' command)""" diff --git a/modules/settings.py b/modules/settings.py index 4c02dfc..13015b8 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -362,7 +362,8 @@ try: allowXcmd = config['fileMon'].getboolean('allowXcmd', False) # default False # games - game_hop_limit = config['messagingSettings'].getint('game_hop_limit', 5) # default 3 hops + game_hop_limit = config['games'].getint('game_hop_limit', 5) # default 5 hops + disable_emojis_in_games = config['games'].getboolean('disable_emojis', False) # default False dopewars_enabled = config['games'].getboolean('dopeWars', True) lemonade_enabled = config['games'].getboolean('lemonade', True) blackjack_enabled = config['games'].getboolean('blackjack', True) diff --git a/modules/system.py b/modules/system.py index 2ac2471..a07a0ea 100644 --- a/modules/system.py +++ b/modules/system.py @@ -276,7 +276,8 @@ if games_enabled is True: if lemonade_enabled: gamesCmdList += "lemonStand, " if gTnW_enabled: - trap_list = trap_list + ("globalthermonuclearwar",) + trap_list = trap_list + ("globalthermonuclearwar","chess") + gamesCmdList += "chess, " if blackjack_enabled: gamesCmdList += "blackJack, " if videoPoker_enabled: