Advertisement
deawrias

tictactoe

Jan 18th, 2018
9,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.06 KB | None | 0 0
  1. #tictactoe
  2. #by crazyjunkie
  3.  
  4. import random
  5.  
  6. class BadInputError(Exception):
  7.     pass
  8.  
  9. class LogicError(Exception):
  10.     pass
  11.  
  12. #===========GAMEBOARDS===========#
  13.  
  14. blankBoard = {
  15.     'UL' : ' ', 'UM' : ' ', 'UR' : ' ',
  16.     'CL' : ' ', 'CM' : ' ', 'CR' : ' ',
  17.     'BL' : ' ', 'BM' : ' ', 'BR' : ' ',
  18. }
  19.  
  20. debugBoard = {
  21.     'UL' : ' ', 'UM' : ' ', 'UR' : ' ',
  22.     'CL' : ' ', 'CM' : ' ', 'CR' : ' ',
  23.     'BL' : ' ', 'BM' : ' ', 'BR' : ' ',
  24. }
  25.  
  26. invertedSpaces = {
  27.     'LU' : 'UL', 'MU' : 'UM', 'RU' : 'UR',
  28.     'LC' : 'CL', 'MC' : 'CM', 'RC' : 'CR',
  29.     'LB' : 'BL', 'MB' : 'BM', 'RB' : 'BR',
  30. }
  31.  
  32. #===========DEFINITIONS===========#
  33.  
  34. '''Spaces'''
  35. spaces = ('UL','UM','UR','CL','CM','CR','BL','BM','BR')
  36.  
  37. '''Wins'''
  38. oWin = ('O','O','O')
  39. xWin = ('X','X','X')
  40.  
  41. '''Doubles'''
  42. oDoubles = [(' ','O','O'),('O',' ','O'),('O','O',' ')]
  43. xDoubles = [(' ','X','X'),('X',' ','X'),('X','X',' ')]
  44.  
  45. '''Input'''
  46. possibleInput = [key for key in blankBoard]
  47. for key in invertedSpaces:
  48.     possibleInput.append(key)
  49.    
  50. '''Space Types'''
  51. corners = ('UL','UR','BL','BR')
  52. sides = ('CL','CR', 'UM', 'BM')
  53.  
  54. '''Space Inversions'''
  55.  
  56. horizontalFlip = {
  57.     'UL' : 'UR','UR' : 'UL',
  58.     'CL' : 'CR','CR' : 'CL',
  59.     'BL' : 'BR','BR' : 'BL',
  60.     }
  61.  
  62. verticalFlip = {
  63.     'UL' : 'BL', 'UM' : 'BM', 'UR' : 'BR',
  64.     'BL' : 'UL', 'BM' : 'UM', 'BR' : 'UR',
  65.     }
  66.  
  67. #===========OBJECTS===========#
  68.  
  69. class ticBoard():
  70.  
  71.     def __init__(self, mode='blank', copyBoard=None):
  72.         if mode == 'blank':
  73.             self.board = {space:blankBoard[space] for space in blankBoard}
  74.         elif mode == 'debug':
  75.             self.board = {space:debugBoard[space] for space in debugBoard}
  76.         elif mode == 'copy' and copyBoard != None:
  77.             self.board = {space:copyBoard.board[space] for space in copyBoard.board}
  78.            
  79.     def draw(self):
  80.         '''Draw board'''
  81.         print()
  82.         print('    L   M   R ')
  83.         print('U:  {} | {} | {} '.format(self.board['UL'], self.board['UM'], self.board['UR']))
  84.         print('   -----------')
  85.         print('C:  {} | {} | {} '.format(self.board['CL'], self.board['CM'], self.board['CR']))
  86.         print('   -----------')
  87.         print('B:  {} | {} | {} '.format(self.board['BL'], self.board['BM'], self.board['BR']))
  88.         print()
  89.  
  90.     def place(self, symbol, space):
  91.         '''Places a symbol at the designated space.'''
  92.         try:
  93.             self.board[space] = symbol
  94.         except:
  95.             raise BadInputError("{} is not a valid space for {}.".format(space, symbol))
  96.  
  97.     def clear(self):
  98.         '''Clears board of all symbols.'''
  99.         self.board = {space:' ' for space in self.board}
  100.  
  101.     def fieldReport(self):
  102.         '''Returns dictionary of triads.'''
  103.         report = {}
  104.         report[('UL','UM','UR')] = (self.board['UL'],self.board['UM'],self.board['UR'])
  105.         report[('CL','CM','CR')] = (self.board['CL'],self.board['CM'],self.board['CR'])
  106.         report[('BL','BM','BR')] = (self.board['BL'],self.board['BM'],self.board['BR'])
  107.         report[('UL','CL','BL')] = (self.board['UL'],self.board['CL'],self.board['BL'])
  108.         report[('UM','CM','BM')] = (self.board['UM'],self.board['CM'],self.board['BM'])
  109.         report[('UR','CR','BR')] = (self.board['UR'],self.board['CR'],self.board['BR'])
  110.         report[('UL','CM','BR')] = (self.board['UL'],self.board['CM'],self.board['BR'])
  111.         report[('UR','CM','BL')] = (self.board['UR'],self.board['CM'],self.board['BL'])
  112.         return report
  113.  
  114.     def returnDoubles(self, report):
  115.         '''Filters out report to only include triads close to winning. ie "[X,X, ]" or '[O, ,O]"'''
  116.         doubles = {}
  117.         for triad in report:
  118.             if report[triad] in oDoubles or report[triad] in xDoubles:
  119.                 doubles[triad] = report[triad]
  120.         return doubles
  121.  
  122.     def checkWin(self):
  123.         '''Returns True if there are three symbols in a row. False if otherwise.'''
  124.         report = self.fieldReport()
  125.         for triad in report:
  126.             if report[triad] == oWin or report[triad] == xWin:
  127.                 return True
  128.         return False
  129.  
  130.     def checkEntry(self, entry, selected):
  131.         '''Returns the entry and whether or not it is valid.'''
  132.         entry = entry.upper()
  133.         if entry in invertedSpaces:
  134.             entry = invertedSpaces[entry]
  135.         if entry not in possibleInput:
  136.             return {'valid':False,'entry':entry, 'message':'\n{} is not a valid entry!'}
  137.         if entry not in selected:
  138.             return {'valid':True,'entry':entry}
  139.         else:
  140.             return {'valid':False,'entry':entry, 'message':'\n{} has already been selected!'}
  141.  
  142.     def buildString(self, string):
  143.         if len(string) != 9:
  144.             print('String is not correct length. Reformatting will occur.')
  145.         string = string[:9]
  146.         while len(string) < 9:
  147.             string += '0'
  148.         for i in range(9):
  149.             if string[i] == '0':
  150.                 self.board[spaces[i]] = ' '
  151.             elif string[i] == '1':
  152.                 self.board[spaces[i]] = 'O'
  153.             elif string[i] == '2':
  154.                 self.board[spaces[i]] = 'X'
  155.            
  156.  
  157.     def blankSpaces(self):
  158.         '''Returns list of free spaces remianing.'''
  159.         return [space for space in self.board if self.board[space] == ' ']
  160.  
  161. class player():
  162.  
  163.     def __init__(self, identity):
  164.         self.id = identity
  165.         self.score = 0
  166.         self.match = 0
  167.         self.symbol = ''
  168.  
  169.     def setName(self, name):
  170.         '''Define player's name.'''
  171.         if 0 < len(str(name)) < 20:
  172.             self.name = name.title()
  173.             return False
  174.         else:
  175.             return True
  176.  
  177.     def setSymbol(self, symbol):
  178.         if symbol.upper() in ['X','O']:
  179.             self.symbol = symbol.upper()
  180.             return False
  181.         else:
  182.             return True
  183.  
  184.     def win(self):
  185.         self.score += 1
  186.  
  187.     def matchWin(self):
  188.         self.match += 1
  189.  
  190.     def resetMatch(self):
  191.         self.match = 0
  192.  
  193.     def getSymbol(self):
  194.         return self.symbol
  195.  
  196.     def getName(self):
  197.         return self.name
  198.  
  199.     def getIdentity(self):
  200.         return self.id
  201.  
  202.     def getScore(self):
  203.         return self.score
  204.  
  205.     def getMatches(self):
  206.         return self.match
  207.  
  208. class computer(player):
  209.  
  210.     def __init__(self, difficulty='E'):
  211.         self.id = 'comp'
  212.         self.difficulty = difficulty[0]
  213.         self.setName('Computer')
  214.         self.setSymbol('X')
  215.         self.score = 0
  216.         self.match = 0
  217.         self.strategy = ''
  218.         self.tactic = ''
  219.         self.lastMove = ''
  220.         self.reiterate = False
  221.  
  222.     def mapCoordinates(self, triad):
  223.         '''Converts a entry from a triad tuple to a dictionary of
  224.           symbol : coordinate values.'''
  225.         mapped = {}
  226.         coor = 0
  227.         for coordinate in triad[0]:
  228.             mapped[coordinate] = triad[1][coor]
  229.             coor+=1
  230.         return mapped
  231.  
  232.     def analyzeMap(self, mappedCoordinates):
  233.         '''Returns empty value from a mapped coordinates dictionary.'''
  234.         for key in mappedCoordinates:
  235.             if mappedCoordinates[key] == ' ':
  236.                 return key
  237.  
  238.     def defineStrategy(self, strategy):
  239.         '''Play offensively (first turn) or defensively.'''
  240.         if strategy in ['offensive','defensive']:
  241.             self.strategy = strategy
  242.  
  243.     def decideTactic(self, board):
  244.         '''Decide tactic based on the first move or by making first move.'''
  245.         if self.strategy == 'offensive':
  246.             firstMove = random.choice(['center','corner'])
  247.             #firstMove = 'corner'
  248.             self.tactic = firstMove
  249.         elif self.strategy == 'defensive':
  250.             for space in board.board:
  251.                 if board.board[space] == 'O':
  252.                     if space in corners:
  253.                         self.tactic = 'corner'
  254.                     elif space == 'CM':
  255.                         self.tactic = 'center'
  256.                     else:
  257.                         self.tactic = 'side'
  258.  
  259.     def clearStrategy(self):
  260.         self.strategy = ''
  261.         self.tactic = ''
  262.  
  263.     def counter(self, doubles):
  264.         '''Either place winning piece or stop opponent from winning.'''
  265.         if doubles != {}:
  266.             triad = doubles.popitem()
  267.             entry = self.analyzeMap(self.mapCoordinates(triad))
  268.             debug(d,'Countering')
  269.             return {'counter':True, 'entry':entry}
  270.         return {'counter':False, 'entry':''}
  271.  
  272.     def trapSimulation(self, board, report, pool):
  273.         '''Simulate different moves to trap opponent.'''
  274.         for coordinate in pool:
  275.             simulatedBoard = ticBoard('copy',board)
  276.             simulatedBoard.place(self.getSymbol(),coordinate)
  277.             simulatedDoubles = board.returnDoubles(simulatedBoard.fieldReport())
  278.             soDoubles = {key:simulatedDoubles[key] for key in simulatedDoubles if 'O' in simulatedDoubles[key]}
  279.             sxDoubles = {key:simulatedDoubles[key] for key in simulatedDoubles if 'X' in simulatedDoubles[key]}
  280.             if len(soDoubles) == 0 and len(sxDoubles) > 1:
  281.                 debug(d,'Trapping')
  282.                 return {'trap':True, 'entry':coordinate}
  283.         return {'trap':False, 'entry':coordinate}
  284.        
  285.     def offensiveStrategy(self, board):
  286.         '''Provide offensive move based on a certain tactic.'''
  287.         if self.tactic == 'center':
  288.             if len(board.blankSpaces()) == 9:
  289.                 debug(d,'Begin Center')
  290.                 return {'offensive':True, 'entry':'CM'}
  291.             elif len(board.blankSpaces()) == 7:
  292.                 for corner in corners:
  293.                     if board.board[corner] == 'O' and board.board[verticalFlip[horizontalFlip[corner]]] == ' ':
  294.                         debug(d,'Countering Corner')
  295.                         return {'offensive':True, 'entry': verticalFlip[horizontalFlip[corner]]}
  296.                 return {'offensive':False, 'entry':''}
  297.             else:
  298.                 return {'offensive':False, 'entry':''}
  299.            
  300.         elif self.tactic == 'corner':
  301.             if len(board.blankSpaces()) == 9:
  302.                 debug(d,'Begin Corner')
  303.                 return {'offensive':True, 'entry':random.choice(corners)}
  304.             else:
  305.                 if board.board['CM'] != 'O':
  306.                     if self.lastMove != '':
  307.                         if board.board[horizontalFlip[self.lastMove]] == ' ' and board.board[self.lastMove[0] + 'M'] != 'O':
  308.                             debug(d,'Horizontal Flip')
  309.                             return {'offensive':True, 'entry':horizontalFlip[self.lastMove]}
  310.                         elif board.board[horizontalFlip[self.lastMove]] == 'O':
  311.                             debug(d,'Invert')
  312.                             return {'offensive':True, 'entry':verticalFlip[horizontalFlip[self.lastMove]]}
  313.                         else:
  314.                             debug(d,'Vertical Flip')
  315.                             return {'offensive':True, 'entry':verticalFlip[self.lastMove]}
  316.                 if board.board['CM'] == 'O':
  317.                     for space in board.board:
  318.                         if board.board[space] == 'X' and space in corners:
  319.                             debug(d,'Form XOX')
  320.                             return {'offensive':True, 'entry':horizontalFlip[verticalFlip[space]]}
  321.  
  322.                 else:
  323.                     return {'offensive':False, 'entry':''}
  324.                
  325.        
  326.     def defensiveStrategy(self, board):
  327.         '''Provide defensive move based on a certain tactic.'''
  328.         if self.tactic == 'center': #Keep Selecting Corners
  329.             for corner in corners:
  330.                 if board.board[corner] == ' ':
  331.                     debug(d,'Get Corners')
  332.                     return {'defense':True, 'entry':corner}
  333.         elif self.tactic == 'corner':
  334.             if board.board['CM'] == ' ': #Get Center
  335.                 debug(d,'Secure Center')
  336.                 return {'defense':True, 'entry':'CM'}
  337.             else:
  338.                 if len(board.blankSpaces()) == 6:
  339.                     cornersFound = 0
  340.                     for corner in corners:
  341.                         if board.board[corner] == 'O':
  342.                             cornersFound += 1
  343.                     if cornersFound == 2:
  344.                         for side in sides:
  345.                             if board.board[side] == ' ':
  346.                                 debug(d,'Two Corners')
  347.                                 return {'defense':True, 'entry':side}
  348.                     else:
  349.                         self.strategy = 'offensive'
  350.                         self.tactic = 'center'
  351.                         self.reiterate = True
  352.                         debug(d,'Retrategizing')
  353.                         return {'defense':False, 'entry':''}
  354.         elif self.tactic == 'side':
  355.             if board.board['CM'] == ' ': #Get Center
  356.                 return {'defense':True, 'entry':'CM'}
  357.             else:
  358.                 if len(board.blankSpaces()) == 6:
  359.                     report = board.fieldReport()
  360.                     for triad in report:
  361.                         if triad == ('O','X','O'):
  362.                             debug(d,'OXO Kill')
  363.                             return {'defense':True, 'entry':random.choice(corner)}
  364.            
  365.         return {'defense':False, 'entry':''}
  366.  
  367.     def think(self, board):
  368.         '''Return best possible move for a given situation.'''
  369.         ### Query Board for Information ###
  370.         while True:
  371.             report = board.fieldReport()
  372.             totalDoubles = board.returnDoubles(report)
  373.             oDoubles = {key:totalDoubles[key] for key in totalDoubles if 'O' in totalDoubles[key]}
  374.             xDoubles = {key:totalDoubles[key] for key in totalDoubles if 'X' in totalDoubles[key]}
  375.             pool = board.blankSpaces()
  376.             if pool == []:
  377.                 return
  378.  
  379.             ### Check for Winning Counters ###
  380.             counterMove = self.counter(xDoubles)
  381.             if counterMove['counter']:
  382.                 self.lastMove = counterMove['entry']
  383.                 return counterMove['entry']
  384.  
  385.             ### Check for Losing Counters ###
  386.             counterMove = self.counter(oDoubles)
  387.             if counterMove['counter']:
  388.                 self.lastMove = counterMove['entry']
  389.                 return counterMove['entry']
  390.            
  391.             ### Check for Trapping Moves ###
  392.             trapMove = self.trapSimulation(board, report, pool)
  393.             if trapMove['trap']:
  394.                 self.lastMove = trapMove['entry']
  395.                 return trapMove['entry']
  396.  
  397.             ### Strategize ###
  398.             if self.strategy == '':
  399.                 if len(board.blankSpaces()) == 9:
  400.                     self.strategy = 'offensive'
  401.                 else:
  402.                     self.strategy = 'defensive'
  403.  
  404.             if self.tactic == '':
  405.                 self.decideTactic(board)
  406.  
  407.             if self.strategy == 'offensive':
  408.                 offenseMove = self.offensiveStrategy(board)
  409.                 if offenseMove['offensive']:
  410.                     self.lastMove = offenseMove['entry']
  411.                     return offenseMove['entry']
  412.             else:
  413.                 defenseMove = self.defensiveStrategy(board)
  414.                 if defenseMove['defense']:
  415.                     self.lastMove = defenseMove['entry']
  416.                     return defenseMove['entry']
  417.  
  418.             ### Random Guess ###
  419.             if self.reiterate:
  420.                 self.reiterate = False
  421.             else:
  422.                 debug(d,'Random Entry')
  423.                 entry = random.choice(pool)
  424.                 self.lastMove = entry
  425.                 return entry
  426.  
  427. class debugger():
  428.  
  429.     def __init__(self):
  430.         self.active = True
  431.  
  432. #===========HELPER FUNCTIONS===========#
  433.  
  434. def nextTurn(turnList, currentTurn):
  435.     currentIndex = turnList.index(currentTurn)
  436.     if (currentIndex + 1) == len(turnList):
  437.         return turnList[0]
  438.     else:
  439.         return turnList[currentIndex+1]
  440.  
  441. def debug(debugObject,statement):
  442.     if debugObject.active:
  443.         print(statement)
  444.  
  445. #===========GAME FUNCTIONS=============#
  446.  
  447. d = debugger()
  448.  
  449. def TicTacToe(debugging=True):
  450.  
  451.     if not debugging:
  452.         d.active = False
  453.  
  454.     ###MENUS###
  455.  
  456.     def mainMenu():
  457.         difficulty = 'Easy'
  458.         players = {}
  459.         debugStatus = ''
  460.         while True:
  461.             if d.active:
  462.                 debugStatus = 'Enabled'
  463.             else:
  464.                 debugStatus = 'Disabled'
  465.             print('\t\tTic-Tac-Toe')
  466.             print('\n\t1. One Player')
  467.             print('\t2. Two Players')
  468.             if players != {}:
  469.                 print('\t\tA. Rematch')
  470.             print('\n\t3. Computer Difficulty:',difficulty)
  471.             print('\t4. Debugging',debugStatus)
  472.            
  473.             selection = str(input('\nSelect Game Mode: '))
  474.             while selection not in ['1', '2', '3', '4', 'A', 'a', 'escape']:
  475.                 print('\nSelection Invalid')
  476.                 selection = str(input('\nSelect Game Mode: '))
  477.                
  478.             if selection == '1':
  479.                 print()
  480.                 players = singlePlayer(difficulty)
  481.                 print()
  482.                 players = gameplay(players)
  483.  
  484.             elif selection == '2':
  485.                 print()
  486.                 players = multiPlayer()
  487.                 print()
  488.                 players = gameplay(players)
  489.  
  490.             elif selection == '3':
  491.                 print()
  492.                 if difficulty == 'Easy':
  493.                     difficulty = 'Medium'
  494.                 elif difficulty == 'Medium':
  495.                     difficulty = 'Hard'
  496.                 elif difficulty == 'Hard':
  497.                     difficulty = 'Impossible'
  498.                 else:
  499.                     difficulty = 'Easy'
  500.  
  501.             elif selection == '4':
  502.                 print()
  503.                 if d.active:
  504.                     d.active = False
  505.                 else:
  506.                     d.active = True
  507.  
  508.             elif selection in ['A','a']:
  509.                 if players != {}:
  510.                     print()
  511.                     players = gameplay(players)
  512.                 else:
  513.                     print('Not an Option')
  514.  
  515.             elif selection == 'escape':
  516.                 break
  517.  
  518.             else:
  519.                 raise BadInputError('Data Provided Has No Function')
  520.  
  521.     def singlePlayer(difficulty):
  522.         '''Returns dictionary of players for singleplayer gameplay.'''
  523.        
  524.         players = {}
  525.  
  526.         newPlayer = player('play1')
  527.         print('Player 1',end=' ')
  528.         if not d.active:
  529.             nameEntry = str(input('please enter your name: '))
  530.             while newPlayer.setName(nameEntry):
  531.                 print('Invalid Entry!')
  532.                 print('Player 1',end=' ')
  533.                 nameEntry = str(input('please enter your name: '))
  534.         else:
  535.             newPlayer.setName("Debug")
  536.            
  537.         newPlayer.setSymbol('O')
  538.         players['play1'] = newPlayer
  539.         players['comp'] = computer(difficulty)
  540.  
  541.         return players
  542.  
  543.     def multiPlayer():
  544.         '''Returns dictionary of players for multiplayer gameplay.'''
  545.  
  546.         symbols = ['X','O']
  547.         players = {}
  548.  
  549.         for identity in ['play1','play2']:
  550.            
  551.             if identity == 'play1':
  552.                 title = 'Player 1'
  553.             else:
  554.                 title = 'Player 2'
  555.  
  556.             newPlayer = player(identity)
  557.             print(title,end=' ')
  558.             nameEntry = str(input('please enter your name: '))
  559.             while newPlayer.setName(nameEntry):
  560.                 print('Invalid Entry!')
  561.                 print(title,end=' ')
  562.                 nameEntry = str(input('please enter your name: '))
  563.             if identity == 'play1':
  564.                 symbolEntry = str(input('O or X: '))
  565.                 while newPlayer.setSymbol(symbolEntry):
  566.                     print('Invalid Entry!')
  567.                     symbolEntry = str(input('O or X: '))
  568.                 symbols.remove(symbolEntry.upper())
  569.             else:
  570.                 newPlayer.setSymbol(symbols[0])
  571.             players[identity] = newPlayer
  572.  
  573.         return players
  574.  
  575.     def gameplay(players):
  576.         '''Provides turn system for a Tic Tac Toe Game.'''
  577.  
  578.         if 'comp' not in players:
  579.             print('Beginning Game, {} vs {}'.format(players['play1'].getName(),players['play2'].getName()))
  580.         else:
  581.             print('Beginning Game, {} vs the Computer'.format(players['play1'].getName()))
  582.         print("Win Two Matches In a Row to Be Victorious")
  583.        
  584.         board = ticBoard(mode='blank')
  585.        
  586.         turnList = list(players.keys())
  587.         firstTurn = random.choice(turnList)
  588.         #firstTurn = 'comp'
  589.         turn = firstTurn
  590.         selected = []
  591.  
  592.         while True:
  593.             board.draw()
  594.             if turn != 'comp':
  595.                 print(players[turn].getName(),'please select a space.')
  596.                 selection = str(input('Space: ')).upper()
  597.                 if not d.active or selection not in ["RESET", "END"]:
  598.                     errorCheck = board.checkEntry(selection,selected)
  599.                     while not errorCheck['valid']:
  600.                         errorMessage = errorCheck['message'].format(selection)
  601.                         print(errorMessage)
  602.                         print(players[turn].getName(),'please select a space.')
  603.                         selection = str(input('Space: ')).upper()
  604.                         errorCheck = board.checkEntry(selection,selected)
  605.                 if selection == 'END':
  606.                     break
  607.                
  608.             else:
  609.                 print('Computer Turn')
  610.                 selection = players['comp'].think(board)
  611.                 errorCheck = board.checkEntry(selection,selected)
  612.                 print('Computer Chooses {}'.format(selection))
  613.                
  614.             if selection != 'RESET' or not d.active:
  615.                 board.place(players[turn].getSymbol(), errorCheck['entry'])
  616.                 selected.append(selection)
  617.            
  618.             if board.checkWin() and selection != 'RESET':
  619.                 board.draw()
  620.                 selected = []
  621.                 winner = turn
  622.                 loser = nextTurn(turnList, turn)
  623.                 if players[winner].getMatches() == 1:
  624.                     print(players[turn].getName(),end=' ')
  625.                     str(input('wins!'))
  626.                     players[turn].win()
  627.                     players[loser].resetMatch()
  628.                     players[winner].resetMatch()
  629.                     break #END GAME
  630.                 elif players[winner].getMatches() == 0:
  631.                     print(players[turn].getName(),end=' ')
  632.                     players[winner].matchWin()
  633.                     players[loser].resetMatch()
  634.                     str(input('won a match! Beginning next round.'))
  635.                     if 'comp' in players:
  636.                        players['comp'].clearStrategy()
  637.                     board.clear()
  638.                     turn = loser
  639.                     firstTurn = loser
  640.                
  641.             else:
  642.                 if len(board.blankSpaces()) == 0 or selection == 'RESET':
  643.                     board.draw()
  644.                     str(input('Draw! Beginning next round.'))
  645.                     if 'comp' in players:
  646.                        players['comp'].clearStrategy()
  647.                     players[turn].resetMatch()
  648.                     players[nextTurn(turnList, turn)].resetMatch()
  649.                     board.clear()
  650.                     firstTurn = nextTurn(turnList, firstTurn)
  651.                     turn = firstTurn
  652.                     selected = []
  653.                 else:
  654.                     turn = nextTurn(turnList, turn)
  655.                
  656.         try:
  657.             print()
  658.             print('\t\tCurrent Score\n')
  659.             print('\t'+players[winner].getName()+'\t\t\t'+str(players[winner].getScore()))
  660.             print('\t'+players[loser].getName()+'\t\t\t'+str(players[loser].getScore()))
  661.             print('\n==========================================\n')
  662.         except:
  663.             print('\tNo Scores to Show.\n')
  664.  
  665.         return players
  666.  
  667.     mainMenu() #Load Main Menu First
  668.  
  669. activeDebug = False
  670. TicTacToe(activeDebug) #Begin Program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement