Skip to content

Commit c2fec53

Browse files
committed
Writing winning combinations for X and O players
1 parent 9724a37 commit c2fec53

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Games/Tic tac toe OOP/tic_tac_toe_oop

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class Board():
1717
if self.cells[cell_number] == ' ':
1818
self.cells[cell_number] = player
1919

20+
def is_winner(self, player):
21+
if self.cells[1] == player and self.cells[2] == player and self.cells[3] == player:
22+
return True
23+
24+
# Reset the board
25+
def reset_board(self):
26+
self.cells = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
2027

2128

2229
board = Board()
@@ -47,6 +54,16 @@ while True:
4754
# Refresh the screen
4855
refresh_screen()
4956

57+
# Check for winner (combinations)
58+
if board.is_winner('X'):
59+
print('\nX winS!')
60+
play_again = str(input('Do you want to play again ? (Y,N)')).upper()
61+
if play_again == 'Y':
62+
board.reset_board()
63+
continue
64+
else:
65+
break
66+
5067
# creating O player
5168
o_choise = int(input('\nO player) Choose the number from 1 - 9: '))
5269
# Update the information - Created a fucntion update_cell

Games/tic_tac_toe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def computer_move(board, player):
8383
print_board()
8484

8585
# Player X input
86-
choice = i----------
86+
choice = int(input('Write a number form 1 to 9 for X: '))
8787
# Checking if the space is empty or not
8888
if board[choice] == '_':
8989
board[choice] = 'X'

0 commit comments

Comments
 (0)