Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''kółko i krzyżyk'''
- def theGame():
- #coord = {1:'l', 2:'', 3:'', 4:'', 5:'', 6:'', 7:'', 8:'', 9:''}
- coord = ['', '', '', '', '', '', '', '', '']
- done = False
- #(('0 0', '1 0', '2 0'), ('0 1' , '1 1' , '2 1'), ('0 2', '1 2', '2 2'), ('0 0', '0 1', '0 2'), ('1 0', '1 1', '1 2'), ('2 0', '2 1', '2 2'), ('0 2', '2 2', '2 0'), ('0 0', '1 1', '2 2'))
- def printGame():
- print('{:4}{:^3}{}{:^3}{}{:^3}{}'.format('',0,'|',1,'|',2,'|'))
- print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(0,' |',coord[0],'|',coord[1],'|',coord[2],'|'))
- print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(1,' |',coord[3],'|',coord[4],'|',coord[5],'|'))
- print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(2,' |',coord[6],'|',coord[7],'|',coord[8],'|'))
- def inputCoords():
- s = input()
- if s == '0 0': s = 0
- if s == '1 0': s = 1
- if s == '2 0': s = 2
- if s == '0 1': s = 3
- if s == '1 1': s = 4
- if s == '2 1': s = 5
- if s == '0 2': s = 6
- if s == '1 2': s = 7
- if s == '2 2': s = 8
- return s
- def moveX():
- print('\nX move:')
- x = inputCoords()
- if coord[x] == 'X' or coord[x] == 'O':
- print('\nAlready taken. Choose again.')
- moveX()
- else:
- coord[x] = 'X'
- def moveO():
- print('\nO move:')
- o = inputCoords()
- if coord[o] == 'X' or coord[o] == 'O':
- print('\nAlready taken. Choose again.')
- moveO()
- else:
- coord[o] = 'O'
- def gameStatus():
- count = 0
- winCoord = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))
- for i in winCoord:
- if coord[i[0]] == 'X':
- if coord[i[1]] == 'X':
- if coord[i[2]] == 'X':
- print('X Wins!\n')
- done = True
- return done
- if coord[i[0]] == 'O':
- if coord[i[1]] == 'O':
- if coord[i[2]] == 'O':
- print('O Wins!\n')
- done = True
- return done
- if coord.count('X')+coord.count('O') == 9:
- done = True
- return done
- while not done :
- printGame()
- done = gameStatus()
- if done == True:
- break
- moveX()
- printGame()
- done = gameStatus()
- if done == True:
- break
- moveO()
- theGame()
Advertisement
Add Comment
Please, Sign In to add comment