Example #1
0
    def run(self):
        test = False
        print(type(test))
        #   sender = self.sender()

        puz = puzzle()

        try:

            puz.work(self.field_Edit1.text(), self.field_Edit2.text(),
                     self.field_Edit3.text(), self.field_Edit4.text(),
                     self.field_Edit5.text(), self.field_Edit6.text())

        except Exception as ex:
            print(ex)
            self.field_7.hide()
            choice = QMessageBox.question(self, 'Error!', str(ex),
                                          QMessageBox.Ok)

            return
        QMessageBox.question(self, 'Ok!', "Успешное добавление в колоду",
                             QMessageBox.Ok)
        self.field_7.hide()
Example #2
0
from search import astar_search, breadth_first_search

import sys # to get command-line arguments
import time # to count time of execution




"""
python run_A_Star.py heuristicNo size steps
"""
arg = sys.argv

heuristic = int(arg[1])

p = puzzle(None, True, "inputState.txt", False, None)

startTime = time.time()

if heuristic == 0 :
    solution = breadth_first_search(p)
elif heuristic == 1 :
    solution = astar_search(p, lambda x : h1(x, p.goal))
elif heuristic == 2 :
    solution = astar_search(p, lambda x : h2(x, p.goal))
elif heuristic == 3 :
    solution = astar_search(p, lambda x : h3(x, p.goal))
elif heuristic == 4 :
    solution = astar_search(p, lambda x : h4(x, p.goal))

Example #3
0
import time # to count time of execution


startTime = time.time()

"""
python run_A_Star.py heuristicNo size steps
"""
arg = sys.argv

heuristic = int(arg[1])
size = int(arg[2])
steps = int(arg[3])
        

p = puzzle(size, False, None, True, steps)

    
if heuristic == 0 :
    solution = breadth_first_search(p)
elif heuristic == 1 :
    solution = astar_search(p, lambda x : h1(x, p.goal))
elif heuristic == 2 :
    solution = astar_search(p, lambda x : h2(x, p.goal))
elif heuristic == 3 :
    solution = astar_search(p, lambda x : h3(x, p.goal))
elif heuristic == 4 :
    solution = astar_search(p, lambda x : h4(x, p.goal))


solution = solution.solution()
def run_simulation(logfile=True):

    #create a fileobject for logfile
    with open("puzzle.log", 'w') as logfile:
        #intiate puzzle
        p1 = puzzle.puzzle()
        p1.board_boat("farmer")
        #p1.print_status()
        logfile.write(",".join(p1.get_status(StatusContent='header')))
        logfile.write(",".join(p1.get_status()))

        counter = 0
        while 1:
            counter = counter + 1
            #deboard 'content' if any
            c2 = p1.get_content_onboard()
            p1.deboard_boat(c2)

            #print("content is being boarded to boat")
            c1 = p1.let_the_dice_roll_boarding()
            #print(c1)
            p1.board_boat(c1)
            #p1.print_status()
            logfile.write(",".join(p1.get_status()))
            p1.toggle_boat_pos()
            #p1.print_status()
            logfile.write(",".join(p1.get_status()))
            p1.lord_of_the_flies()
            logfile.write(",".join(p1.get_status()))
            if not p1.all_is_well():
                #print("someone got killed")
                #print(counter)
                return False
                #break

            #print("content is de-boarding")
            d1 = p1.get_content_onboard()
            #print(d1)
            p1.deboard_boat(d1)
            #p1.print_status()
            logfile.write(",".join(p1.get_status()))
            #put check here about aliveness and completion
            if p1.is_it_succes():
                #print("Solved")
                #print(counter)
                return True
                #break

            if p1.board_or_not():
                #print("content is being boarded to boat from bank2")
                c1 = p1.let_the_dice_roll_boarding()
                #print(c1)
                p1.board_boat(c1)
            #p1.print_status()
            logfile.write(",".join(p1.get_status()))

            p1.toggle_boat_pos()
            p1.lord_of_the_flies()
            #p1.print_status()
            logfile.write(",".join(p1.get_status()))
            if not p1.all_is_well():
                #logfile.write(",".join(p1.get_status()))
                #print("someone got killed")
                #print(counter)
                return False
Example #5
0
import puzzle

if __name__ == "__main__":
    pieces = puzzle.puzzle("Scans/horses numbered", 380, 50)
    sortedScoreEdges = puzzle.solve(pieces)
Example #6
0
startTime = time.time()


try:
    opts, args = getopt.getopt(sys.argv[1:],"s:i:r:h:")
except getopt.GetoptError:
    print 'puzzleMain.py -i <inputFile> -h <heuristic> OR puzzleMain.py -s <size> -r <steps> -h <heuristic>' 
    #<size> := NxN - 1, <inputFile> := inputState.txt, <heuristic> := {0,...,5}, steps := {0,...99999999}
    sys.exit(2)

steps = -1    
for opt, arg in opts:
    if opt == '-i':
        inputFile = arg
        """ (size := NxN - 1, wantTextInput, wantDifficulty, steps)"""
        p = puzzle(None, True, inputFile, False, None)
    elif opt == '-s':
        size = int(arg)
    elif opt == '-r':
        steps = int(arg)
        """ (size := NxN - 1, wantTextInput, wantDifficulty, steps)"""
        p = puzzle(size, False, None, True, steps)
    elif opt == '-h':
        heuristic = int(arg)



print "\n___Initial State___"
printState(p.initial)
print
print "\n___Goal State___"
Example #7
0
from search import astar_search, breadth_first_search

import sys  # to get command-line arguments
import time  # to count time of execution

startTime = time.time()
"""
python run_A_Star.py heuristicNo size steps
"""
arg = sys.argv

heuristic = int(arg[1])
size = int(arg[2])
steps = int(arg[3])

p = puzzle(size, False, None, True, steps)

if heuristic == 0:
    solution = breadth_first_search(p)
elif heuristic == 1:
    solution = astar_search(p, lambda x: h1(x, p.goal))
elif heuristic == 2:
    solution = astar_search(p, lambda x: h2(x, p.goal))
elif heuristic == 3:
    solution = astar_search(p, lambda x: h3(x, p.goal))
elif heuristic == 4:
    solution = astar_search(p, lambda x: h4(x, p.goal))

solution = solution.solution()

print "Actions made : ", len(solution)