From 08851182a74698be1848dfc2a76aea690b3ed21f Mon Sep 17 00:00:00 2001 From: jona605a Date: Sat, 8 Aug 2020 13:47:38 +0200 Subject: [PATCH] :exclamation: Surrender!! --- funcs/games/gameLoops.py | 2 +- funcs/games/hex.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/funcs/games/gameLoops.py b/funcs/games/gameLoops.py index 418b523..b7bf606 100644 --- a/funcs/games/gameLoops.py +++ b/funcs/games/gameLoops.py @@ -61,7 +61,7 @@ async def runHex(channel,command,user): data = json.load(f) winner = data[str(channel.id)]["winner"] if winner != 0: - addMoney(data[str(channel.id)]["players"][winner-1].lower(),20) + addMoney(data[str(channel.id)]["players"][winner-1].lower(),50) #deleteGame("hex games",str(channel.id)) with open("resources/games/hexGames.json", "r") as f: diff --git a/funcs/games/hex.py b/funcs/games/hex.py index a1653ff..6dc1c50 100644 --- a/funcs/games/hex.py +++ b/funcs/games/hex.py @@ -53,8 +53,25 @@ def parseHex(command, channel, user): return placeHex(channel,commands[1], user) except: return "I didn't get that. To place a piece use \"!hex place [position]\". A valid position is e.g. \"E2\".", False, False, False, False + + # Undo + elif commands[0] == "undo": + return undoHex(channel, user) + + # Surrender + elif commands[0] == "surrender": + with open("resources/games/hexGames.json", "r") as f: + data = json.load(f) + players = data[channel]["players"] + if user in players: + opponent = (players.index(user) + 1) % 2 + data[channel]["winner"] = opponent + return "{} surrendered. Ending game.".format(getName(user)), False, False, True, False + else: + return "You can't surrender when you're not a player.", False, False, False, False + else: - return "I didn't get that. Use \"!hex start [opponent]\" to start a game or \"!hex stop\" to stop a current game.", False, False, False, False + return "I didn't get that. Use \"!hex start [opponent]\" to start a game, \"!hex place [position]\" to place a piece, \"!hex undo\" to undo your last move or \"!hex stop\" to stop a current game.", False, False, False, False # Starts the game @@ -248,6 +265,14 @@ def evaluateBoard(board): return score, isWon +def undoHex(channel, user): + + message = "yup" + gwendoturn = False + return message, True, True, False, gwendoturn + + + # Plays as the AI def hexAI(channel):