Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .idea/Python_Project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added tictactoe/__pycache__/tictactoe.cpython-313.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions tictactoe/tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def player(board):
o_count = sum(row.count(O) for row in board)
return O if x_count > o_count else X


# Returns the list of empty positions on the board
def actions(board):
"""Returns a list of all possible actions (i, j) available on the board."""
return [(i, j) for i in range(3) for j in range(3) if board[i][j] is EMPTY]
Expand Down Expand Up @@ -116,10 +116,12 @@ def min_value(board):


if __name__ == "__main__":
print("Welcome to Tic-Tac-Toe! This game will play itself using AI.")
board = initial_state()
while not terminal(board):
move = minimax(board)
board = result(board, move)
print(f"Player {player(board)} made move: {move}")
for row in board:
print(row)
print(" | ".join([cell if cell else " " for cell in row]))
print()