Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b_tictactoe_replace.py
- from time import sleep as x
- import os
- cls=lambda: os.system('cls')
- r=range
- def m(s=''):
- cls()
- t=t2
- if '!' in s:
- t=''
- mv="Player %s's Turn..."%p
- print(b[0]+t.replace('@',mv)+s)
- if not t:
- raw_input('\n\n\tPress Enter To Continue\n')
- play = ''
- while play.lower() != 'q':
- p='X'
- b = {}
- t2='''
- To Restart: 'Spacebar'
- To Quit: 'Q'
- @
- '''
- b[0]='''
- 1 | 2 | 3 | |
- ---+---+--- ---+---+---
- 4 | 5 | 6 | |
- ---+---+--- ---+---+---
- 7 | 8 | 9 | |
- '''
- b[1]='123 456 789 147 258 369 159 357' ### for win checking
- while 1:
- m()
- play=raw_input('\tTo Play A Square Enter Available Number Here: ')
- if any([z in play.lower() for z in 'q ']):
- print('\n\n\t*** Game Cancelled...\n')
- x(3)
- break
- elif play and play in b[1]:
- t=list(b[0])
- t[b[0].index(play)+15]=p
- b[0]=''.join(t)
- ### a minimalistic approach is using the replace method
- for z in (0,1):
- b[z]=b[z].replace(play,['.',p][z])
- if p*3 in b[1]:
- m('\n\tPlayer "'+p+'" Won !!!')
- break
- elif b[0].count('.') == 9:
- m("\n\n\tNo More Moves... Player 'O' Wins By Half Point !!!")
- break
- else:
- p=('X' if p == 'O' else 'O')
- m()
- ### <<<
- else:
- m('\n\t*** Invalid Entry ***')
- x(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement