2022-09-14

Sep 14 In-Class Exercise Thread.

Please post your solutions to the Sep 14 In-Class Exercise to this thread.
Best,
Chris
Please post your solutions to the Sep 14 In-Class Exercise to this thread. Best, Chris

-- Sep 14 In-Class Exercise Thread
def gameProgress(self):
    board = self.board
    answers = [
            [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 answer in answers:
        s = board[answer[0] // 3][answer[0] % 3]
        s += board[answer[1] // 3][answer[1] % 3]
        s += board[answer[2] // 3][answer[2] % 3]
        if s == "xxx":
            return "x"
        elif s == "ooo":
            return "o"
    for line in board:
        if "." in line:
            return "Continue"
    return "Draw"
(Edited: 2022-09-14)
def gameProgress(self): board = self.board answers = [ [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 answer in answers: s = board[answer[0] // 3][answer[0] % 3] s += board[answer[1] // 3][answer[1] % 3] s += board[answer[2] // 3][answer[2] % 3] if s == "xxx": return "x" elif s == "ooo": return "o" for line in board: if "." in line: return "Continue" return "Draw"

-- Sep 14 In-Class Exercise Thread
    def gameProgress(self):
        # I like to brute force things
        ans = [
            [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 winSet in ans:
            if (self.board[winSet[0]//3][winSet[0]%3] == 
                self.board[winSet[1]//3][winSet[1]%3] == 
                self.board[winSet[2]//3][winSet[2]%3]):
                if self.board[winSet[0]//3][winSet[0]%3] == "x":
                    return "x wins"
                elif self.board[winSet[0]//3][winSet[0]%3] == "o":
                    return "o wins"
        for i in self.board:
            for j in i:
                if j == ".":
                    return "continue"
        return "draw"
def gameProgress(self): # I like to brute force things ans = [ [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 winSet in ans: if (self.board[winSet[0]//3][winSet[0]%3] == self.board[winSet[1]//3][winSet[1]%3] == self.board[winSet[2]//3][winSet[2]%3]): if self.board[winSet[0]//3][winSet[0]%3] == "x": return "x wins" elif self.board[winSet[0]//3][winSet[0]%3] == "o": return "o wins" for i in self.board: for j in i: if j == ".": return "continue" return "draw"

-- Sep 14 In-Class Exercise Thread
 def gameProgress(self):
      for i in range(len(self.board)):
           if i == 0:
                for j in range(len(self.board[i]):
                     if j == 0:
                          if self.board[i][j] == self.board[i + 1][j + 1] == self.board[i + 2][j + 2] and (self.board[i][j] in ('o', 'x')):
                          return self.board[i][j]
                     elif j == 1:
                          if self.board[i][j] == self.board[i + 1][j] == self.board[i + 2][j] and (self.board[i][j] in ('o', 'x')):
                               return self.board[i][j]
                     else:
                          if self.board[i][j] == self.board[i + 1][j - 1] == self.board[i + 2][j - 2] and (self.board[i][j] in ('o', 'x')):
                               return self.board[i][j]
           else:
                if self.board[i][0] == self.board[i][1] == self.board[i][2] and self.board[i][0] in ('x','o'):
                     return self.board[i][0]
      for i in range(len(self.board)):
           for j in range(len(self.board)):
                if self.board[i][j] == '.':
                     return 'continue'
      return 'draw'
(Edited: 2022-09-14)
def gameProgress(self): for i in range(len(self.board)): if i == 0: for j in range(len(self.board[i]): if j == 0: if self.board[i][j] == self.board[i + 1][j + 1] == self.board[i + 2][j + 2] and (self.board[i][j] in ('o', 'x')): return self.board[i][j] elif j == 1: if self.board[i][j] == self.board[i + 1][j] == self.board[i + 2][j] and (self.board[i][j] in ('o', 'x')): return self.board[i][j] else: if self.board[i][j] == self.board[i + 1][j - 1] == self.board[i + 2][j - 2] and (self.board[i][j] in ('o', 'x')): return self.board[i][j] else: if self.board[i][0] == self.board[i][1] == self.board[i][2] and self.board[i][0] in ('x','o'): return self.board[i][0] for i in range(len(self.board)): for j in range(len(self.board)): if self.board[i][j] == '.': return 'continue' return 'draw'

-- Sep 14 In-Class Exercise Thread
 
 def gameProgress(self)
     symbols = ['x', 'o']
     for symbol in symbols:
 
         # check all the horizontal rows
         for i in range(3):
             if(board[i] == symbol+symbol+symbol):
                 return symbol
 
         #check all the verticle rows
         for j in range(3):
             if(board[0][j] + board[1][j] + board[2][j] == symbol+symbol+symbol):
                 return symbol
 
         #check all the diagonals
         if( board[0][0] == board[1][1] == board[2][2] == symbol):
             return symbol
 
         if( board[0][2] == board[1][1] == board[2][0] ==symbol):
             return symbol
 
     for i in range(3):
         for j in range(3):
             if(board[i][j] != '.'):
                 return "continue"
     
     return "draw"
(Edited: 2022-09-14)
def gameProgress(self) symbols = ['x', 'o'] for symbol in symbols: # check all the horizontal rows for i in range(3): if(board[i] == symbol+symbol+symbol): return symbol #check all the verticle rows for j in range(3): if(board[0][j] + board[1][j] + board[2][j] == symbol+symbol+symbol): return symbol #check all the diagonals if( board[0][0] == board[1][1] == board[2][2] == symbol): return symbol if( board[0][2] == board[1][1] == board[2][0] ==symbol): return symbol for i in range(3): for j in range(3): if(board[i][j] != '.'): return "continue" return "draw"

-- Sep 14 In-Class Exercise Thread
    def gameProgress(self):
        game = self.board
        for i in range(3):
            #check rows
            if game[i][0] == game[i][1] == game[i][2] and game[i][0] != '.':
                return game[i][0]
            #check columns
            if game[0][i] == game[1][i] == game[2][i] and game[0][i] != '.':
                return game[0][i]
                
        #check diagonals
        if game[0][0] == game[1][1] == game[2][2] and game[0][0] != '.':
            return game[0][0]
        if game[0][2] == game[1][1] == game[2][0] and game[1][1] != '.':
            return game[1][1]
        
        #check if draw or continue
        done = True
        for i in range(3):
            for j in range(3):
                if game[i][j] == '.': done = False
        
        if done: return 'draw'
        else: return 'continue'
(Edited: 2022-09-14)
def gameProgress(self): game = self.board for i in range(3): #check rows if game[i][0] == game[i][1] == game[i][2] and game[i][0] != '.': return game[i][0] #check columns if game[0][i] == game[1][i] == game[2][i] and game[0][i] != '.': return game[0][i] #check diagonals if game[0][0] == game[1][1] == game[2][2] and game[0][0] != '.': return game[0][0] if game[0][2] == game[1][1] == game[2][0] and game[1][1] != '.': return game[1][1] #check if draw or continue done = True for i in range(3): for j in range(3): if game[i][j] == '.': done = False if done: return 'draw' else: return 'continue'

-- Sep 14 In-Class Exercise Thread
        def gameProgress(self):
            for i, item in enumerate(self.board):
                if(self.board[i][0] != '.' and self.board[i][0] == self.board[i][1] and self.board[i][2] == self.board[i][0]):
                    return print(self.board[0][i])
                if (self.board[0][i] != '.' and self.board[0][i] == self.board[1][i] and self.board[2][i] == self.board[0][i]):
                    return print(self.board[0][i])
            if (self.board[0][0] != '.' and self.board[1][1] == self.board[0][0] and self.board[2][2] == self.board[0][0]):
                return print(self.board[0][0])
            if (self.board[0][2] != '.' and self.board[1][1] == self.board[0][2] and self.board[2][0] == self.board[0][2]):
                return print(self.board[0][2])
            for item in self.board:
                if '.' in item:
                    return print("Continue")
            return print("Draw")
(Edited: 2022-09-14)
def gameProgress(self): for i, item in enumerate(self.board): if(self.board[i][0] != '.' and self.board[i][0] == self.board[i][1] and self.board[i][2] == self.board[i][0]): return print(self.board[0][i]) if (self.board[0][i] != '.' and self.board[0][i] == self.board[1][i] and self.board[2][i] == self.board[0][i]): return print(self.board[0][i]) if (self.board[0][0] != '.' and self.board[1][1] == self.board[0][0] and self.board[2][2] == self.board[0][0]): return print(self.board[0][0]) if (self.board[0][2] != '.' and self.board[1][1] == self.board[0][2] and self.board[2][0] == self.board[0][2]): return print(self.board[0][2]) for item in self.board: if '.' in item: return print("Continue") return print("Draw")

-- Sep 14 In-Class Exercise Thread
    def gameProgress(self):
        for i in range(3):
            #rows
            if(self.board[i][0] == self.board[i][1] == self.board[i][2]):
                return self.board[i][0]
            #columns
            if(self.board[0][i] == self.board[1][i] == self.board[2][i]):
                return self.board[i][0]
        if(self.board[0][0] == self.board[1][1] == self.board[2][2]):
            return self.board[0][0]
        if(self.board[2][0] == self.board[1][1] == self.board[0][2]):
            return self.board[2][0]
        for i in range(3):
            for j in range(3):
                if(self.board[i][j] != '.'):
                    return 'continue'
        return 'draw'
def gameProgress(self): for i in range(3): #rows if(self.board[i][0] == self.board[i][1] == self.board[i][2]): return self.board[i][0] #columns if(self.board[0][i] == self.board[1][i] == self.board[2][i]): return self.board[i][0] if(self.board[0][0] == self.board[1][1] == self.board[2][2]): return self.board[0][0] if(self.board[2][0] == self.board[1][1] == self.board[0][2]): return self.board[2][0] for i in range(3): for j in range(3): if(self.board[i][j] != '.'): return 'continue' return 'draw'

-- Sep 14 In-Class Exercise Thread
def gameProgress(self):
    #draw
    draw = False
    for i in range(len(self.board)):
        for j in range(len(self.board[i])):
            if self.board[i][j] != '.':
                draw = True
    if not draw: return 'continue'
    else: return 'draw'
(Edited: 2022-09-14)
def gameProgress(self): #draw draw = False for i in range(len(self.board)): for j in range(len(self.board[i])): if self.board[i][j] != '.': draw = True if not draw: return 'continue' else: return 'draw'

-- Sep 14 In-Class Exercise Thread
 GameProgress(self):
     Result = “”
     For col in range(3):
        Check = “”
        For row in range(3):
            If row.contains(“.”):
               Result = “continue”
               Break
            If self.board[row] = ‘xxx’:
               Result = ‘x’
               Break
            Elif board[row] = ‘ooo’:
               Result =‘o’
               Break
            Check += board[row][col]
      If check = ‘xxx’:
          Result = ‘x’
          Break
      Elif check = ‘ooo’:
          Result = ‘o’
          Break
     # Missing Check diagonal
     Return result if result else ‘draw’
GameProgress(self): Result = “” For col in range(3): Check = “” For row in range(3): If row.contains(“.”): Result = “continue” Break If self.board[row] = ‘xxx’: Result = ‘x’ Break Elif board[row] = ‘ooo’: Result =‘o’ Break Check += board[row][col] If check = ‘xxx’: Result = ‘x’ Break Elif check = ‘ooo’: Result = ‘o’ Break # Missing Check diagonal Return result if result else ‘draw’
[ Next ]
X