Esempio n. 1
0
    def alphabetaBclicked(self):
        self.gameType = "ALPHABETA"
        print(
            "\n\n\n-------------------ALPHA BETA PRUNING-------------------\n-------------------AI TURN---------------------"
        )
        action = alphabeta(globalState)
        print(
            "---- (as all action have same utility value, we choose one random) ----\n********************************************************************\n\n\n"
        )
        temp = random.choice([1, 2, 3, 4])

        self.b[temp - 1].setIcon(
            QIcon("/Users/rachitrathore/PycharmProjects/AI3/green.png"))
        self.b[temp - 1].setIconSize(QSize(50, 50))
        self.b[temp - 1].setEnabled(False)
        coord = noToCoord(temp)
        globalState.machineCoord.append(coord)
        self.winL.setText(
            "Machine played first! \nHuman it's your Turn...Place your blue coin"
        )
        self.winL.adjustSize()
        self.minimaxB.setEnabled(False)
        self.alphabetaB.setEnabled(False)
        for i in range(16):
            self.b[i].setEnabled(True)
Esempio n. 2
0
    def b16clicked(self):
        if not possibleClicks(globalState).__contains__([3, 3]):
            self.winL.setText(
                "HUMAN TURN -- \nPlease place your coin in right position")
            self.winL.adjustSize()
            return
        else:
            self.b[15].setIcon(QIcon("blue.png"))
            self.b[15].setIconSize(QSize(50, 50))
            self.b[15].setEnabled(False)
            globalState.humanCoord.append([3, 3])

            if terminalTest(globalState) and utilityValue(globalState) == -1:
                self.winL.setText("HUMAN WON!! Please reset")
                self.winL.adjustSize()
                for i in range(16):
                    self.b[i].setEnabled(False)
                return

            if self.gameType == "MINIMAX":
                action = minimax(globalState)
            elif self.gameType == "ALPHABETA":
                action = alphabeta(globalState)

            globalState.machineCoord.append(action)
            temp = coordToNo(action)
            self.b[temp - 1].setIcon(QIcon("green.png"))
            self.b[temp - 1].setIconSize(QSize(50, 50))
            self.b[temp - 1].setEnabled(False)

            if terminalTest(globalState) and utilityValue(globalState) == 1:
                self.winL.setText("MACHINE WON!! Please reset")
                self.winL.adjustSize()
                for i in range(16):
                    self.b[i].setEnabled(False)
                return

            self.winL.setText(
                "Machine already played ! \nHuman it's your Turn...Place your blue coin"
            )
            self.winL.adjustSize()