コード例 #1
0
    def aiPlay(self):
        m = MiniMax(self.gameBoard)
        best_move = m.bestMove(5, self.gameBoard, self.currentTurn)

        #print("best move: ", best_move)
        self.playPiece(best_move)


#        print('\n\nmove %d: Player %d, column %d\n' % (self.pieceCount, self.currentTurn, randColumn+1))
        if self.currentTurn == 1:
            self.currentTurn = 2
        elif self.currentTurn == 2:
            self.currentTurn = 1
コード例 #2
0
ファイル: testMiniMax.py プロジェクト: BenTarman/Connect-4-AI
    def test_game_end_win(self):
        gameArr = [
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 2, 0, 0, 0, 0, 0],
                    [0, 1, 2, 1, 0, 0, 0],
                    [0, 1, 1, 2, 0, 0, 0],
                    [0, 2, 1, 2, 2, 0, 0],
                    [1, 2, 2, 2, 1, 0, 0]
                  ]

        m = MiniMax(gameArr)
        best_move = m.bestMove(5, gameArr, 2)

        self.assertEqual(best_move, None)
コード例 #3
0
ファイル: testMiniMax.py プロジェクト: BenTarman/Connect-4-AI
    def test_game_end_full(self):
        # player 2 has win on diagnol
        gameArr = [
                    [1, 2, 1, 2, 1, 2, 1],
                    [2, 1, 2, 1, 2, 1, 2],
                    [1, 1, 2, 2, 1, 1, 2],
                    [2, 2, 1, 1, 1, 2, 2],
                    [2, 1, 1, 2, 2, 1, 1],
                    [1, 2, 2, 2, 2, 2, 2]
                  ]
        m = MiniMax(gameArr)
        best_move = m.bestMove(5, gameArr, 2)

        self.assertEqual(best_move, None)
コード例 #4
0
ファイル: testMiniMax.py プロジェクト: BenTarman/Connect-4-AI
    def test_diagnol_win(self):
        # player 2 has win on diagnol
        gameArr = [
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 1, 2, 1, 0, 0, 0],
                    [0, 1, 1, 2, 0, 0, 0],
                    [0, 2, 1, 2, 2, 0, 0],
                    [1, 2, 2, 2, 1, 0, 0]
                  ]
        m = MiniMax(gameArr)
        best_move = m.bestMove(5, gameArr, 2)

        self.assertEqual(best_move, 1)
コード例 #5
0
ファイル: testMiniMax.py プロジェクト: BenTarman/Connect-4-AI
    def test_obvious_win(self):
        #player 1 should go for the win here
        gameArr = [
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0],
                    [1, 2, 0, 0, 0, 0, 0],
                    [1, 2, 0, 0, 0, 0, 0],
                    [1, 2, 0, 0, 0, 0, 0]
                  ]
        m = MiniMax(gameArr)
        best_move = m.bestMove(5, gameArr, 1)

        self.assertEqual(best_move, 0)
コード例 #6
0
ファイル: testMiniMax.py プロジェクト: BenTarman/Connect-4-AI
    def test_block(self):
        #palyer 2 should block player 1 here
        gameArr = [
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 1, 0],
                    [0, 2, 0, 0, 0, 1, 0],
                    [0, 2, 2, 1, 0, 1, 0]
                  ]
        m = MiniMax(gameArr)
        best_move = m.bestMove(5, gameArr, 2)

        self.assertEqual(best_move, 5)