def main(args):

    flag = args.flag
    if not flag or flag == 1:
        #Iterative Deepening Search
        tic = time.clock()
        gameItrObject = pegSolitaireUtils.game(args.input)
        if False == search.ItrDeepSearch(gameItrObject):
            gameItrObject.trace = ['GOAL NOT FOUND']

        toc = time.clock()
        timeItr = toc - tic

        print "Itr Deepening Search:"
        print "Execution Time: " + str(timeItr)
        print "Nodes Expanded: " + str(gameItrObject.nodesExpanded)
        print "Trace: " + str(gameItrObject.trace) + '\n'

    if not flag or flag == 2:
        #Astar with first heuristic
        tic = time.clock()
        gameAOneObject = pegSolitaireUtils.game(args.input)
        if False == search.aStarOne(gameAOneObject):
            print("false")
            gameAOneObject.trace = ['GOAL NOT FOUND']

        toc = time.clock()
        timeAOne = toc - tic

        print "Astar One Search:"
        print "Execution Time: " + str(timeAOne)
        print "Nodes Expanded: " + str(gameAOneObject.nodesExpanded)
        print "Trace: " + str(gameAOneObject.trace) + '\n'

    if not flag or flag == 3:
        #AStar with second Heuristic
        tic = time.clock()
        gameATwoObject = pegSolitaireUtils.game(args.input)
        if False == search.aStarTwo(gameATwoObject):
            gameATwoObject.trace = ['GOAL NOT FOUND']

        toc = time.clock()
        timeATwo = toc - tic

        print "Astar Two Search:"
        print "Execution Time: " + str(timeATwo)
        print "Nodes Expanded: " + str(gameATwoObject.nodesExpanded)
        print "Trace: " + str(gameATwoObject.trace)
Example #2
0
def main(args):
    flag = args.flag
    if not flag or flag == 1:
		#Iterative Deepening Search
		tic = time.clock()
		gameItrObject = pegSolitaireUtils.game(args.input)
		search.ItrDeepSearch(gameItrObject)
		#set = search.ItrDeepSearch(gameItrObject)
		toc = time.clock()
		timeItr = toc - tic

		print "Itr Deepening Search:"
		print "Execution Time: " + str(timeItr)
		print "Nodes Expanded: " + str(gameItrObject.nodesExpanded)
		print "Trace: " + str(gameItrObject.trace)+ '\n'
		#print "Nodes Expanded: " + str(set[1])
		#print "Trace: " + str(set[0])+ '\n'

    if not flag or flag == 2:
        #Astar with first heuristic
        tic = time.clock()
        gameAOneObject = pegSolitaireUtils.game(args.input)
        search.aStarOne(gameAOneObject)
        toc = time.clock()
        timeAOne = toc- tic

        print "Astar One Search:"
        print "Execution Time: " + str(timeAOne)
        print "Nodes Expanded: " + str(gameAOneObject.nodesExpanded)
        print "Trace: " + str(gameAOneObject.trace) + '\n'


    if not flag or flag == 3:
        #AStar with second Heuristic
        tic = time.clock()
        gameATwoObject = pegSolitaireUtils.game(args.input)
        search.aStarTwo(gameATwoObject)
        toc = time.clock()
        timeATwo = toc - tic

        print "Astar Two Search:"
        print "Execution Time: " + str(timeATwo)
        print "Nodes Expanded: " + str(gameATwoObject.nodesExpanded)
        print "Trace: " + str(gameATwoObject.trace)
Example #3
0
def main(args):

    flag = args.flag
    if not flag or flag == 1:
        #Iterative Deepening Search
        tic = time.time()
        gameItrObject = pegSolitaireUtils.game(args.input)
        search.ItrDeepSearch(gameItrObject)
        toc = time.time()
        timeItr = toc - tic

        print("Itr Deepening Search:")
        print("Execution Time: " + str(timeItr))
        print("Nodes Expanded: " + str(gameItrObject.nodesExpanded))
        print("Trace: " + str(gameItrObject.trace) + '\n')

    if not flag or flag == 2:
        #Astar with first heuristic
        tic = time.time()
        gameAOneObject = pegSolitaireUtils.game(args.input)
        search.aStarOne(gameAOneObject)
        toc = time.time()
        timeAOne = toc - tic

        print("Astar One Search:")
        print("Execution Time: " + str(timeAOne))
        print("Nodes Expanded: " + str(gameAOneObject.nodesExpanded))
        print("Trace: " + str(gameAOneObject.trace) + '\n')

    if not flag or flag == 3:
        #AStar with second Heuristic
        tic = time.time()
        gameATwoObject = pegSolitaireUtils.game(args.input)
        search.aStarTwo(gameATwoObject)
        toc = time.time()
        timeATwo = toc - tic

        print("Astar Two Search:")
        print("Execution Time: " + str(timeATwo))
        print("Nodes Expanded: " + str(gameATwoObject.nodesExpanded))
        print("Trace: " + str(gameATwoObject.trace))
Example #4
0
def depthLimitedSearch(pegSolitaireObject, maxDepth):
    #Check if the current state is goal state or not
    if pegSolitaireUtils.isGoalState(pegSolitaireObject.gameState):
        return True
    
    #If current state is already explored, it will not explore it furthur and return
    if pegSolitaireUtils.isAlreadyExplored(pegSolitaireObject.gameState): 
        return
    
    #if depth reached is zero, goal can't be find with these moves and it backtracks
    if maxDepth == 0:
        return
    
    #Check for all pegs in the peg board in all direction for next game state
    for i in xrange(7):
        for j in xrange(7):
            if pegSolitaireObject.gameState[i][j] == 1: 
                for direction in all_directions:
                    #check valid move
                    if pegSolitaireObject.is_validMove((i,j),direction):
                        #Save game state in another state variable, so that we can backtrack if our next move eventually fails
                        parentObject = pegSolitaireUtils.game("game.txt")
                        parentObject.gameState = pegSolitaireUtils.copyGameState(pegSolitaireObject)
                        #Get next valid move state
                        pegSolitaireObject.getNextState((i,j),direction)
    
                        #Recursively call function with next valid move and depth-1
                        result = depthLimitedSearch(pegSolitaireObject, maxDepth-1)
                        
                        #If the above exploration fails it will return to its initial game state (backtrack)
                        if result == None:
                            pegSolitaireUtils.restoreInitialState(pegSolitaireObject,parentObject.gameState)
                        #If Goal state is reached, it computes the trace and return true
                        if result == True:
                            #Get next move position for computing trace
                            newpos = pegSolitaireObject.getNextPosition((i,j), direction)
                            pegSolitaireObject.trace.insert(0,newpos)
                            pegSolitaireObject.trace.insert(0,(i,j))
                            return True

    return
Example #5
0
 def setUpClass(cls):
     game = pegSolitaireUtils.game('./game.txt')
     print 'Testing with game:'
     print game
Example #6
0
 def setUp(self):
     self.game = pegSolitaireUtils.game('./game.txt')
import argparse
import time
import search
import config
import pegSolitaireUtils
import readGame

tic = time.clock()
gameItrObject = pegSolitaireUtils.game('./original.txt')
#gameItrObject = pegSolitaireUtils.game('./game.txt')
search.ItrDeepSearch(gameItrObject)
search.aStarOne(gameItrObject)
search.aStarTwo(gameItrObject)
toc = time.clock()
toc = time.clock()
timeItr = toc - tic

print "Itr Deepening Search:"
print "Execution Time: " + str(timeItr)
print "Nodes Expanded: " + str(gameItrObject.nodesExpanded)
print "Trace: " + str(gameItrObject.trace) + '\n'
import argparse
import time
import search
import config
import pegSolitaireUtils
import readGame

tic = time.clock()
gameItrObject = pegSolitaireUtils.game('./original.txt')
#gameItrObject = pegSolitaireUtils.game('./game.txt')
search.ItrDeepSearch(gameItrObject)
search.aStarOne(gameItrObject)
search.aStarTwo(gameItrObject)
toc = time.clock()
toc = time.clock()
timeItr = toc - tic

print "Itr Deepening Search:"
print "Execution Time: " + str(timeItr)
print "Nodes Expanded: " + str(gameItrObject.nodesExpanded)
print "Trace: " + str(gameItrObject.trace)+ '\n'