Web Tic-Tac-Toe
For CS506 final presentation.
Wenzhi Xu
Outline
1. Outcomes
2. Technology I used
3. OOD
4. Algorithm Analysis
5. Drawbacks
6. Q&A
7. Reference
Outcomes

- 5*5 Tac Tic Toe
- Support AI (low intelligence)
- Support reset play board
- Web UI can be played online
- Support multiple users to play at the same time
Code Structure

http://book.xuwenzhi.com
Try It!
Please don't care the subdomain name.
Technolegy I used
1. Python with OOP
2. Javascript(ES6), HTML and CSS
3. Appier Framework
4. Minimax algorithm for AI
5. Nginx Server with reverse proxy
6. Design Pattern with Combination Mode
7. Using simple unit testing to verify some cases

OOD

- Tictactoe class is the core engine
- Index class depend on Tictactoe class
How to support multiple users?

Minimax Algorithm
"""
core AI minimax algorithm for 5 * 5 chess board
"""
def minimax(self, play_board, depth, player):
if player == 'X':
best = [-1, -1, -infinity]
else:
best = [-1, -1, +infinity]
if depth == 0 or self.check(play_board) != "":
score = self.evaluate(play_board)
return [-1, -1, score]
empty_cells = self.empty_cells(play_board)
for cell in empty_cells:
x, y = cell[0], cell[1]
play_board[x * self.diameter + y] = player
# using DFS to track all steps
score = self.minimax(play_board, depth - 1, 'X' if player == 'O' else 'O')
play_board[x * self.diameter + y] = ""
score[0], score[1] = x, y
if player == 'X':
if score[2] > best[2]:
best = score # max value
else:
if score[2] < best[2]:
best = score # min value
return bestMinimax Algorithm
- Using DFS to traverse all steps
- Try all possible results of player and AI
- Calculate the scores of these results
- Determine AI's next step
play_board[x * self.diameter + y] = player
score = self.minimax(play_board, depth - 1, 'X' if player == 'O' else 'O')
play_board[x * self.diameter + y] = ""Shortage
1. Some magic numbers.
2. Minimax algorithm execution time is too long.
3. Board attribute in Tictactoe should be private.


Q&A
References
https://towardsdatascience.com/tic-tac-toe-creating-unbeatable-ai-with-minimax-algorithm-8af9e52c1e7d
Thanks!
Tictactoe
By xuwenzhi
Tictactoe
- 175