def getroomname(rid): conn = getconn() cursor = conn.cursor() cursor.execute('select rname from roominfo where rid=?', (rid, )) row = cursor.fetchone() conn.close() return row[0]
def getAreaRooms(area, exp_depth=2): arooms = [] brooms = [] conn = getconn() cursor = conn.cursor() cursor.execute( 'SELECT t2.rid FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from v_traversal_roominfo) t2 where t1.area=t2.tarea and t1.cname=?', (area.decode("utf8"), )) rows = cursor.fetchall() for row in rows: arooms.append(row[0]) cursor.execute( 'SELECT t2.rid FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from v_traversal_roominfo) t2,v_roomrel_nextarea t3 where t2.rid=t3.rid and t1.area=t2.tarea and t3.next_area<>? and t1.cname=?', (area.decode("utf8"), area.decode("utf8"))) rows = cursor.fetchall() conn.close() for row in rows: if row[0] not in brooms: brooms.append(row[0]) if len(brooms) > 0: nodes = [] for rid in brooms: p = MudRoomSearchProblem(rid, None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p, nodes, exp_depth) for node in nodes: if node.status not in arooms: arooms.append(node.status) return (arooms, brooms)
def getTCSuccessors(self, state): """ Returns successor states, the actions they require, and a cost of 1. As noted in search.py: For a given state, this should return a list of triples, (successor, action, stepCost), where 'successor' is a successor to the current state, 'action' is the action required to get there, and 'stepCost' is the incremental cost of expanding to that successor """ successors = [] #get from roomrel table conn = getconn() cursor = conn.cursor() cursor.execute( 'select rid,nextrid,exit,bak1,bak2,cost from roomrel where rel_type="normal" and rid=?', (state, )) rows = cursor.fetchall() conn.close() for row in rows: nextState = row[1] action = getTCaction(row[2], row[3], row[4]) if row[5] is None or row[5] == "": cost = 1 else: cost = int(row[5]) successors.append((nextState, action, cost)) return successors
def loc_split(loc): conn = getconn() cursor = conn.cursor() cursor.execute('select cname from area_name_map') rows = cursor.fetchall() for row in rows: regexp = r'^' + row[0].encode("utf8") + '(.*)' if re.search(regexp, loc): s = re.search(regexp, loc) area = row[0].encode("utf8") rname = s.group(1) if len(rname) > 0: cursor.execute( 'SELECT count(1) FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from roominfo) t2 where t1.area=t2.tarea and t1.cname=? and t2.rname=?', (area.decode("utf8"), rname.decode("utf8"))) else: cursor.execute( 'SELECT count(1) FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from roominfo) t2 where t1.area=t2.tarea and t1.cname=?', (area.decode("utf8"), )) row1 = cursor.fetchone() if int(row1[0]) == 0: continue else: conn.close() return (area, rname) conn.close() return (None, None)
def get_room_list(area, rname): ret = [] if area is None: return ret conn = getconn() cursor = conn.cursor() (arooms, brooms) = getAreaRooms(area) if len(rname) > 0: cursor.execute( 'SELECT rid,rname from roominfo where rname=? and area=?', (rname.decode("utf8"), area.decode("utf8"))) rows = cursor.fetchall() for row in rows: ret.append(row[0]) cursor.execute('SELECT rid,rname from roominfo where rname=?', (rname.decode("utf8"), )) rows = cursor.fetchall() conn.close() for row in rows: if (row[0] in arooms) and (row[0] not in ret): ret.append(row[0]) else: ret = arooms return (ret, arooms, brooms)
def loc_split(loc): conn = getconn() cursor = conn.cursor() cursor.execute('select cname from area_name_map') rows = cursor.fetchall() conn.close() for row in rows: regexp = r'^' + row[0].encode("utf8") + '(.*)' if re.search(regexp, loc): s = re.search(regexp, loc) return (row[0].encode("utf8"), s.group(1)) return (None, None)
def main(args): rid = args[1].decode("gb18030") moves = args[2].decode("gb18030").encode("utf8").split("|||") conn = getconn() cursor = conn.cursor() for mymove in moves[:-1]: cursor.execute('select rid from roomrel where nextrid=? and exit=?', (rid, mymove.decode("utf8"))) row = cursor.fetchone() if row is not None: rid = row[0] conn.close() print rid.encode("gb18030")
def main(args): # area = "xkt;ddj;em;qfa;fds;fz;gb;gm;ha;ms;xt;gjc;gw;yinz;gy;hanz;hz;hmy;hhh;hyd;bs;hs;cll;xc;hb;hb1;hb2;hb3;hb4;hn1;hn2;hn3;hn4;jx;jyg;jmg;jz;jy;jzh;km;fd;lld;llx;lj;dzt;lz;lxc;ljz;ly;ll;mt;mz;mlb;mlx;mj;mgk;mr;mrf;nc;ny;px;pyh;py;qlc;qy;qhb;qhn;qf;qq;qzh;qz;ry;rbz;rz;ssb;lvz;shg;fzl;sl;sld;fengd;sy;skf;sdb;sdn;sz;taih;tais;dzf;tgk;th;tyc;ty;tdh;tls;tzf;tz;tx;wat;wjg;gd;wl;yb;wd;wdc;wm;wys;xyz;xy;xf;xz;xiny;xx;txg;xch;xs;ys;yzw;yz;yiz;yg;ywm;yy;zp;zjk;zz;ca;jb1;jb2;jb3;jb4;jn1;jn2;jn3;jn4;zj;zx;zf;tdf;xh;hsz;jnqz;hzbs;zuo;ct;qiu;kf;bofu;fm;fh;ht;tf;tt;hst;cym;scm;zjc;sd;kd;jk;lanz;huangz" # cname="大轮谢客亭;都大锦;峨嵋;峨嵋千佛庵;发呆室;福州;丐帮;古墓;古墓河岸;古墓密室;古墓小厅;挂剑祠;关外;归云隐者;归云庄;汉中;杭州;黑木崖;红花会;胡一刀;花园别墅区;华山;华山苍龙岭;华山村;淮北;黄河渡口北1;黄河渡口北2;黄河渡口北3;黄河渡口北4;黄河渡口南1;黄河渡口南2;黄河渡口南3;黄河渡口南4;嘉兴;嘉峪关;剑门关;江州;晋阳;荆州;昆明;琅缳福地;老林东;老林西;灵鹫;灵鹫独尊厅;灵州;凌霄城;陆家庄;洛阳;绿柳山庄;曼陀山庄;梅庄;苗岭北;苗岭西;明教;莫高窟;慕容;慕容复;南昌;南阳;平西王府;鄱阳湖;濮阳;麒麟村;琴韵小筑;青海湖北;青海湖南;曲埠;曲清;全真教;泉州;日月神教;荣宝斋;汝州;杀手帮;沙漠绿洲;山海关;少林方丈楼;少林寺;神龙岛;神龙峰顶;神龙山腰;史可法;蜀道北;蜀道南;苏州;太湖;泰山;泰山岱宗坊;塘沽口;桃花岛;桃园村;桃源;天地会;天龙寺;天柱峰;铁掌峰;听香水榭;万安塔;万劫谷;无量谷底;无量山;无量玉璧;武当;武当村;武庙;武夷山;戏园子;襄阳;萧峰;小镇;信阳;星宿;星宿天秀宫;许昌;雪山派;牙山;燕子坞;扬州;驿站;瑛姑;岳王墓;岳阳;赞普;张家口;张志;长安;长江渡口北1;长江渡口北2;长江渡口北3;长江渡口北4;长江渡口南1;长江渡口南2;长江渡口南3;长江渡口南4;镇江;朱熹;庄府;提督府;西湖;韩世忠;江南钱庄;杭州别墅;昌隆镖局;朝廷;裘千丈;康亲王府;钵夫;飞马镖局;飞虎镖局;后堂;天福镖局;丹陛桥;洪水坛;朝阳门;神策门;端门;树洞内部;客店;建康府;兰州;湟中" # ctname="谢客亭;龙门镖局;玉女池;千佛庵大殿;发呆室;福威镖局;土地庙;断龙石;河岸;密室;小厅;挂剑祠;集市;隐者居;归云亭;汉中;大理寺;成德殿;杭州分舵大门;高粱地;花园别墅区;书房;苍龙岭;打谷场;淮北;无;风陵渡;无;无;无;孟津渡;无;无;嘉兴城;嘉峪关;剑门关;韩家;萧府;荆州;神威镖局;琅缳福地;老林尽头;老林边缘;百丈涧;独尊厅大门;皇宫大门;凌霄大厅;陆家庄;洛阳中心广场;绿柳山庄大门;小桥;梅庄天井;无;无;半山门;莫高窟;湖边;春来茶馆;白家;南阳城;平西王府大门;鄱阳湖边;濮阳;岳飞家;琴韵小居;黄羊滩;无;孔庙;荣昌交易行;崇玄台;泉州港;小村庄;荣宝斋;汝州城;万纶台;沙漠绿洲;山海关南门;方丈楼;少林寺;海滩;峰顶;小回廊;城北军营;无;无;宝带桥;太湖边;南天门;岱宗坊;塘沽口;海港;桃园小路;桃源驿站;侧厅;瑞鹤门;天柱峰下;小亭;听香水榭;万安塔;万劫谷;谷底;崖间古松;无量玉璧;武当广场;武当山门;武庙;武夷山路;戏园子;襄阳当铺;望星楼二层;小镇;镇淮桥;巨岩;天秀宫;许昌城;桥头;牙山湾中心;燕子坞大门;中央广场;驿站;黑沼小屋;墓前广场;南门内大街;赞普广场;大境门;荆西镖局;朱雀门;扬子津;无;无;无;无;采石矶;无;无;梦溪园;岳麓书院;庄府大门;提督府正门;孤山;大厅;江南钱庄;无;昌隆镖局;厅堂;望江亭;王府大门;殿前广场;飞马镖局;飞虎镖局;后堂;天福镖局;丹陛桥;洪水坛;朝阳门;神策门;端门;树洞内部;客店;中城;府前广场;宫城" # area_list = area.split(";") # cname_list = cname.split(";") # ctname_list = ctname.split(";") # size = len(area_list) # conn = getconn() # cursor = conn.cursor() # for i in range(size): # cursor.execute('insert into areainfo(aid,xy_ename,cname,ct_cname) values(?,?,?,?)',(area_list[i].decode("utf8"),area_list[i].decode("utf8"),cname_list[i].decode("utf8"),ctname_list[i].decode("utf8"))) # conn.commit() # conn.close() words = "" conn = getconn() cursor = conn.cursor()
def mhdHeuristic(state, problem=None): goal_rid = problem.goal conn = getconn() cursor = conn.cursor() cursor.execute('select xofct,yofct,zofct from roominfo where rid=?', (state, )) row = cursor.fetchone() s_xofct = row[0] s_yofct = row[1] s_zofct = row[2] cursor.execute('select xofct,yofct,zofct from roominfo where rid=?', (goal_rid, )) row = cursor.fetchone() g_xofct = row[0] g_yofct = row[1] g_zofct = row[2] conn.close() return abs(s_xofct - g_xofct) + abs(s_yofct - g_yofct) + abs(s_zofct - g_zofct)
def get_room_list(area, rname): ret = [] if area is None: return ret conn = getconn() cursor = conn.cursor() if len(rname) > 0: cursor.execute( 'SELECT t2.rid FROM area_name_map t1,roominfo t2 where t1.area=t2.area and t1.cname=? and t2.rname=?', (area.decode("utf8"), rname.decode("utf8"))) else: cursor.execute( 'SELECT t2.rid FROM area_name_map t1,roominfo t2 where t1.area=t2.area and t1.cname=?', (area.decode("utf8"), )) rows = cursor.fetchall() conn.close() for row in rows: ret.append(row[0]) return ret
def main(args): rid = args[1].decode("gb18030") conn = getconn() cursor = conn.cursor() cursor.execute( 'select area,rname,rdesc,exitsdesc from roominfo where rid=?', (rid, )) row = cursor.fetchone() area = row[0].encode("utf8") roomname = row[1].encode("utf8") roomdesc = row[2].encode("utf8") exitsdesc = row[3].encode("utf8") conn.close() p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() exitsdesc = ','.join(elist) s1 = area + roomname + roomdesc + exitsdesc bakid = md5digest(s1) print bakid
def get_room_list_byRName(ref_rid, rname): depth = 15 nodes = [] p = MudRoomSearchProblem(ref_rid, None) nodes = breadthFirstTraversalList(p, nodes, depth) conn = getconn() cursor = conn.cursor() cursor.execute('SELECT rid from roominfo where rname=?', (rname.decode("utf8"), )) rows = cursor.fetchall() conn.close() if len(rows) == 0: return [] rids = [] for n in nodes: for row in rows: if row[0] == n.status: rids.append(n.status) return rids
def main(args): test = PinYin() test.load_word() conn = getconn() cursor = conn.cursor() cursor.execute('select rname,rid from roominfo where py_name is null') # cursor.execute('select cname,area from area_name_map where py_name is null') rows = cursor.fetchall() for row in rows: myword = row[0].encode("utf8") pylist = test.hanzi2pinyin(string=myword) pystr = pylist[0] for w in pylist[1:]: pystr = pystr + w[0] # cursor.execute('update area_name_map set py_name=? where cname=? and area=?',(pystr,row[0],row[1])) cursor.execute('update roominfo set py_name=? where rid=?', (pystr, row[1])) conn.commit() conn.close()
def main(args): #lines = "||| 后堂 ||| | ||| 左配殿----三清殿----右配殿 ||| | ||| 武当广场 ||||||三清殿 - [门派]|||||| 这里是凌霄宫的三清殿,是武当派会客的地点。供着元始|||天尊、太上道君和天上老君的神像,香案上香烟缭绕。靠墙放|||着几张太师椅,地上放着几个蒲团。东西两侧是走廊,南边是|||练武的广场,北边是后院。|||||| 这里明显的出口是 north、south、east 和 west。|||||| 神武功德录(Board) [ 115 张留言,115 张未读 ]||| 武当派道长 谷虚道长(Guxu daozhang)||| 武当派第三代弟子 中年道长(Zhongnian daozhang)||| 一流高手 武当派真人「武当首侠」宋远桥(Songyuanqiao)|||>".split("|||") lines = args[1].decode("gb18030").encode("utf8").split("|||") #lines = "||| 星宿海 ||| | ||| 星宿海 ||| ↓ ||| 湖泊 ||||||星宿海 - |||||| 这里是星宿海边。说是海,其实是片湖泊和沼泽,地形十分险恶。|||东面石壁上一道裂缝通到一个山洞。||| 「初春」: 太阳无奈地缓缓挂向西边的才露新芽的树梢。|||||| 这里明显的出口是north 和 southup。|||||| 垂头菊(Flower)||| 星宿派鼓手(Gushou)||| 星宿派号手(Haoshou)||| 钹手首领(Boshou shouling)||| 星宿派邪士「星宿派大师兄」摘星子(Zhaixing zi)||| 星宿派钹手(Boshou)|||> ".split("|||") roomname = "" roomdesc = "" step = 0 for i, line in enumerate(lines): if step == 0 and re.search(r"^(\S.*?) -", line): s = re.search(r"^(\S.*?) -", line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip()) == 0: continue if step == 2 and len(line.strip()) > 0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^一片浓雾中,什么也看不清。", line): break if step == 3 and re.search(r"^\S+", line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+", line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ", line): startline = 1 myline = line if re.search(r"。$", line): startline = 0 break else: continue if startline == 1: myline = myline + line if re.search(r"。$", line): startline = 0 break else: continue s = re.search(r"^\s*这里.*?的.*?有 (.*?)。", myline) exitsdesc = "" if len(myline) > 0: exitsdesc = s.group(1) p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() sorteddesc = ','.join(elist) conn = getconn() cursor = conn.cursor() cursor.execute( 'select rid,exitsdesc,area from roominfo where rname=? and rdesc=?', (roomname.decode("utf8"), roomdesc.decode("utf8"))) rows = cursor.fetchall() conn.close() if len(rows) > 0: for row in rows: elist = p.split(row[1].encode("utf8")) elist.sort() if sorteddesc == ','.join(elist): print row[2] print row[0]
def main(args): lines = args[1].decode("gb18030").encode("utf8").split("|||") area = args[2].decode("gb18030").encode("utf8") roomname = "" roomdesc = "" step = 0 for i,line in enumerate(lines): if step==0 and re.search(r"^(\S.*?) -",line): s = re.search(r"^(\S.*?) -",line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip())==0: continue if step == 2 and len(line.strip())>0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^\S+",line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+",line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ",line): startline = 1 myline = line if re.search(r"。$",line): startline = 0 break else: continue if startline == 1: myline = myline + line if re.search(r"。$",line): startline = 0 break else: continue s = re.search(r"^\s*这里.*?的.*?有 (.*?)。",myline) exitsdesc = "" if len(myline)>0: exitsdesc = s.group(1) p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() exitsdesc = ','.join(elist) s1 = area + roomname + roomdesc + exitsdesc bakid = md5digest(s1) print bakid conn = getconn() cursor = conn.cursor() cursor.execute('select rid from roominfo where bakid=?',(bakid,)) row = cursor.fetchone() conn.close() if row==None: print 0 else: print row[0]
def lbylines(ref_rid, lines): roomname = "" roomdesc = "" step = 0 for i, line in enumerate(lines): if step == 0 and re.search(r"^(\S.*?) -", line): s = re.search(r"^(\S.*?) -", line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip()) == 0: continue if step == 2 and len(line.strip()) > 0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^一片浓雾中,什么也看不清。", line): break if step == 3 and re.search(r"^\S+", line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+", line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ", line): startline = 1 myline = line if re.search(r"。$", line): startline = 0 break else: continue if startline == 1: myline = myline + line if re.search(r"。$", line): startline = 0 break else: continue s = re.search(r"^\s*这里.*?的.*?有 (.*?)。", myline) exitsdesc = "" if len(myline) > 0: exitsdesc = s.group(1) p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() sorteddesc = ','.join(elist) conn = getconn() cursor = conn.cursor() cursor.execute( 'select rid,exitsdesc from roominfo where rname=? and rdesc=?', (roomname.decode("utf8"), roomdesc.decode("utf8"))) rows = cursor.fetchall() conn.close() myrids = [] ridcount = 0 if len(rows) == 0: return 0 else: for row in rows: elist = p.split(row[1].encode("utf8")) elist.sort() if sorteddesc == ','.join(elist): myrids.append(row[0]) ridcount = ridcount + 1 if ridcount == 1: return myrids[0] if ridcount == 0: return 0 if ridcount > 1: k = 0 v = 99999 for myrid in myrids: c_rid = myrid if c_rid == ref_rid: return ref_rid else: p = MudRoomSearchProblem(ref_rid, c_rid) _, cost, _ = bfs(p) if v > cost: k = c_rid v = cost return k
def lbylines2(lines): roomname = "" roomdesc = "" step = 0 for i, line in enumerate(lines): if step == 0 and re.search(r"^(\S.*?) -", line): s = re.search(r"^(\S.*?) -", line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip()) == 0: continue if step == 2 and len(line.strip()) > 0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^一片浓雾中,什么也看不清。", line): break if step == 3 and re.search(r"^\S+", line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+", line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ", line): startline = 1 myline = line if re.search(r"。$", line): startline = 0 break else: continue if startline == 1: myline = myline + line if re.search(r"。$", line): startline = 0 break else: continue s = re.search(r"^\s*这里.*?的.*?有 (.*?)。", myline) exitsdesc = "" if len(myline) > 0: exitsdesc = s.group(1) p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() sorteddesc = ','.join(elist) conn = getconn() cursor = conn.cursor() cursor.execute( 'select rid,exitsdesc from roominfo where rname=? and rdesc=?', (roomname.decode("utf8"), roomdesc.decode("utf8"))) rows = cursor.fetchall() conn.close() myrid = "0" ridcount = 0 if len(rows) == 0: return (0, 0) else: for row in rows: elist = p.split(row[1].encode("utf8")) elist.sort() if sorteddesc == ','.join(elist): myrid = row[0] ridcount = ridcount + 1 if ridcount == 1: return (1, myrid) if ridcount == 0: return (0, 0) if ridcount > 1: return (2, ridcount)
def main(args): rid = args[1].decode("gb18030") #rid = '6d9de40de944b975eb87f20bf0c9f0a1' lines = args[2].decode("gb18030").encode("utf8").split("|||") area = args[3].decode("gb18030").encode("utf8") roomname = "" roomdesc = "" step = 0 for i, line in enumerate(lines): if step == 0 and re.search(r"^(\S.*?) -", line): s = re.search(r"^(\S.*?) -", line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip()) == 0: continue if step == 2 and len(line.strip()) > 0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^\S+", line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+", line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ", line): startline = 1 myline = line continue if startline == 1 and re.search(r"^\S+", line): myline = myline + line continue if startline == 1 and re.search(r"^\s+", line): startline = 0 break s = re.search(r"^\s*这里.*?的.*?有 (.*?)。", myline) exitsdesc = "" if len(myline) > 0: exitsdesc = s.group(1) p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() exitsdesc = ','.join(elist) s1 = area + roomname + roomdesc + exitsdesc bakid1 = md5digest(s1) conn = getconn() #conn = sqlite3.connect('./xkxmap.sqlite') cursor = conn.cursor() cursor.execute( 'select area,rname,rdesc,exitsdesc from roominfo where rid=?', (rid, )) row = cursor.fetchone() area = row[0].encode("utf8") roomname = row[1].encode("utf8") roomdesc = row[2].encode("utf8") exitsdesc = row[3].encode("utf8") conn.close() p = re.compile(r"、| 和 ") elist = p.split(exitsdesc) elist.sort() exitsdesc = ','.join(elist) s1 = area + roomname + roomdesc + exitsdesc bakid2 = md5digest(s1) if bakid1 <> bakid2: print 0 else: print 1
val_map = {'A': 1.0, 'D': 0.5714285714285714, 'H': 0.0} values = [val_map.get(node, 0.25) for node in G.nodes()] # Specify the edges you want here red_edges = [('A', 'C'), ('E', 'C')] edge_colours = ['black' if not edge in red_edges else 'red' for edge in G.edges()] black_edges = [edge for edge in G.edges() if edge not in red_edges] """ # Need to create a layout when doing # separate calls to draw nodes and edges conn = getconn() cursor = conn.cursor() cursor.execute( "select rid,rname,rdesc,exitsdesc,xofct,yofct from roominfo where area='yz'" ) rows = cursor.fetchall() rid_rname_dict = {} edge_list = [] init_pos = {} fixed = [] for row in rows: rid = row[0] rname = row[1] rdesc = row[2] exitsdesc = row[3] cursor.execute('select rid,nextrid,exit,bexit from roomrel where rid=?',
def main(args): #pdb.set_trace() #lines1 = "yz|||s|e|w|s|||n|e|w|n|||2|||-3|||-1".split("|||") old_rid = args[1].decode("gb18030") # old_rid="bc50074a9e9a76f0d6499aa0f992939e" #$area|||$fromct|||$toct|||$xofct|||$yofct|||$zofct conn = getconn() cursor = conn.cursor() cursor.execute( 'select area,fromct,toct,xofct,yofct,zofct,t_area,py_name,room_type from roominfo where rid=?', (old_rid, )) # print 'select area,fromct,toct,xofct,yofct,zofct,t_area,py_name,room_type from roominfo where rid={0}'.format(old_rid) row = cursor.fetchone() area = row[0].encode("utf8") fromct = row[1].encode("utf8") toct = row[2].encode("utf8") xofct = row[3] yofct = row[4] zofct = row[5] t_area = row[6] py_name = row[7] room_type = row[8] #roomname: # lines = "|||||| 黄河南岸 ||| /||| 大官道----虎牢关 ||| / \||| 山野小径 官道 ||||||虎牢关 - |||||| 这里是洛阳东边门户和重要的关隘,因西周穆王在此牢虎而得名。其南连嵩|||岳,北濒黄河,山岭交错,自成天险。大有“一夫当关,万夫莫开”之势,为历|||代兵家必争之地。||| 「初春」:清晨,东方的天空布满了灰蒙蒙的云层。|||||| 这里明显的方向有 southeast、southwest、west 和 northeast。||||||".split("|||") #lines = "||| 后堂 ||| | ||| 左配殿----三清殿----右配殿 ||| | ||| 武当广场 ||||||三清殿 - [门派]|||||| 这里是凌霄宫的三清殿,是武当派会客的地点。供着元始|||天尊、太上道君和天上老君的神像,香案上香烟缭绕。靠墙放|||着几张太师椅,地上放着几个蒲团。东西两侧是走廊,南边是|||练武的广场,北边是后院。|||||| 这里明显的出口是 north、south、east 和 west。|||||| 神武功德录(Board) [ 115 张留言,115 张未读 ]||| 武当派道长 谷虚道长(Guxu daozhang)||| 武当派第三代弟子 中年道长(Zhongnian daozhang)||| 一流高手 武当派真人「武当首侠」宋远桥(Songyuanqiao)|||>".split("|||") lines = args[2].decode("gb18030").encode("utf8").split("|||") roomname = "" roomdesc = "" step = 0 for i, line in enumerate(lines): if step == 0 and re.search(r"^(\S.*?) -", line): s = re.search(r"^(\S.*?) -", line) ss = s.group(1) roomname = ss step = 2 continue if step == 2 and len(line.strip()) == 0: continue if step == 2 and len(line.strip()) > 0: roomdesc = roomdesc + line step = 3 continue if step == 3 and re.search(r"^\S+", line): roomdesc = roomdesc + line continue if step == 3 and re.search(r"^\s+", line): break startline = 0 myline = "" for line in lines: if re.search(r"^\s*这里.*?的.*?有 ", line): startline = 1 myline = line if re.search(r"。$", line): startline = 0 break else: continue if startline == 1: myline = myline + line if re.search(r"。$", line): startline = 0 break else: continue s = re.search(r"^\s*这里.*?的.*?有 (.*?)。", myline) exitsdesc = "" if len(myline) > 0: exitsdesc = s.group(1) #npcs p = re.compile( r"^\s*((一|二|三|四|五|六|七|八|九|十)(位|只))?(.*?)\((.*?)\)( <(.*?)>)?$") npclist = [] for line in lines: if p.match(line): s = p.match(line) npc_num = 1 if s.group(2) is not None: npc_num = to_numbers(s.group(2)) ps = re.compile(r" |「|」") mylist = ps.split(s.group(4).strip(" ")) npc_title1 = "" npc_title2 = "" npc_title3 = "" npc_cname = "" ts = [] for t in mylist: if t == "": continue ts.append(t) if len(ts) == 4: npc_title1 = ts[0] npc_title2 = ts[1] npc_title3 = ts[2] npc_cname = ts[3] if len(ts) == 3: npc_title1 = ts[0] npc_title2 = ts[1] npc_cname = ts[2] if len(ts) == 2: npc_title1 = ts[0] npc_cname = ts[1] if len(ts) == 1: npc_cname = ts[0] npc_ename = s.group(5) npc_status = s.group(7) if npc_status is None: npc_status = "normal" npcdict = {} npcdict["num"] = npc_num npcdict["title1"] = npc_title1 npcdict["title2"] = npc_title2 npcdict["title3"] = npc_title3 npcdict["cname"] = npc_cname npcdict["ename"] = npc_ename npclist.append(npcdict) # print roomname # print roomdesc # print exitsdesc # print npclist[1]['cname'] # print 'here begin md5' s = area + roomname + roomdesc + exitsdesc + str(xofct) + str(yofct) + str( zofct) # print s.decode('utf8').encode("gb18030") rid = md5digest(s) # print rid s1 = area + roomname + roomdesc + exitsdesc bakid = md5digest(s1) # # # cursor.execute('select 1 from roominfo where rid=?', (rid, )) row = cursor.fetchone() if row is None: cursor.execute('delete from roominfo where rid=?', (old_rid, )) # print 'delete from roominfo where rid={0}'.format(old_rid) cursor.execute( 'insert into roominfo (rid,area,fromct,toct,xofct,yofct,zofct, rname,rdesc,exitsdesc,bakid,t_area,py_name,room_type) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', (rid, area.decode("utf8"), fromct.decode("utf8"), toct, xofct, yofct, zofct, roomname.decode("utf8"), roomdesc.decode("utf8"), exitsdesc.decode("utf8"), bakid, t_area, py_name, room_type)) # print 'insert into roominfo (rid,area,fromct,toct,xofct,yofct,zofct, rname,rdesc,exitsdesc,bakid,t_area,py_name,room_type) values ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13})'.format(rid,area.decode("utf8").encode("gb18030"),fromct.decode("utf8").encode("gb18030"),toct,xofct,yofct,zofct, roomname.decode("utf8").encode("gb18030"),roomdesc.decode("utf8").encode("gb18030"),exitsdesc.decode("utf8").encode("gb18030"),bakid,t_area,py_name,room_type) #update roomrel: cursor.execute('update roomrel set rid=? where rid=?', (rid, old_rid)) # print 'update roomrel set rid={0} where rid={1}'.format(rid,old_rid) cursor.execute('update roomrel set nextrid=? where nextrid=?', (rid, old_rid)) # print 'update roomrel set nextrid={0} where nextrid={1}'.format(rid,old_rid) conn.commit() print rid else: print '0' conn.close()