def multiplayer_minimax_search(miniMaxGame, d=4, cutoff_test=None, eval_fn=None): #get the initial state for all subsequent moves by us initialState = miniMaxGame.initial #action list that is used to prime the dfs actionList = miniMaxGame.actions(miniMaxGame.initial, True) print "actionList: " + str(actionList) #create pool to run each action in parallel pool = Pool() #get all the results for the actions. this is a blocking call actionResult = pool.map(performActionAndSendStateIntoMultiPlayerMaxVal, itertools.izip(actionList, itertools.repeat(miniMaxGame), itertools.repeat(initialState), itertools.repeat(d))) pool.close() pool.terminate() #setup initial values for the max val and action maxAction = actionResult[0][0] maxScore = actionResult[0][1] #go over all results and pick out the best one for result in actionResult: thisScore = result[1] if thisScore > maxScore: maxScore = thisScore maxAction = result[0] print "maxAction: " + str(maxAction) + " score: " + str(maxScore) return maxAction
def Get_data(self): query = 'select * from edid_semantics' print 'query:' + query self.cursor.execute(query) desc = self.cursor.description return [dict(itertools.izip([col[0] for col in desc], row)) for row in self.cursor.fetchall()]
def _test_roundrip_of(self, block): """ Serialize to and deserialize from xml then check that the result == block. """ restored = self.parse_xml_to_block(self.export_xml_for_block(block)) self._assert_xthing_equal(block, restored) for first, second in itertools.izip(self.runtime.get_asides(block), self.runtime.get_asides(restored)): self._assert_xthing_equal(first, second)
def get_diff(source_contents, target_contents): source = source_contents.split('\n') target = target_contents.split('\n') line_number = 1 for source_line, target_line in itertools.izip(source, target): source_length = len(source_line) target_length = len(target_line) calc_matrix = zeros((source_length + 1, target_length + 1)) sequence_length = calculate_sequence_length(calc_matrix, source_length + 1, target_length + 1, source_line, target_line) if int(sequence_length) != source_length: print 'Line Number : ' + str(line_number) print colored(' - ' + source_line, 'red') print colored(' + ' + target_line, 'green') print '----------------------------------------------------------' else: print 'Line Number : ' + str(line_number) + ' : No Change' print '----------------------------------------------------------' line_number += 1 # Handle the remaining lines if line_number > len(source): remaining_lines = target[line_number-1:] for line in remaining_lines: print 'Line Number : ' + str(line_number) print colored(' - ' + line, 'red') print '----------------------------------------------------------' line_number += 1 else: remaining_lines = source[line_number-1:] for line in remaining_lines: print 'Line Number : ' + str(line_number) print colored(' + ' + line, 'green') print '----------------------------------------------------------' line_number += 1
def multiplayer_minimax_search(miniMaxGame, d=4, cutoff_test=None, eval_fn=None): #get the initial state for all subsequent moves by us initialState = miniMaxGame.initial #action list that is used to prime the dfs actionList = miniMaxGame.actions(miniMaxGame.initial, True) print "actionList: " + str(actionList) #create pool to run each action in parallel pool = Pool() #get all the results for the actions. this is a blocking call actionResult = pool.map( performActionAndSendStateIntoMultiPlayerMaxVal, itertools.izip(actionList, itertools.repeat(miniMaxGame), itertools.repeat(initialState), itertools.repeat(d))) pool.close() pool.terminate() #setup initial values for the max val and action maxAction = actionResult[0][0] maxScore = actionResult[0][1] #go over all results and pick out the best one for result in actionResult: thisScore = result[1] if thisScore > maxScore: maxScore = thisScore maxAction = result[0] print "maxAction: " + str(maxAction) + " score: " + str(maxScore) return maxAction
def main(): output_combinations_table() key = [ lambda : key_by_space(9, 0), lambda : key_by_space(8, 1), lambda : key_by_space(0, 2), lambda : key_by_space(4, 3), lambda : key_by_space(9, 4), lambda : key_by_space(6, 5), lambda : key_by_space(7, 6), lambda : key_by_guess(4, 7, '\''), #??? lambda : key_by_space(2, 8), lambda : key_by_space(6, 9), lambda : key_by_space(10, 10), lambda : key_by_space(1, 11), lambda : key_by_space(9, 12), lambda : key_by_space(6, 13), lambda : key_by_space(4, 14), lambda : key_by_space(8, 15), lambda : key_by_space(8, 16), lambda : key_by_space(4, 17), lambda : key_by_space(10, 18), lambda : key_by_space(6, 19), lambda : key_by_space(7, 20), lambda : key_by_space(4, 21), lambda : key_by_space(6, 22), lambda : key_by_space(4, 23), lambda : key_by_space(0, 24), lambda : key_by_guess(1, 25, 'y'), lambda : key_by_space(7, 26), lambda : key_by_space(10, 27), lambda : key_by_space(3, 28), lambda : key_by_space(9, 29), lambda : key_by_space(7, 30), lambda : key_by_space(1, 31), lambda : key_by_space(0, 32), lambda : key_by_space(10, 33), lambda : key_by_space(8, 34), lambda : key_by_space(10, 35), lambda : key_by_space(9, 36), lambda : key_by_space(5, 37), lambda : key_by_space(7, 38), lambda : key_by_space(1, 39), lambda : key_by_space(0, 40), lambda : key_by_space(8, 41), lambda : key_by_space(5, 42), lambda : key_by_guess(3, 43, 'n'), lambda : key_by_space(4, 44), lambda : key_by_guess(7, 45, 'y'), lambda : key_by_space(7, 46), lambda : key_by_guess(10, 47, 'e'), lambda : key_by_guess(10, 48, 'r'), lambda : key_by_space(7, 49), lambda : key_by_guess(3, 50, 'i'), lambda : key_by_guess(3, 51, 't'), lambda : key_by_guess(3, 52, 'h'), lambda : key_by_guess(3, 53, 'm'), lambda : key_by_space(4, 54), lambda : key_by_space(1, 55), lambda : key_by_space(10, 56), lambda : key_by_space(1, 57), lambda : key_by_space(0, 58), lambda : key_by_space(9, 59), lambda : key_by_space(3, 60), lambda : key_by_space(7, 61), lambda : key_by_guess(0, 62, 'o'), lambda : key_by_space(0, 63), lambda : key_by_space(10, 64), lambda : key_by_guess(6, 65, 't'), lambda : key_by_space(5, 66), lambda : key_by_guess(10, 67, 'y'), lambda : key_by_space(10, 68), lambda : key_by_space(7, 69), lambda : key_by_space(1, 70), lambda : key_by_space(3, 71), lambda : key_by_space(2, 72), lambda : key_by_space(1, 73), lambda : key_by_space(0, 74), lambda : key_by_guess(10, 75, 'h'), lambda : key_by_guess(10, 76, 'a'), lambda : key_by_guess(10, 77, 'n'), lambda : key_by_space(10, 78), lambda : key_by_guess(3, 79, 'e'), lambda : key_by_guess(3, 80, 'x'), lambda : key_by_guess(3, 81, 't'), lambda : key_by_guess(10, 82, 'e'), lambda : key_by_guess(6, 83, 'c'), lambda : key_by_guess(6, 84, 'e'), # lambda : key_by_guess(6, 68, 't'), ] for i, s in enumerate(MSGS): print '%2d: %s' % (i + 1, ''.join([strxor(k(), ch) for k, ch in itertools.izip(key, s.decode('hex'))]))