Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def display_board(board):
- for i in range(7, 0, -3):
- for n in range(0, 3):
- print(board[i+n], end=' ')
- print()
- def player_input():
- n=''
- while n!='X' and n!='O':
- n=input('X or O: ')
- return n
- def place_marker(board, marker, position):
- board[position]=marker
- return board
- def win_check(board, a):
- check=False
- for i in range(7, 0, -3):
- if board[i]==board[i+1]==board[i+2]==a:
- check=True
- for i in range(1, 4):
- if board[i]==board[i+3]==board[i+6]==a:
- check=True
- if board[1]==board[5]==board[9]==a or board[3]==board[5]==board[7]==a:
- check=True
- return check
- def space_check(board, position):
- if board[position]!='.':
- return False
- else:
- return True
- def full_board_check(board):
- for i in board:
- if i=='.':
- return False
- return True
- if __name__=="__main__":
- game_on='Y'
- while game_on=='Y':
- print('\n'*100)
- testboard2 = ['.' for x in range(0, 10)]
- display_board(testboard2)
- i=''
- while not win_check(testboard2, i):
- print('\n'*100)
- display_board(testboard2)
- i=player_input()
- loc=int(input('Enter position: '))
- while not space_check(testboard2, loc):
- print('Choose again: ')
- loc=int(input('Enter position: '))
- place_marker(testboard2, i, loc)
- win_check(testboard2, i)
- if full_board_check(testboard2):
- print('Het bang')
- break
- print('\n'*100)
- display_board(testboard2)
- print('The player {} won the game'.format(i))
- game_on=input('Play again? Y/N: ')
- print("Thank you for playing this game. I've worked my butt off on this")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement