def load_dataset(): print "start loading go dataset files" # sgf에서 plays 추출 file_names = get_file_names(GO_FOLDER, POSTFIX) for name in file_names: plays = Plays() plays.load_from_sgf(GO_FOLDER + "/" + name) splitted_name = name.split("_") play_num = int(splitted_name[1]) features = FeatureMap(plays, play_num) f = open( OTHER_TRAIN_FOLDER + "/" + name + "_" + str(play_num) + "_x" + ".csv", 'w') txt = "" for feature in features.input_planes_valuenet: for rows in feature: for r in range(0, len(rows)): if r == len(rows) - 1: txt += str(rows[r]) else: txt += str(rows[r]) + "," txt += "\n" txt += "\n" f.write(txt) f.close() f = open( OTHER_TRAIN_FOLDER + "/" + name + "_" + str(play_num) + "_y" + ".csv", 'w') cur_label = splitted_name[2][0] f.write(cur_label) f.close() print "finish.."
def getargumenttopredict(self): #print 'getargumenttopredict' #print 'getargumenttopredict : len(self.move_history) : ' + str(len(self.move_history)) if len(self.move_history) == 0: #print 'len(self.move_history) == 0' return self.first_state() s = "" i = 1 playlist = [] for move in self.move_history: if i % 2 == 1: playlist.append(('b', (move[0] - 1, move[1] - 1))) else: playlist.append(('w', (move[0] - 1, move[1] - 1))) i = i + 1 s = None try: plays = Plays(playlist) features = FeatureMap(plays, len(plays)) #s = features.input_planes # <-- use this value s = features.input_planes_policynet # <-- use this value except Exception as e: print "Unexpected error in getargumenttopredict : ", sys.exc_info( )[0] print e pass return s
def load_dataset(): print "start" num_saves = 0 file_names = get_file_names(SGF_FOLDER, POSTFIX) for name in file_names: plays = Plays() plays.load_from_sgf(SGF_FOLDER+"/"+name) if plays.total_nonpass_plays < 10: continue for play_num in range(0, plays.total_plays+1): features = FeatureMap(plays, play_num) if type(features) is NoneType: continue f = open(SAVE_FOLDER+"/"+name+"_"+str(play_num)+"_x"+".csv", 'w') txt = "" inputs = features.input_planes_policynet for feature in inputs: for rows in feature: for r in range(0, len(rows)): if r == len(rows)-1: txt += str(rows[r]) else: txt += str(rows[r]) + "," txt+="\n" txt+="\n" f.write(txt) f.close() txt = "" f = open(SAVE_FOLDER+"/"+name+"_"+str(play_num)+"_y"+".csv", 'w') for rows in features.label: for r in range(0, len(rows)): r_value = rows[r] if r == len(rows)-1: txt += str(r_value) else: txt += str(r_value) + "," txt+="\n" f.write(txt) f.close() num_saves += 1 if num_saves % 100 == 0: print "finish "+str(num_saves)+" sgf files.." print "finish all.."
def getargumenttopredictvalue(self): #print 'getargumenttopredictvalue' #print 'getargumenttopredictvalue : len(self.move_history) : ' + str(len(self.move_history)) if len(self.move_history) == 0: #print 'len(self.move_history) == 0' return self.first_statevalue() #print self.move_history s = "" i = 1 playlist = [] for move in self.move_history: if i % 2 == 1: playlist.append(('b', (move[0] - 1, move[1] - 1))) else: playlist.append(('w', (move[0] - 1, move[1] - 1))) i = i + 1 s = None try: #print 'ZZ01' plays = Plays(playlist) #print 'ZZ02' features = FeatureMap(plays, len(plays)) #print 'ZZ03' s = features.input_planes_valuenet # <-- use this value #print 'ZZ04' #print_features(s) #pprint.pprint(s) #print 'ZZ05' except Exception as e: print "Unexpected error in getargumenttopredictvalue : ", sys.exc_info( )[0] print e #print "Unexpected error in getargumenttopredictvalue : ", sys.exc_info()[0] pass return s
game.make_move((2, 2)) print str(game.current_board) #make argument to call model.predict i = 1 playlist = [] for move in game.move_history: if i%2 == 1: playlist.append(('b', (move[0]-1, move[1]-1))) else: playlist.append(('w', (move[0]-1, move[1]-1))) i = i + 1 plays = Plays(playlist) features = FeatureMap(plays, len(plays)) print "first : " print features.input_planes # <-- use this value #another way print "second : " print game.getargumenttopredict() #mcts test. reference only interface. inner logic will be modified. root = StateNode(None, GoState(game)) mcts = MCTS(tree_policy=UCB1(c=1.41), default_policy=evaluation, backup=monte_carlo) best_action = mcts(root)
start = True m = 0 while m < rand_move_number: #make argument to call model.predict playlist = [] n = 1 for move in game.move_history: if n % 2 == 1: playlist.append(('b', (move[0] - 1, move[1] - 1))) else: playlist.append(('w', (move[0] - 1, move[1] - 1))) n += 1 plays = Plays(playlist) features = FeatureMap(plays, len(playlist)) X = features.input_planes_policynet pred_pos = sl_policy.predict(np.asarray([X], dtype=np.float)) tmp_pred_pos = np.argmax(pred_pos) col, row = get_state(tmp_pred_pos) while not game.legal_move((col, row)): pred_pos = np.delete(pred_pos, tmp_pred_pos) if len(pred_pos) == 0: start = False break tmp_pred_pos = np.argmax(pred_pos) col, row = get_state(tmp_pred_pos)