🧹 Last bit of cleaning up before pushing

This commit is contained in:
NikolajDanger
2021-03-31 01:02:32 +02:00
parent b345720468
commit 6c1a1cf626
37 changed files with 125 additions and 118 deletions

View File

@ -22,13 +22,13 @@ class HexGame():
commands = command.lower().split()
game = self.bot.database["hex games"].find_one({"_id":channel})
if command == "" or command == " ":
return "I didn't get that. Use \"!hex start [opponent]\" to start a game.", False, False, False, False
return "I didn't get that. Use \"/hex start [opponent]\" to start a game.", False, False, False, False
elif commands[0] == "start":
# Starting a game
if len(commands) == 1: # if the commands is "!hex start", the opponent is Gwendolyn at difficulty 2
if len(commands) == 1: # if the commands is "/hex start", the opponent is Gwendolyn at difficulty 2
commands.append("2")
self.bot.log("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1], level = 10)
self.bot.log("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1])
return self.hexStart(channel,user,commands[1]) # commands[1] is the opponent
# If using a command with no game, return error
@ -47,7 +47,7 @@ class HexGame():
try:
return self.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
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":
@ -78,7 +78,7 @@ class HexGame():
return "You can only swap as the second player after the very first move.", False, False, False, False
else:
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
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
def hexStart(self, channel, user, opponent):
@ -142,7 +142,7 @@ class HexGame():
if player == turn:
board = game["board"]
self.bot.log("Placing a piece on the board with placeHex()", level = 10)
self.bot.log("Placing a piece on the board with placeHex()")
# Places on board
board = self.placeOnHexBoard(board,player,position)
@ -153,7 +153,7 @@ class HexGame():
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"turn":turn}})
# Checking for a win
self.bot.log("Checking for win", level = 10)
self.bot.log("Checking for win")
winner = self.evaluateBoard(game["board"])[1]
if winner == 0: # Continue with the game.
@ -174,7 +174,7 @@ class HexGame():
# Is it now Gwendolyn's turn?
gwendoTurn = False
if game["players"][turn-1] == "Gwendolyn":
self.bot.log("It's Gwendolyn's turn", level = 10)
self.bot.log("It's Gwendolyn's turn")
gwendoTurn = True
# Update the board
@ -226,7 +226,7 @@ class HexGame():
turn = game["turn"]
# You can only undo after your turn, which is the opponent's turn.
if user == game["players"][(turn % 2)]: # If it's not your turn
self.bot.log("Undoing {}'s last move".format(self.bot.databaseFuncs.getName(user)), level = 10)
self.bot.log("Undoing {}'s last move".format(self.bot.databaseFuncs.getName(user)))
lastMove = game["gameHistory"].pop()
game["board"][lastMove[0]][lastMove[1]] = 0
@ -251,7 +251,7 @@ class HexGame():
# Plays as the AI
def hexAI(self, channel):
self.bot.log("Figuring out best move", level = 10)
self.bot.log("Figuring out best move")
game = self.bot.database["hex games"].find_one({"_id":channel})
board = game["board"]
@ -293,7 +293,7 @@ class HexGame():
chosenMove = (i // BOARDWIDTH , i % BOARDWIDTH)
"""
placement = "abcdefghijk"[chosenMove[1]]+str(chosenMove[0]+1)
self.bot.log("ChosenMove is {} at {}".format(chosenMove,placement), level = 10)
self.bot.log("ChosenMove is {} at {}".format(chosenMove,placement))
return self.placeHex(channel,placement, "Gwendolyn")
@ -327,7 +327,7 @@ class HexGame():
scores[player] = Distance[u] # A player's score is the shortest distance to goal. Which equals the number of remaining moves they need to win if unblocked by the opponent.
break
else:
self.bot.log("For some reason, no path to the goal was found. ", level = 10)
self.bot.log("For some reason, no path to the goal was found. ")
if scores[player] == 0:
winner = player
break # We don't need to check the other player's score, if player1 won.