예제 #1
0
def run(agent=defaultAgent, ghost=defaultGhost, layout=defaultLayout):
    sys.setrecursionlimit(8000)

    usage = """
    USAGE:      python run.py <game_options> <agent_options>
    EXAMPLES:   (1) python run.py
                    - plays a game with the human agent
                      in small maze
    """

    parser = ArgumentParser(usage)
    parser.add_argument('--seed', help='RNG seed', type=int, default=1)
    parser.add_argument('--agentfile',
                        help='Python file containing a `PacmanAgent` class.',
                        default=agent)
    parser.add_argument(
        '--ghostagent',
        help='Ghost agent available in the `ghostAgents` module.',
        choices=["dumby", "greedy", "smarty"],
        default=ghost)
    parser.add_argument('--layout',
                        help='Maze layout (from layout folder).',
                        default=layout)
    parser.add_argument('--silentdisplay',
                        help="Disable the graphical display of the game.",
                        action="store_true")

    args = parser.parse_args()

    if (args.agentfile == "humanagent.py" and args.silentdisplay):
        print("Human agent cannot play without graphical display")
        exit()
    agent = load_agent_from_file(args.agentfile)(args)

    gagt = ghosts[args.ghostagent]
    nghosts = 1
    if (nghosts > 0):
        gagts = [gagt(i + 1) for i in range(nghosts)]
    else:
        gagts = []
    total_score, total_computation_time, total_expanded_nodes = runGame(
        args.layout, agent, gagts, not silentDisplay, expout=0)

    return [total_score, total_computation_time, total_expanded_nodes]
예제 #2
0
파일: run.py 프로젝트: Pseudolesss/ia1
                        default=0)
    parser.add_argument('--agentfile',
                        help='Python file containing a `PacmanAgent` class.',
                        default="humanagent.py")
    parser.add_argument(
        '--ghostagent',
        help='Ghost agent available in the `ghostAgents` module.',
        choices=["lefty", "greedy", "randy"],
        default="greedy")
    parser.add_argument('--layout',
                        help='Maze layout (from layout folder).',
                        default="small")
    parser.add_argument('--silentdisplay',
                        help="Disable the graphical display of the game.",
                        action="store_true")

    args = parser.parse_args()
    agent = load_agent_from_file(args.agentfile)(args)

    gagt = ghosts[args.ghostagent]
    if (args.nghosts > 0):
        gagts = [gagt(i + 1) for i in range(args.nghosts)]
    else:
        gagts = []
    total_score, total_computation_time, total_expanded_nodes = runGame(
        args.layout, agent, gagts, not args.silentdisplay, expout=0)

    print("Total score : " + str(total_score))
    print("Total computation time (seconds) : " + str(total_computation_time))
    print("Total expanded nodes : " + str(total_expanded_nodes))
    agent = load_agent_from_file(args.agentfile, "PacmanAgent")(args)

    gagt = ghosts[args.ghostagent]
    nghosts = args.nghosts
    if (nghosts > 0):
        gagts = [gagt(i + 1, args) for i in range(nghosts)]
    else:
        gagts = []
    layout = layout_thin_borders(args.layout, args.w)
    bsagt = None
    if args.bsagentfile is not None:
        bsagt = load_agent_from_file(args.bsagentfile,
                                     "BeliefStateAgent")(args)

    total_score, total_computation_time, total_expanded_nodes = runGame(
        layout,
        agent,
        gagts,
        bsagt,
        not args.silentdisplay,
        expout=0,
        hiddenGhosts=args.hiddenghosts)

    print("Total score : " + str(total_score))
    print("Total computation time (seconds) : " + str(total_computation_time))
    print("Total expanded nodes : " + str(total_expanded_nodes))
    f = open("temp", "w+")
    s, c, e = total_score, total_computation_time, total_expanded_nodes
    f.write(str(s) + ";" + str(c) + ";" + str(e))
    f.close()
예제 #4
0
        gagts = []
    layout = args.layout
    bsagt = None
    oraclebsagt = None
    startingIndex = 0
    if args.bsagentfile is not None:
        bsagt = load_agent_from_file(args.bsagentfile,
                                     "BeliefStateAgent")(args)
        startingIndex = nghosts + 1
    if args.oraclebsagentfile is not None:
        oraclebsagt = load_agent_from_file(args.oraclebsagentfile,
                                           "BeliefStateAgent")(args)
    total_score, total_computation_time, _ = runGame(
        layout,
        agent,
        gagts,
        bsagt,
        not args.silentdisplay,
        expout=0,
        hiddenGhosts=args.hiddenghosts,
        edibleGhosts=args.edibleghosts,
        startingIndex=startingIndex,
        oracleBeliefStateAgent=oraclebsagt)

    print("Total score : " + str(total_score))
    print("Total computation time (seconds) : " + str(total_computation_time))
    f = open("temp", "w+")
    s, c = total_score, total_computation_time
    f.write(str(s) + ";" + str(c))
    f.close()
    agent = load_agent_from_file(args.agentfile, "PacmanAgent")(args)

    gagt = ghosts[args.ghostagent]
    nghosts = args.nghosts
    if (nghosts > 0):
        gagts = [gagt(i + 1, args) for i in range(nghosts)]
    else:
        gagts = []
    layout = args.layout
    bsagt = None
    if args.bsagentfile is not None:
        bsagt = load_agent_from_file(args.bsagentfile,
                                     "BeliefStateAgent")(args)

    total_score, total_computation_time, _ = runGame(
        layout,
        agent,
        gagts,
        bsagt,
        not args.silentdisplay,
        expout=0,
        hiddenGhosts=args.hiddenghosts,
        edibleGhosts=args.edibleghosts)

    print("Total score : " + str(total_score))
    print("Total computation time (seconds) : " + str(total_computation_time))
    f = open("temp", "w+")
    s, c = total_score, total_computation_time
    f.write(str(s) + ";" + str(c))
    f.close()