📝 Place on Hex board
should work
This commit is contained in:
@ -569,6 +569,9 @@ async def parseCommands(message,content):
|
|||||||
except:
|
except:
|
||||||
logThis("Something went wrong (error code 1500)")
|
logThis("Something went wrong (error code 1500)")
|
||||||
|
|
||||||
|
elif content.startswith("whatsmyid"):
|
||||||
|
logThis("Author's ID is "+str(message.author.id))
|
||||||
|
|
||||||
# Not a command
|
# Not a command
|
||||||
else:
|
else:
|
||||||
logThis("That's not a command (error code 001)",str(message.channel))
|
logThis("That's not a command (error code 001)",str(message.channel))
|
||||||
|
@ -161,20 +161,28 @@ def placeHex(channel : str,player : int,position : str):
|
|||||||
else:
|
else:
|
||||||
return "There's no game in this channel", False, False, False, False
|
return "There's no game in this channel", False, False, False, False
|
||||||
|
|
||||||
# Returns a board where a piece has been placed in the column
|
|
||||||
def placeOnHexBoard(board,player,column):
|
|
||||||
placementx, placementy = -1, column
|
|
||||||
|
|
||||||
for x in range(len(board)):
|
# Returns a board where the placement has occured
|
||||||
if board[x][column] == 0:
|
def placeOnHexBoard(board,player,position):
|
||||||
placementx = x
|
# Translates the position
|
||||||
|
position = position.lower()
|
||||||
|
try:
|
||||||
|
column = ord(position[0])-97 # ord() translates from letter to number
|
||||||
|
row = int(position[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."
|
||||||
|
except:
|
||||||
|
logThis("Invalid position (error code 1531)")
|
||||||
|
return "Error. The position should be a letter followed by a number, e.g. \"e2\"."
|
||||||
|
|
||||||
board[placementx][placementy] = player
|
# Place at the position
|
||||||
|
if board[row][column] == 0:
|
||||||
if placementx == -1:
|
board[row][column] = player
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return board
|
return board
|
||||||
|
else:
|
||||||
|
logThis("Cannot place on existing piece (error code 1532)")
|
||||||
|
return "Error. You must place on an empty space."
|
||||||
|
|
||||||
# Checks if someone has won the game and returns the winner
|
# Checks if someone has won the game and returns the winner
|
||||||
def isHexWon(board):
|
def isHexWon(board):
|
||||||
|
@ -111,3 +111,4 @@
|
|||||||
1520 - Unspecified AI error
|
1520 - Unspecified AI error
|
||||||
1531 - Invalid position
|
1531 - Invalid position
|
||||||
1532 - Cannot place on existing piece
|
1532 - Cannot place on existing piece
|
||||||
|
1533 - Position out of bounds
|
||||||
|
Reference in New Issue
Block a user