Skip to content

Commit

Permalink
Update tic_tac_toe.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding4Hours authored Jul 9, 2024
1 parent 21cf8b0 commit 8a68452
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tic_tac_toe.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re

#a = {}

def update_board(board, move, player):
if move not in board or board[move] in ['X', 'O']:
if board[move] == 'X' or board[move] == 'O':
return False
board[move] = player
return True

def check_winner(board):
Expand All @@ -23,21 +22,21 @@ def check_winner(board):
def update_readme(board, status):
with open('README.md', 'r') as file:
content = file.read()
celll = lambda cell: '/img/blank.png' if cell is None else '/img/o.png' if cell == 'O' else '/img/x.png' if cell == 'X' else cell

ttype = lambda cell: 'X' if cell == 'X' else 'O' if cell == 'O' else 'Empty' if cell is None else cell
cell_image = lambda cell: '/img/blank.png' if cell == ' ' else '/img/o.png' if cell == 'O' else '/img/x.png'
cell_type = lambda cell: 'X' if cell == 'X' else 'O' if cell == 'O' else 'Empty' if cell == ' ' else cell

board_str = f"""| Tic | Tac | Toe |
|--|--|--|
| [![{ttype(board[0])}]({celll(board[0])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%200) |
[![{ttype(board[1])}]({celll(board[1])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%201) |
[![{ttype(board[2])}]({celll(board[2])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%202) |
| [![{ttype(board[3])}]({celll(board[3])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%203) |
[![{ttype(board[4])}]({celll(board[4])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%204) |
[![{ttype(a[5])}]({celll(board[5])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%205) |
| [![{ttype(board[6])}]({celll(board[6])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%206) |
[![{ttype(board[7])}]({celll(board[7])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%207) |
[![{ttype(board[8])}]({celll(board[8])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%208) |
| [![{cell_type(board[0])}]({cell_image(board[0])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%201) |
[![{cell_type(board[1])}]({cell_image(board[1])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%202) |
[![{cell_type(board[2])}]({cell_image(board[2])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%203) |
| [![{cell_type(board[3])}]({cell_image(board[3])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%204) |
[![{cell_type(board[4])}]({cell_image(board[4])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%205) |
[![{cell_type(board[5])}]({cell_image(board[5])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%206) |
| [![{cell_type(board[6])}]({cell_image(board[6])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%207) |
[![{cell_type(board[7])}]({cell_image(board[7])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%208) |
[![{cell_type(board[8])}]({cell_image(board[8])})](https://github.com/Coding4Hours/tic_tac_toe/issues/new?title=move%209) |
"""

new_content = re.sub(r'## Current Board\n\n.*?\n\n', f'## Current Board\n\n{board_str}\n\n', content, flags=re.DOTALL)
Expand All @@ -52,6 +51,7 @@ def main(move):

board = re.findall(r'\| (.) \| (.) \| (.) \|', content)
board = [item for sublist in board for item in sublist]
board = [' ' if cell == 'Empty' else cell for cell in board]

current_player = 'X' if content.endswith("It's X's turn to play.") else 'O'

Expand Down

0 comments on commit 8a68452

Please sign in to comment.