def placePieceGeneric(self, locI, locJ): board = CPU.convertBoard(self.cpu, self.getGameBoard()) currTurn = self.getCurrTurn() if currTurn == "Player": player = -1 else: player = 1 five = self.fiveInARow(board, player) self.checkWin() if not self.getGameBoard()[locI][locJ].hasStone and not self.gameOver: # Check who's turn it is if currTurn == "Player": self.getGameBoard()[locI][locJ].click(currTurn) self.setCurrTurn("CPU") board = CPU.convertBoard(self.cpu, self.getGameBoard()) five = self.fiveInARow(board, -1) self.checkWin() self.placePieceCPU() elif currTurn == "CPU": self.getGameBoard()[locI][locJ].click(currTurn) self.setCurrTurn("Player") board = CPU.convertBoard(self.cpu, self.getGameBoard()) five = self.fiveInARow(board, 1) self.checkWin() else: return -1 # A problem occurred five = self.fiveInARow(board, player) board = CPU.convertBoard(self.cpu, self.getGameBoard()) self.checkWin()
def checkWin(self): # Check which player wins and output it board = CPU.convertBoard(self.cpu, self.getGameBoard()) cpuWon = self.fiveInARow(board, 1) playerWon = self.fiveInARow(board, -1) if not self.gameOver: if playerWon > 0: self.playerWins = True self.gameOver = True if cpuWon > 0: self.computerWins = True self.gameOver = True