-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtic_tac_toe.py
35 lines (25 loc) · 876 Bytes
/
tic_tac_toe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from typing import Tuple, TypeVar
T = TypeVar("T", int, int)
def get_cell_position(cell_str: str) -> Tuple[T, T]:
# Convert the letter part of the cell string to a column index
column_index = ord(cell_str[0]) - ord("A")
# Convert the digit part of the cell string to a row index
row_index = int(cell_str[1]) - 1
# Return the row and column indices as a tuple
return row_index, column_index
def tic_tac_toe() -> Tuple[T, T]:
board = [
(" ", " ", "O"),
("X", " ", " "),
(" ", " ", "X"),
]
cell_str = "C1"
row, col = get_cell_position(cell_str)
if board[row][col] == "X":
print("There is an X in cell", cell_str)
elif board[row][col] == "O":
print("There is an O in cell", cell_str)
else:
print("There is no X or O in cell", cell_str)
return row, col
tic_tac_toe()