class theGame:
    playerSymbol = ["X","O"]
    def __init__ (self):
        self.board = "1 2 3 4 5 6 7 8 9".split()
        self.player = 1
    def getPlayer(self):
        return self.player
    def getPlayerSymbol(self):
        return theGame.playerSymbol[self.player]
    def printBoard(self):
        if len(self.board) != 9:
            return
        print(self.board[0]+"|"+self.board[1]+"|"+self.board[2])
        print("-----")
        print(self.board[3]+"|"+self.board[4]+"|"+self.board[5])
        print("-----")
        print(self.board[6]+"|"+self.board[7]+"|"+self.board[8])
        print("")    
    def getResult(self):
        b = self.board
        #Check for winner first
        # check for rows
        if b[0] == b[1] and b[1] == b[2]:
            return 1
        if b[3] == b[4] and b[3] == b[5]:
            return 1
        if b[6] == b[7] and b[6] == b[8]:
            return 1

        #check for colmns
        if b[0] == b[3] and b[3] == b[6]:
            return 1

        if b[1] == b[4] and b[4] == b[7]:
            return 1

        if b[2] == b[5] and b[5] == b[8]:
            return 1

        #check diagonals
        if b[0] == b[4] and b[4] == b[8]:
            return 1

        if b[2] == b[4] and b[4] == b[6]:
            return 1
        
        for i in b:
            if i in "123456789":
                return 0
        return 2


    def isValidMove(self,move):
        if not (move >= 1 and move <= 9):
            return False
        if self.board[move-1] in "123456789":
            return True
        return False

    def switchPlayers(self):
        self.player = (self.player + 1) % 2
    
    def makeMove(self,m):
        if self.isValidMove(m):
          
            self.board[m-1] = theGame.playerSymbol[self.player]
    
