📝 More drawing

This commit is contained in:
jona605a
2020-08-06 17:46:51 +02:00
parent cb31f3226c
commit 899445d8b2
3 changed files with 40 additions and 55 deletions

View File

@ -118,7 +118,7 @@ def placeHex(channel : str,player : int,position : str):
board = placeOnHexBoard(board,player,position)
if board != None:
if isinstance(board, list):
# If the move is valid:
data[channel]["board"] = board
turn = (data[channel]["turn"]+1)%2
@ -160,8 +160,9 @@ def placeHex(channel : str,player : int,position : str):
# hexDraw() # something something
return message, True, True, gameWon, gwendoTurn
else:
# Invalid move
return "That move is invalid. Place only on empty spaces.", True, True, False, False
# Invalid move, and "board" is the error message
message = board
return message, True, True, False, False
else:
return "There's no game in this channel", False, False, False, False
@ -172,7 +173,7 @@ def placeOnHexBoard(board,player,position):
position = position.lower()
try:
column = ord(position[0])-97 # ord() translates from letter to number
row = int(position[1])
row = int(position[1])-1
if column not in range(boardWidth) or row not in range(boardWidth):
logThis("Position out of bounds (error code 1533)")
return "Error. That position is out of bounds."
@ -191,58 +192,9 @@ def placeOnHexBoard(board,player,position):
# Checks if someone has won the game and returns the winner
def isHexWon(board):
won = 0
winDirection = ""
winCoordinates = [0,0]
for row in range(len(board)):
for place in range(len(board[row])):
if won == 0:
piecePlayer = board[row][place]
if piecePlayer != 0:
# Checks horizontal
if place <= boardWidth-4:
pieces = [board[row][place+1],board[row][place+2],board[row][place+3]]
else:
pieces = [0]
if all(x == piecePlayer for x in pieces):
won = piecePlayer
winDirection = "h"
winCoordinates = [row,place]
# Checks vertical
if row <= boardWidth-4:
pieces = [board[row+1][place],board[row+2][place],board[row+3][place]]
else:
pieces = [0]
if all(x == piecePlayer for x in pieces):
won = piecePlayer
winDirection = "v"
winCoordinates = [row,place]
# Checks right diagonal
if row <= boardWidth-4 and place <= boardWidth-4:
pieces = [board[row+1][place+1],board[row+2][place+2],board[row+3][place+3]]
else:
pieces = [0]
if all(x == piecePlayer for x in pieces):
won = piecePlayer
winDirection = "r"
winCoordinates = [row,place]
# Checks left diagonal
if row <= boardWidth-4 and place >= 3:
pieces = [board[row+1][place-1],board[row+2][place-2],board[row+3][place-3]]
else:
pieces = [0]
if all(x == piecePlayer for x in pieces):
won = piecePlayer
winDirection = "l"
winCoordinates = [row,place]
winningPieces = []
# you know... code here
return won, winningPieces