@@ -135,53 +135,55 @@ def isBoardFull(board):
135
135
return False
136
136
return True
137
137
138
-
139
- print ('Welcome to Tic Tac Toe!' )
140
-
141
- while True :
142
- # Reset the board
143
- theBoard = [' ' ] * 10
144
- playerLetter , computerLetter = inputPlayerLetter ()
145
- turn = whoGoesFirst ()
146
- print ('The ' + turn + ' will go first.' )
147
- gameIsPlaying = True
148
-
149
- while gameIsPlaying :
150
- if turn == 'player' :
151
- # Player's turn.
152
- drawBoard (theBoard )
153
- move = getPlayerMove (theBoard )
154
- makeMove (theBoard , playerLetter , move )
155
-
156
- if isWinner (theBoard , playerLetter ):
138
+ def main ():
139
+ print ('Welcome to Tic Tac Toe!' )
140
+
141
+ while True :
142
+ # Reset the board
143
+ theBoard = [' ' ] * 10
144
+ playerLetter , computerLetter = inputPlayerLetter ()
145
+ turn = whoGoesFirst ()
146
+ print ('The ' + turn + ' will go first.' )
147
+ gameIsPlaying = True
148
+
149
+ while gameIsPlaying :
150
+ if turn == 'player' :
151
+ # Player's turn.
157
152
drawBoard (theBoard )
158
- print ( 'Hooray! You have won the game!' )
159
- gameIsPlaying = False
160
- else :
161
- if isBoardFull (theBoard ):
153
+ move = getPlayerMove ( theBoard )
154
+ makeMove ( theBoard , playerLetter , move )
155
+
156
+ if isWinner (theBoard , playerLetter ):
162
157
drawBoard (theBoard )
163
- print ('The game is a tie !' )
164
- break
158
+ print ('Hooray! You have won the game !' )
159
+ gameIsPlaying = False
165
160
else :
166
- turn = 'computer'
167
-
168
- else :
169
- # Computer's turn.
170
- move = getComputerMove (theBoard , computerLetter )
171
- makeMove (theBoard , computerLetter , move )
172
-
173
- if isWinner (theBoard , computerLetter ):
174
- drawBoard (theBoard )
175
- print ('The computer has beaten you! You lose.' )
176
- gameIsPlaying = False
161
+ if isBoardFull (theBoard ):
162
+ drawBoard (theBoard )
163
+ print ('The game is a tie!' )
164
+ break
165
+ else :
166
+ turn = 'computer'
167
+
177
168
else :
178
- if isBoardFull (theBoard ):
169
+ # Computer's turn.
170
+ move = getComputerMove (theBoard , computerLetter )
171
+ makeMove (theBoard , computerLetter , move )
172
+
173
+ if isWinner (theBoard , computerLetter ):
179
174
drawBoard (theBoard )
180
- print ('The game is a tie! ' )
181
- break
175
+ print ('The computer has beaten you! You lose. ' )
176
+ gameIsPlaying = False
182
177
else :
183
- turn = 'player'
184
-
185
- if not playAgain ():
186
- break
187
-
178
+ if isBoardFull (theBoard ):
179
+ drawBoard (theBoard )
180
+ print ('The game is a tie!' )
181
+ break
182
+ else :
183
+ turn = 'player'
184
+
185
+ if not playAgain ():
186
+ break
187
+
188
+ if __name__ == "__main__" :
189
+ main ()
0 commit comments