def doMove(self, current_board, player): board = copy.deepcopy(current_board) if player == 1: opponent = 2 else: opponent = 1 node = Node(board, "", 0, player) node = self.statespace( node, 0, player, player, opponent); bestscore = -100 wins_score = -1 move = 0 print "New Round" for child in node.childs: print "Child value=", child.value, "score=", child.wins_score if child.value > bestscore: if rules.isMoveLegal(board, child.board.last_move): bestscore = child.value move = child.board.last_move elif child.value == bestscore: if child.wins_score > wins_score: wins_score = child.wins_score move = child.board.last_move return move
def doMove(self, current_board, player): board = copy.deepcopy(current_board) # Build tree searchtree = [] node = Node(board, "", 0, player) node = self.statespace(node, 0, player) print node print node.value bestscore = -10 move = 0 for child in node.childs: print "Child value=", child.value if child.value > bestscore: if rules.isMoveLegal(board, child.board.last_move): bestscore = child.value move = child.board.last_move return move #while 1: # for move in range(7): #print "move", move # if rules.isMoveLegal(board, move): # searchtree.append(self.makeBoard(move, board, player)) # for state in searchtree: # for move in range(7): # if rules.isMoveLegal(board, move): # state.append(self.makeBoard(move, board, player)) # print searchtree return 0
def setmove(self, trigger, event, number): if rules.isMoveLegal(self.board, number): self.move = number return widget.DONE
def listMoves(self, board, player): options = [] for move in range(7): if rules.isMoveLegal(board, move): options.append(self.makeBoard(move, board, player)) return options
def doMove(self, board, player): while 1: move = int(random() * 7) if rules.isMoveLegal(board, move): return move