🎆 Hex now playable!

This commit is contained in:
jona605a
2020-08-07 02:12:14 +02:00
parent 251a32ae76
commit d02e9dcde7
4 changed files with 51 additions and 98 deletions

View File

@ -110,10 +110,9 @@ def placeHex(channel : str,player : int,position : str):
if channel in data:
board = data[channel]["board"]
logThis("Placing a piece on the board with placeHex()")
# Places on board
board = placeOnHexBoard(board,player,position)
# Updates the drawing
hexDraw.drawHexPlacement(channel,player,position)
if isinstance(board, list):
# If the move is valid:
@ -141,7 +140,7 @@ def placeHex(channel : str,player : int,position : str):
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
else:"""
gameWon = False
message = data[channel]["players"][player-1]+" placed at "+position+". It's now "+data[channel]["players"][turn]+"'s turn."
message = getName(data[channel]["players"][player-1])+" placed at "+position+". It's now "+getName(data[channel]["players"][turn])+"'s turn."
with open("resources/games/hexGames.json", "w") as f:
json.dump(data,f,indent=4)
@ -229,37 +228,6 @@ def AICalcHexPoints(board,player):
score = 0
otherPlayer = player%2+1
# Adds points for middle placement
for row in range(len(board)):
if board[row][3] == player:
score += AIScoresHex["middle"]
# Checks horizontal
for row in range(boardWidth):
rowArray = [int(i) for i in list(board[row])]
for place in range(boardWidth-3):
window = rowArray[place:place+4]
score += evaluateWindow(window,player,otherPlayer)
# Checks Vertical
for column in range(boardWidth):
columnArray = [int(i[column]) for i in list(board)]
for place in range(boardWidth-3):
window = columnArray[place:place+4]
score += evaluateWindow(window,player,otherPlayer)
# Checks right diagonal
for row in range(boardWidth-3):
for place in range(boardWidth-3):
window = [board[row][place],board[row+1][place+1],board[row+2][place+2],board[row+3][place+3]]
score += evaluateWindow(window,player,otherPlayer)
# Checks left diagonal
for row in range(boardWidth-3):
for place in range(3,boardWidth):
window = [board[row][place],board[row+1][place-1],board[row+2][place-2],board[row+3][place-3]]
score += evaluateWindow(window,player,otherPlayer)
## Checks if anyone has won
#won = isHexWon(board)[0]