Skip to content

Commit 14dc4ce

Browse files
committed
Minor bug fixes
1 parent 04819b6 commit 14dc4ce

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

gameWindow.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
55
This is the gameWindow file. It creates the GUI for the Tic-Tac-Toe game and allows the user to play against Joe.
66
7+
8+
BUILD 7.0.2
79
'''
810

11+
from time import sleep
912
import tkinter as tk
1013
import keras
1114
import numpy as np
@@ -27,7 +30,7 @@
2730
joeWins = ["I win!", "I'm the best!", "I'm unbeatable!", "I'm the champion!", "I'm the king!"]
2831
joeLosses = ["You win this time...", "You got lucky...", "I'll get you next time...", "I'll be back!", "I am just an average Joe..."]
2932

30-
model = keras.models.load_model('6.5.6st/a0.01_g0.9_i10000.keras')
33+
model = keras.models.load_model('a0.01_g0.9_i10000.keras')
3134

3235
# Globals
3336
board = bd.Board()
@@ -103,6 +106,14 @@ def getJoeMove(board):
103106

104107
# get best action
105108
qValues = model.predict(board.vector.reshape(1,-1), verbose=0)[0]
109+
110+
# if first move, choose randomly from top 3 actions
111+
if np.count_nonzero(board.vector == joeTurn) == 0 and joeTurn == X:
112+
qValues = np.argsort(qValues)
113+
qValues = qValues[0:3] # get top 3 actions
114+
action = np.random.choice(qValues) # choose randomly from top 3
115+
116+
# otherwise, choose best action
106117
for action in np.argsort(qValues)[::-1]:
107118
if board.validMove(*divmod(action, 3)):
108119
break
@@ -137,6 +148,9 @@ def resetGame():
137148
buttons[row][col].config(text=" ")
138149

139150
currentPlayer = X
151+
if joeTurn == X:
152+
sleep(0.5)
153+
joeMove()
140154
updateStatusLabel()
141155

142156

@@ -184,7 +198,7 @@ def switchJoeTurn():
184198

185199
# update the switch button text
186200
def updateSwitchButton():
187-
switchButton.config(text=f"Make {determinePlayer(O)} Go First", font=("Helvetica", 16))
201+
switchButton.config(text=f"Make {determinePlayer(O)} Go First")
188202

189203

190204
# update the status label

0 commit comments

Comments
 (0)