✨ Four in a row "AI"
This commit is contained in:
@ -12,7 +12,7 @@ def fourInARowStart(channel, user, opponent):
|
||||
if user.lower() != opponent.lower():
|
||||
if channel not in data["4 in a row games"]:
|
||||
|
||||
if opponent.lower() == "gwendolyn":
|
||||
if opponent.lower() in ["gwendolyn",""," "]:
|
||||
opponent = "Gwendolyn"
|
||||
|
||||
board = [ [ 0 for i in range(7) ] for j in range(6) ]
|
||||
@ -25,11 +25,11 @@ def fourInARowStart(channel, user, opponent):
|
||||
|
||||
fourInARowDraw.drawImage(channel)
|
||||
|
||||
return "Started game. It's "+user+"'s turn", True, False, False
|
||||
return "Started game against "+opponent+". It's "+user+"'s turn", True, False, False, False
|
||||
else:
|
||||
return "There's already a 4 in a row game going on in this channel", False, False, False
|
||||
return "There's already a 4 in a row game going on in this channel", False, False, False, False
|
||||
else:
|
||||
return "You can't play against yourself", False, False, False
|
||||
return "You can't play against yourself", False, False, False, False
|
||||
|
||||
# Places a piece at the lowest available point in a specific column
|
||||
def placePiece(channel : str,player : int,column : int):
|
||||
@ -63,7 +63,9 @@ def placePiece(channel : str,player : int,column : int):
|
||||
data["4 in a row games"][channel]["win direction"] = winDirection
|
||||
data["4 in a row games"][channel]["win coordinates"] = winCoordinates
|
||||
|
||||
message = data["4 in a row games"][channel]["players"][won-1]+" won. Adding 20 GwendoBucks to their account."
|
||||
message = data["4 in a row games"][channel]["players"][won-1]+" won."
|
||||
if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn":
|
||||
message += " Adding 20 GwendoBucks to their account."
|
||||
elif 0 not in board[0]:
|
||||
gameWon = True
|
||||
message = "It's a draw!"
|
||||
@ -73,23 +75,29 @@ def placePiece(channel : str,player : int,column : int):
|
||||
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
gwendoTurn = False
|
||||
|
||||
if data["4 in a row games"][channel]["players"][turn] == "Gwendolyn":
|
||||
logThis("It's Gwendolyn's turn")
|
||||
gwendoTurn = True
|
||||
|
||||
fourInARowDraw.drawImage(channel)
|
||||
return message, True, True, gameWon
|
||||
return message, True, True, gameWon, gwendoTurn
|
||||
else:
|
||||
return "There isn't any room in that column", True, True, False
|
||||
return "There isn't any room in that column", True, True, False, False
|
||||
else:
|
||||
return "There's no game in this channel", False, False, False
|
||||
return "There's no game in this channel", False, False, False, False
|
||||
|
||||
|
||||
# Parses command
|
||||
def parseFourInARow(command, channel, user):
|
||||
if command == "" or command == " ":
|
||||
return "I didn't get that. \"Use !fourinarow start [opponent]\" to start a game.", False, False, False
|
||||
return "I didn't get that. \"Use !fourinarow start [opponent]\" to start a game.", False, False, False, False
|
||||
|
||||
|
||||
elif command.startswith(" start "):
|
||||
command = command.replace(" start ","")
|
||||
elif command.startswith(" start ") or command == (" start"):
|
||||
command = command.replace(" start ","").replace(" start","")
|
||||
return fourInARowStart(channel,user,command)
|
||||
|
||||
elif command.startswith(" stop"):
|
||||
@ -97,9 +105,9 @@ def parseFourInARow(command, channel, user):
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["4 in a row games"][channel]["players"]:
|
||||
return "Ending game.", False, False, True
|
||||
return "Ending game.", False, False, True, False
|
||||
else:
|
||||
return "You can't end a game where you're not a player.", False, False, False
|
||||
return "You can't end a game where you're not a player.", False, False, False, False
|
||||
elif command.startswith(" place"):
|
||||
commands = command.split(" ")
|
||||
#try:
|
||||
@ -107,7 +115,7 @@ def parseFourInARow(command, channel, user):
|
||||
#except:
|
||||
# return "I didn't quite get that", False, False, False
|
||||
else:
|
||||
return "I didn't get that", False, False, False
|
||||
return "I didn't get that", False, False, False, False
|
||||
|
||||
def isWon(channel):
|
||||
logThis("Checking for win",channel)
|
||||
@ -161,7 +169,6 @@ def isWon(channel):
|
||||
# Checks left diagonal
|
||||
if line <= 6-4 and place >= 3:
|
||||
pieces = [game[line+1][place-1],game[line+2][place-2],game[line+3][place-3]]
|
||||
print(pieces)
|
||||
else:
|
||||
pieces = [0]
|
||||
|
||||
|
Reference in New Issue
Block a user