Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(0)  |  Derive(0)  |  Import(2)
Solves a game using iterative deepening, i.e. determines if by playing
perfectly the first player can force a win, or whether it will always
lose against a perfect opponent.


This algorithm explores the game by using several times the Negamax
algorithm, always starting at the initial state of the game, but
taking increasing depth (in the list ai_depths) until the score of
the initial condition indicates that the first player will certainly
win or loose, in which case it stops. The use of transposition table(more...)

        def id_solve(game, ai_depths, win_score, scoring=None,
          tt=None, verbose=True):
    """
    Solves a game using iterative deepening, i.e. determines if by playing
    perfectly the first player can force a win, or whether it will always
    lose against a perfect opponent.
    
    
    This algorithm explores the game by using several times the Negamax
    algorithm, always starting at the initial state of the game, but
    taking increasing depth (in the list ai_depths) until the score of
    the initial condition indicates that the first player will certainly
    win or loose, in which case it stops. The use of transposition table
    leads to speed gain as the results of shallower searches are used to
    help exploring the deeper ones.
        
    Arguments:
    ----------
    
    :param ai_depths: list of AI depths to try (e.g. [5,6,7,8,9,10])
    :param win_score: Score above which a score means a win.
    :param scoring: scoring function (see Negamax)
    :param tt: (optional) a transpo. table to speed up computations.
    :param verbose: If true, prints a summary of the best move after each
        depth tried.
        
    Returns
    -------
    
    This function returns a tuple (result, depth, move, tt)
    
    :result: Either 1 (certain victory of the first player) or -1
    (certain defeat) or 0 (either draw, or the search was not deep enough)
    :depth: The minimal number of moves before victory (or defeat)
    :move: Best move to play for the first player.
    :tt: will be None if ``use_tt`` was set to false, else will be a
    transposition table containing all the relevant situations to play
    a perfect game and can be used with ``AI_player(tt)``
    """
    
    if not hasattr(game, 'players'): # the user provided a Game class
        game = game(players = [AI_Player(None), AI_Player(None)])
    
    for depth in ai_depths:
        ai = Negamax(depth, scoring, tt= tt)
        ai(game)
        alpha = ai.alpha
        if verbose:
             print( "d:%d, a:%d, m:%s"%(depth, alpha, str(game.ai_move)))
        if abs(alpha) >= win_score:
            break
    
    # 1:win, 0:draw, -1:defeat
    result = (+1 if alpha>= win_score else (
             -1 if alpha <= -win_score else 0))
    
    return result, depth, game.ai_move
        


src/e/a/easyAI-0.0.0.4/easyAI/__init__.py   easyAI(Download)
from .TwoPlayersGame import TwoPlayersGame
from .Player import Human_Player, AI_Player
from .AI import Negamax, DictTT, id_solve, df_solve
 

src/e/a/easyAI-HEAD/easyAI/__init__.py   easyAI(Download)
from .TwoPlayersGame import TwoPlayersGame
from .Player import Human_Player, AI_Player
from .AI import Negamax, DictTT, id_solve, df_solve