You can now go back in time! With "!hex undo" !

This commit is contained in:
jona605a
2020-08-08 14:16:31 +02:00
parent 08851182a7
commit 8be15b6dd5
2 changed files with 29 additions and 16 deletions

View File

@ -26,7 +26,7 @@ HEX_DIRECTIONS = [(0,1),(-1,1),(-1,0),(0,-1),(1,-1),(1,0)]
# Parses command
def parseHex(command, channel, user):
commands = command.split()
commands = command.lower().split()
if command == "" or command == " ":
return "I didn't get that. Use \"!hex start [opponent]\" to start a game.", False, False, False, False
@ -108,7 +108,7 @@ def hexStart(channel, user, opponent):
players = [user,opponent]
random.shuffle(players) # random starting player
winningPieces = [[""],[""],[""]] # etc.
lastMove = (5,5)
lastMove = (-1,-1)
data[channel] = {"board":board, "winner":0,
"players":players, "winningPieces":winningPieces, "turn":1, "difficulty":difficulty, "lastMove":lastMove}
@ -266,14 +266,37 @@ def evaluateBoard(board):
return score, isWon
def undoHex(channel, user):
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
if user in data[channel]["players"]:
if data[channel]["lastMove"] != (-1,-1):
turn = data[channel]["turn"]
# You can only undo after your turn, which is the opponent's turn.
if user == data[channel]["players"][(turn % 2)]: # If it's not your turn
logThis("Undoing {}'s last move".format(getName(user)))
lastMove = data[channel]["lastMove"]
data[channel]["board"][lastMove[0]][lastMove[1]] = 0
data[channel]["turn"] = turn%2 + 1
# Update the board
hexDraw.drawHexPlacement(channel,0,"abcdefghijk"[lastMove[1]]+str(lastMove[0]+1))
return "You undid", True, True, False, False
else:
# Sassy
return "Nice try. You can't undo your opponent's move. ", False, False, False, False
else:
# Sassy
return "Really? You undo right at the start of the game?", False, False, False, False
else:
return "You're not a player in the game", False, False, False, False
message = "yup"
gwendoturn = False
return message, True, True, False, gwendoturn
# Plays as the AI
def hexAI(channel):
logThis("Figuring out best move")