Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- def print_field():
- for line in field:
- print(' '.join(line))
- def move_player():
- return map(int, input().split())
- def move_comp():
- return random.randint(0, 2), random.randint(0, 2)
- #def move_comp_smart(n):
- #if n == 1:
- #return 1, 1
- #elif n == 2
- def move_X(n):
- print('>> X turn <<')
- x, y = move_comp()
- while field[x][y] != '.':
- print('>> Error turn. Try again <<')
- x, y = move_comp()
- field[x][y] = 'X'
- print_field()
- if this_is_win():
- print('>>> "X" VICTORY! <<<')
- sys.exit()
- def move_O(n):
- print('>> O turn <<')
- x, y = move_player()
- while field[x][y] != '.':
- print('>> Error turn. Try again <<')
- x, y = move_player()
- field[x][y] = 'O'
- print_field()
- if this_is_win():
- print('>>> "O" VICTORY! <<<')
- sys.exit()
- def this_is_win():
- return (field[0][0] == field[0][1] == field[0][2] != '.' or
- field[1][0] == field[1][1] == field[1][2] != '.' or
- field[2][0] == field[2][1] == field[2][2] != '.' or
- field[0][0] == field[1][0] == field[2][0] != '.' or
- field[0][1] == field[1][1] == field[2][1] != '.' or
- field[0][2] == field[1][2] == field[2][2] != '.' or
- field[0][0] == field[1][1] == field[2][2] != '.' or
- field[0][2] == field[1][1] == field[2][0] != '.')
- field = [['.'] * 3 for i in range (3)]
- print_field()
- move_X(1)
- move_O(1)
- move_X(2)
- move_O(2)
- move_X(3)
- move_O(3)
- move_X(4)
- move_O(4)
- move_X(5)
- print(">> It's a draw :c <<")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement