예제 #1
0
def solve():
    sets=[] # The variable 'sets' stores multiple problem sets.
            # Each problem set comes from a different folder in /Problems/
            # Additional sets of problems will be used when grading projects.
            # You may also write your own problems.

    r = open(os.path.join("Problems","ProblemSetList.txt"))    # ProblemSetList.txt lists the sets to solve.
    line = getNextLine(r)                                   # Sets will be solved in the order they appear in the file.
    while not line=="":                                     # You may modify ProblemSetList.txt for design and debugging.
        sets.append(ProblemSet(line))                       # We will use a fresh copy of all problem sets when grading.
        line=getNextLine(r)                                 # We will also use some problem sets not given in advance.

    # Initializing problem-solving agent from Solver.java
    agent=Solver()   # Your agent will be initialized with its default constructor.
                    # You may modify the default constructor in Solver.java

    # Running agent against each problem set
    with open("AgentAnswers.csv","w") as results:     # Results will be written to ProblemResults.csv.
                                                        # Note that each run of the program will overwrite the previous results.
                                                        # Do not write anything else to ProblemResults.txt during execution of the program.
        results.write("ProblemSet,RProblem,Solver's Answer\n")
        for set in sets:
            for problem in set.problems:   # Your agent will solve one problem at a time.
                #try:
                answer = agent.Solve(problem)  # The problem will be passed to your agent as a RProblem object as a parameter to the Solve method
                                                # Your agent should return its answer at the conclusion of the execution of Solve.

                results.write("%s,%s,%d\n" % (set.name, problem.name, answer))
    r.close()
예제 #2
0
from queue import PriorityQueue
from State import State
from State_string import State_string
from Solver import Solver

if __name__ == "__main__":
    start1 = "hma"
    goal1 = "ham"
    print("Starting...")
    a = Solver(start1, goal1)
    a.Solve()
    for i in range(len(a.path)):
        print("%d)" % i + a.path[i])