Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TicTacToeBoard:
- def new_game(self):
- self.field = [['-', '-', '-'], ['-', '-', '-'], ['-', '-', '-']]
- self.k = 0
- self.b = ''
- self.n = False
- def get_field(self):
- return self.field
- def __init__(self):
- self.field = [['-', '-', '-'], ['-', '-', '-'], ['-', '-', '-']]
- self.k = 0
- self.b = ''
- self.n = False
- def make_move(self, row, col):
- if self.field[row - 1][col - 1] != ('X' or '0'):
- if self.k % 2 == 0:
- self.field[row - 1][col - 1] = 'X'
- else:
- self.field[row - 1][col - 1] = '0'
- self.k += 1
- if self.b == '':
- if self.check_field() == 'X':
- self.n = True
- return self.b
- elif self.check_field() == '0':
- self.n = True
- return self.b
- else:
- return 'Продолжаем играть'
- if self.n:
- return 'Игра уже завершена'
- else:
- return 'Клетка' + ' ' + str(row) + ',' + ' ' + str(col) + ' ' + 'уже занята'
- def check_field(self):
- for i in self.field:
- if self.field[0][0] == self.field[0][1] == self.field[0][2] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[1][0] == self.field[1][1] == self.field[1][2] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[2][0] == self.field[2][1] == self.field[2][2] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][0] == self.field[1][1] == self.field[2][2] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][2] == self.field[1][1] == self.field[2][0] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][0] == self.field[1][0] == self.field[2][0] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][1] == self.field[1][1] == self.field[2][1] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][2] == self.field[1][2] == self.field[2][2] == 'X':
- self.b = 'Победил игрок X'
- return 'X'
- if self.field[0][0] == self.field[0][1] == self.field[0][2] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[1][0] == self.field[1][1] == self.field[1][2] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[2][0] == self.field[2][1] == self.field[2][2] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[0][0] == self.field[1][1] == self.field[2][2] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[0][2] == self.field[1][1] == self.field[2][0] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[0][0] == self.field[1][0] == self.field[2][0] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[0][1] == self.field[1][1] == self.field[2][1] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- if self.field[0][2] == self.field[1][2] == self.field[2][2] == '0':
- self.b = 'Победил игрок 0'
- return '0'
- else:
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement