Ejemplo n.º 1
0
 def minimax_pruning(self):
     self.player1 = Player.RandomPlayer(self.board.boardString, 'x')
     self.player2 = Player.MinimaxAlphaBetaPlayer(self.board.boardString,
                                                  'y')
     CLOSED = []
     CLOSED.append(self.board)
     cloneBoard = Board.Board()
     cloneBoard.clone(self.board)
     while True:
         w = self.board.winner()
         if w != None:
             Misc.printCLOSED(CLOSED)
             print w
             return w
         if self.activeTurn == 'x':
             self.board.createBoard(self.player1.random().stringifyBoard())
             self.changeTurns()
         elif self.activeTurn == 'y':
             self.board.createBoard(
                 self.player2.minimaxDecisionABPruning().stringifyBoard())
             self.changeTurns()
         CLOSED.append(self.board.boardArr)
         self.board.printBoard()
         self.player1.modifyBoard(self.board.stringifyBoard())
         self.player2.modifyBoard(self.board.stringifyBoard())
Ejemplo n.º 2
0
    def random(self, N):
        CLOSED = []
        CLOSED.append(self.boardArr)
        cars = self.getCarsFromBoard()
        cloneBoard = Board()
        #for i in range(6):
            #for j in range(6):
                #bitch.boardArr[i][j] = self.boardArr[i][j]
        cloneBoard.clone(self)

        while True:
            if cloneBoard.isDone() == True:
                misc.printCLOSED(CLOSED)
                return
            if len(CLOSED) == N:
                misc.printCLOSED(CLOSED)
                return

            nextBoards = cloneBoard.next()
            boardIndex = randint(0,len(nextBoards)-1)
            nextBoard = nextBoards[boardIndex]
            if nextBoard not in CLOSED:
                CLOSED.append(nextBoard)
            cloneBoard.boardArr = nextBoard
        

        # The Code commented out underneath is for me to remember what an idiot i am.
            '''
Ejemplo n.º 3
0
command = str(sys.argv[1])  # storing the command

board = Board.Board()

if len(sys.argv
       ) > 2:  # checking whether there's the optional argument for input
    boardString = str(sys.argv[2])  # storing the argument into an input string
    board.createBoard(boardString)

if command == "print":
    board.printBoard()
elif command == "done":
    print board.isDone()
elif command == "next":
    nextBoards = board.next()
    misc.printCLOSED(nextBoards)
elif command == "random":
    board.random(10)
elif command == "bfs":
    board.bfs()
elif command == "astar":
    board.astar()
elif command == "test":
    #print misc.findAll(board.boardArr, 'q')
    board.next_for_car('o')
    #board.moveCar('q', 'up', 2)
    #print misc.find(board.boardArr, 'p')
    #print misc.findAll(board.boardArr, 'p')
    #board.moveCar('p','right',2)
Ejemplo n.º 4
0
 def printPath(self):
     boardArrs = []
     for board in self.boards:
         boardArrs.append(board.boardArr)
     misc.printCLOSED(boardArrs) #or boards.boardArr