📝 Place on Hex board
should work
This commit is contained in:
@ -568,7 +568,10 @@ async def parseCommands(message,content):
|
||||
await runhex(message.channel,command,"#"+str(message.author.id))
|
||||
except:
|
||||
logThis("Something went wrong (error code 1500)")
|
||||
|
||||
|
||||
elif content.startswith("whatsmyid"):
|
||||
logThis("Author's ID is "+str(message.author.id))
|
||||
|
||||
# Not a command
|
||||
else:
|
||||
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:
|
||||
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)):
|
||||
if board[x][column] == 0:
|
||||
placementx = x
|
||||
|
||||
board[placementx][placementy] = player
|
||||
|
||||
if placementx == -1:
|
||||
return None
|
||||
else:
|
||||
# Returns a board where the placement has occured
|
||||
def placeOnHexBoard(board,player,position):
|
||||
# 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\"."
|
||||
|
||||
# Place at the position
|
||||
if board[row][column] == 0:
|
||||
board[row][column] = player
|
||||
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
|
||||
def isHexWon(board):
|
||||
|
@ -110,4 +110,5 @@
|
||||
1510 - Unspecified parsing error
|
||||
1520 - Unspecified AI error
|
||||
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