Skip to content

Commit

Permalink
Merge pull request #314 from realpython/tic-tac-toe-ai-python
Browse files Browse the repository at this point in the history
Tic tac toe ai python
  • Loading branch information
bryancanlas committed Oct 10, 2022
2 parents d5b42ef + 1a23ceb commit ba354d1
Show file tree
Hide file tree
Showing 83 changed files with 17 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .cli import main

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/browser/cli.py

import http.server
import socketserver
import threading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/browser/players.py

from asyncio import Queue

from tic_tac_toe.game.players_async import AsyncPlayer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/browser/renderers.py

from js import document
from tic_tac_toe.game.renderers import Renderer
from tic_tac_toe.logic.models import GameState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/browser/script.py

from asyncio.queues import Queue

from js import document
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .cli import main

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/args.py

import argparse
from typing import NamedTuple

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/cli.py

from tic_tac_toe.game.engine import TicTacToe

from .args import parse_args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/players.py

import re

from tic_tac_toe.game.players import Player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/renderers.py

import textwrap
from typing import Iterable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# frontends/play.py

from console.players import ConsolePlayer
from console.renderers import ConsoleRenderer
from tic_tac_toe.game.engine import TicTacToe
from tic_tac_toe.game.players import RandomComputerPlayer
from tic_tac_toe.logic.models import Mark

from console.players import ConsolePlayer
from console.renderers import ConsoleRenderer

player1 = ConsolePlayer(Mark("X"))
player2 = RandomComputerPlayer(Mark("O"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .cli import main

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/window/cli.py

from queue import Queue
from threading import Thread

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/window/players.py

from queue import Queue

from tic_tac_toe.game.players import Player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/window/renderers.py

import tkinter as tk
from queue import Queue
from tkinter import ttk
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/engine.py

from dataclasses import dataclass
from typing import Callable, TypeAlias

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/engine_async.py

from dataclasses import dataclass

from tic_tac_toe.game.engine import ErrorHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/players.py

import abc
import time

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/players_async.py

import abc
import asyncio

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/renderers.py

import abc

from tic_tac_toe.logic.models import GameState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# tic_tac_toe/logic/exceptions.py


class InvalidGameState(Exception):
"""Raised when the game state is invalid."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/minimax.py

import json
from functools import cache, partial
from importlib import resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/models.py

import enum
import random
import re
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/validators.py

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .cli import main

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/args.py

import argparse
from typing import NamedTuple

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/cli.py

from tic_tac_toe.game.engine import TicTacToe

from .args import parse_args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/players.py

import re

from tic_tac_toe.game.players import Player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/renderers.py

import textwrap
from typing import Iterable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frontends/play.py

from console.players import ConsolePlayer
from console.renderers import ConsoleRenderer
from tic_tac_toe.game.engine import TicTacToe
from tic_tac_toe.game.players import RandomComputerPlayer
from tic_tac_toe.logic.models import Mark

from console.players import ConsolePlayer
from console.renderers import ConsoleRenderer

player1 = ConsolePlayer(Mark("X"))
player2 = RandomComputerPlayer(Mark("O"))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pyproject.toml

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/engine.py

from dataclasses import dataclass
from typing import Callable, TypeAlias

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/players.py

import abc
import time

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/renderers.py

import abc

from tic_tac_toe.logic.models import GameState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# tic_tac_toe/logic/exceptions.py


class InvalidGameState(Exception):
"""Raised when the game state is invalid."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/minimax.py

from functools import partial

from tic_tac_toe.logic.models import GameState, Mark, Move
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/models.py

import enum
import random
import re
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/validators.py

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pyproject.toml

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# tic_tac_toe/logic/exceptions.py


class InvalidGameState(Exception):
"""Raised when the game state is invalid."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/models.py

import enum
import re
from dataclasses import dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/validators.py

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pyproject.toml

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/engine.py

from dataclasses import dataclass
from typing import Callable, TypeAlias

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/players.py

import abc
import random
import time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/renderers.py

import abc

from tic_tac_toe.logic.models import GameState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# tic_tac_toe/logic/exceptions.py


class InvalidGameState(Exception):
"""Raised when the game state is invalid."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/models.py

import enum
import re
from dataclasses import dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/validators.py

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/__main__.py

from .cli import main

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/args.py

import argparse
from typing import NamedTuple

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/cli.py

from tic_tac_toe.game.engine import TicTacToe

from .args import parse_args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/players.py

import re

from tic_tac_toe.game.players import Player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/console/renderers.py

import textwrap
from typing import Iterable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frontends/play.py

from tic_tac_toe.game.engine import TicTacToe
from tic_tac_toe.game.players import RandomComputerPlayer
from tic_tac_toe.logic.models import Mark
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pyproject.toml

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/engine.py

from dataclasses import dataclass
from typing import Callable, TypeAlias

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/players.py

import abc
import random
import time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/game/renderers.py

import abc

from tic_tac_toe.logic.models import GameState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# tic_tac_toe/logic/exceptions.py


class InvalidGameState(Exception):
"""Raised when the game state is invalid."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tic_tac_toe/logic/models.py

import enum
import re
from dataclasses import dataclass
Expand Down
Loading

0 comments on commit ba354d1

Please sign in to comment.