コード例 #1
0
    def action(self, game: GameState):
        if game.game_over():
            return None

        possibleMoves = game.legal_moves()
        boards = game.children()

        win_h = self.win_heuristic(boards)
        if not win_h == -1:
            return possibleMoves[win_h], 1

        evals = self.heuristic.hs(boards)
        evals = self.default_heuristic(boards, evals)

        if self.variance:
            if not game.turn():
                evals = [1 - e for e in evals]
            total = sum(evals)
            evals = [e / total for e in evals]
            choice = random.random()
            s = 0
            for idx, e in enumerate(evals):
                s += e
                if choice <= s:
                    bestIdx = idx
                    break

        else:
            if game.turn():
                bestIdx = np.argmax(evals)
            else:
                bestIdx = np.argmin(evals)

        bestMove = possibleMoves[bestIdx]

        return bestMove, evals[bestIdx]
コード例 #2
0
ファイル: HumanActionModel.py プロジェクト: Minro4/YaraZero
 def action(self, game: GameState):
     print(game.__str__())
     moves = game.legal_moves()
     print(game.moves_str())
     inp = int(input())
     return moves[inp], 0