✨ 🎨 Two types of drawing
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import random
|
||||
|
||||
from . import fourInARowDraw
|
||||
from funcs import logThis
|
||||
@ -8,9 +9,12 @@ def fourInARowStart(channel, user, opponent):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user.lower() != opponent.lower()+"schcd":
|
||||
if user.lower() != opponent.lower():
|
||||
if channel not in data["4 in a row games"]:
|
||||
|
||||
if opponent.lower() == "gwendolyn":
|
||||
opponent = "Gwendolyn"
|
||||
|
||||
board = [ [ 0 for i in range(7) ] for j in range(6) ]
|
||||
|
||||
data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"",
|
||||
@ -60,6 +64,9 @@ def placePiece(channel : str,player : int,column : int):
|
||||
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."
|
||||
elif 0 not in board[0]:
|
||||
gameWon = True
|
||||
message = "It's a draw!"
|
||||
else:
|
||||
gameWon = False
|
||||
message = data["4 in a row games"][channel]["players"][player-1]+" placed a piece in column "+str(column+1)+". It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn."
|
||||
@ -77,8 +84,6 @@ def placePiece(channel : str,player : int,column : int):
|
||||
|
||||
# Parses command
|
||||
def parseFourInARow(command, channel, user):
|
||||
|
||||
print(command)
|
||||
if command == "" or command == " ":
|
||||
return "I didn't get that. \"Use !fourinarow start [opponent]\" to start a game.", False, False, False
|
||||
|
||||
@ -121,9 +126,9 @@ def isWon(channel):
|
||||
piecePlayer = game[line][place]
|
||||
if piecePlayer != 0:
|
||||
# Checks horizontal
|
||||
try:
|
||||
if place <= 7-4:
|
||||
pieces = [game[line][place+1],game[line][place+2],game[line][place+3]]
|
||||
except:
|
||||
else:
|
||||
pieces = [0]
|
||||
|
||||
if all(x == piecePlayer for x in pieces):
|
||||
@ -132,9 +137,9 @@ def isWon(channel):
|
||||
winCoordinates = [line,place]
|
||||
|
||||
# Checks vertical
|
||||
try:
|
||||
if line <= 6-4:
|
||||
pieces = [game[line+1][place],game[line+2][place],game[line+3][place]]
|
||||
except:
|
||||
else:
|
||||
pieces = [0]
|
||||
|
||||
if all(x == piecePlayer for x in pieces):
|
||||
@ -143,9 +148,9 @@ def isWon(channel):
|
||||
winCoordinates = [line,place]
|
||||
|
||||
# Checks right diagonal
|
||||
try:
|
||||
if line <= 6-4 and place <= 7-4:
|
||||
pieces = [game[line+1][place+1],game[line+2][place+2],game[line+3][place+3]]
|
||||
except:
|
||||
else:
|
||||
pieces = [0]
|
||||
|
||||
if all(x == piecePlayer for x in pieces):
|
||||
@ -154,9 +159,10 @@ def isWon(channel):
|
||||
winCoordinates = [line,place]
|
||||
|
||||
# Checks left diagonal
|
||||
try:
|
||||
if line <= 6-4 and place >= 3:
|
||||
pieces = [game[line+1][place-1],game[line+2][place-2],game[line+3][place-3]]
|
||||
except:
|
||||
print(pieces)
|
||||
else:
|
||||
pieces = [0]
|
||||
|
||||
if all(x == piecePlayer for x in pieces):
|
||||
@ -168,3 +174,15 @@ def isWon(channel):
|
||||
return won, winDirection, winCoordinates
|
||||
|
||||
|
||||
def fourInARowAI(channel):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
foundPlace = False
|
||||
|
||||
while foundPlace == False:
|
||||
placement = random.randint(0,6)
|
||||
if data["4 in a row games"][channel]["board"][0][placement] == 0:
|
||||
foundPlace = True
|
||||
return placePiece(channel,2,placement)
|
||||
|
||||
|
Reference in New Issue
Block a user