✨ Fully converted to slash commands
This commit is contained in:
@ -3,7 +3,6 @@ import copy
|
||||
import math
|
||||
|
||||
from .connectFourDraw import drawConnectFour
|
||||
from funcs import logThis
|
||||
|
||||
AIScores = {
|
||||
"middle": 3,
|
||||
@ -45,7 +44,7 @@ class connectFour():
|
||||
return "That difficulty doesn't exist", False, False, False, False
|
||||
except:
|
||||
# Opponent is another player
|
||||
opponent = self.bot.funcs.getID(opponent)
|
||||
opponent = self.bot.databaseFuncs.getID(opponent)
|
||||
if opponent != None:
|
||||
difficulty = 5
|
||||
diffText = ""
|
||||
@ -71,7 +70,7 @@ class connectFour():
|
||||
if players[0] == "Gwendolyn":
|
||||
gwendoTurn = True
|
||||
|
||||
return "Started game against "+self.bot.funcs.getName(opponent)+diffText+". It's "+self.bot.funcs.getName(players[0])+"'s turn", True, False, False, gwendoTurn
|
||||
return "Started game against "+self.bot.databaseFuncs.getName(opponent)+diffText+". It's "+self.bot.databaseFuncs.getName(players[0])+"'s turn", True, False, False, gwendoTurn
|
||||
else:
|
||||
return "There's already a connect 4 game going on in this channel", False, False, False, False
|
||||
|
||||
@ -89,7 +88,7 @@ class connectFour():
|
||||
turn = (game["turn"]+1)%2
|
||||
self.bot.database["connect 4 games"].update_one({"_id":channel},{"$set":{"turn":turn}})
|
||||
|
||||
logThis("Checking for win")
|
||||
self.bot.log("Checking for win", level = 10)
|
||||
won, winDirection, winCoordinates = self.isWon(board)
|
||||
|
||||
if won != 0:
|
||||
@ -99,7 +98,7 @@ class connectFour():
|
||||
self.bot.database["connect 4 games"].update_one({"_id":channel},
|
||||
{"$set":{"win coordinates":winCoordinates}})
|
||||
|
||||
message = self.bot.funcs.getName(game["players"][won-1])+" placed a piece in column "+str(column+1)+" and won."
|
||||
message = self.bot.databaseFuncs.getName(game["players"][won-1])+" placed a piece in column "+str(column+1)+" and won."
|
||||
winAmount = int(game["difficulty"])**2+5
|
||||
if game["players"][won-1] != "Gwendolyn":
|
||||
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
|
||||
@ -108,12 +107,12 @@ class connectFour():
|
||||
message = "It's a draw!"
|
||||
else:
|
||||
gameWon = False
|
||||
message = self.bot.funcs.getName(game["players"][player-1])+" placed a piece in column "+str(column+1)+". It's now "+self.bot.funcs.getName(game["players"][turn])+"'s turn."
|
||||
message = self.bot.databaseFuncs.getName(game["players"][player-1])+" placed a piece in column "+str(column+1)+". It's now "+self.bot.databaseFuncs.getName(game["players"][turn])+"'s turn."
|
||||
|
||||
gwendoTurn = False
|
||||
|
||||
if game["players"][turn] == "Gwendolyn":
|
||||
logThis("It's Gwendolyn's turn")
|
||||
self.bot.log("It's Gwendolyn's turn", level = 10)
|
||||
gwendoTurn = True
|
||||
|
||||
self.draw.drawImage(channel)
|
||||
@ -166,7 +165,7 @@ class connectFour():
|
||||
if user == game["players"][turn]:
|
||||
piece = turn + 1
|
||||
else:
|
||||
logThis("It wasn't their turn")
|
||||
self.bot.log("It wasn't their turn", level = 10)
|
||||
return "It's not your turn!", False, False, False, False
|
||||
column = int(commands[1])-1
|
||||
else:
|
||||
@ -236,7 +235,7 @@ class connectFour():
|
||||
|
||||
# Plays as the AI
|
||||
async def connectFourAI(self, channel):
|
||||
logThis("Figuring out best move")
|
||||
self.bot.log("Figuring out best move", level = 10)
|
||||
game = self.bot.database["connect 4 games"].find_one({"_id":channel})
|
||||
|
||||
board = game["board"]
|
||||
@ -249,7 +248,7 @@ class connectFour():
|
||||
testBoard = self.placeOnBoard(testBoard,player,column)
|
||||
if testBoard != None:
|
||||
scores[column] = await self.minimax(testBoard,difficulty,player%2+1,player,-math.inf,math.inf,False)
|
||||
logThis("Best score for column "+str(column)+" is "+str(scores[column]))
|
||||
self.bot.log("Best score for column "+str(column)+" is "+str(scores[column]), level = 10)
|
||||
|
||||
possibleScores = scores.copy()
|
||||
|
||||
|
Reference in New Issue
Block a user