def be_defenced(self): if(self.equip[0].id == 30): print("%s使用了[%s]" % (self.name, cd.card_nm[self.equip[0].id])) self.use_kill = 0 elif (self.equip[0].id == 27): if(len(self.has_card)>3): op.choices_num = [0] * 120 ok = 0 if(op.judge(("是否使用%s?" % (cd.card_nm[27])), 380, 30, ["使用", "不使用"], 420, 30, 0) == 0): print("%s使用了[%s]" % (self.name, cd.card_nm[self.equip[0].id])) x = 1 self.can_choose = 2 self.chosen = [0]*120 while (sum(self.chosen) < 2 or x != 0): op.choices_num = [0] * 120 x = op.judge("请弃置2张牌", 380, 30, ["确定"], 420, 30, 0) op.has_end, op.has_confirm, op.has_cancel = 0, 0, 0 for i in range(len(self.chosen)-1,-1,-1): if (self.chosen[i] == 1): tmp = self.has_card.pop(i) print("%s丢掉了" % (self.name), end="") tmp.show() cd.throw_queue.append(tmp) ok = 1 self.can_choose = 1 self.pl_can_choose = 1 op.has_end, op.has_confirm, op.has_cancel = 0, 0, 0 op.task_queue.clear() op.task_queue.append(op.Button("结束出牌", 750, 400, 30, op.end_stage)) op.task_queue.append(op.Button("确定", 460, 400, 30, op.confirm)) op.task_queue.append(op.Button("取消", 590, 400, 30, op.cancel)) return ok return 0
def response(self, evt): if (evt == [1, self, 3, 0]): if (len(self.has_card) < 1): return x = -1 while (x == -1): op.choices_num = [0] * 120 x = op.judge(("是否发动技能【印记】?"), 360, 30, ["确定", "取消"], 400, 30, 0) if (x == 1): return x = -1 self.pl_can_choose = 1 self.can_choose = 1 while (x == -1 or sum(self.pl_chosen) < 1 or sum(self.chosen) < 1): op.choices_num = [0] * 120 x = op.judge(("请选择一名其他角色并弃1张手牌发动【印记】"), 360, 30, ["确定"], 400, 30, 0) for i in range(len(self.has_card)): if (self.chosen[i] != 0): tmp = self.has_card.pop(i) cd.throw_queue.append(tmp) print("%s弃置了" % (self.name), end="") tmp.show() print() break self.chosen = [0] * 120 for i in range(len(pl.player_in_game)): if (self.pl_chosen[i] != 0): self.mark_pos[i] += 1 self.attack_dis = max(self.mark_pos)
def lost_hp(self, num, user, type=0): if (self.mark_pos[user.pos] > 0): x = -1 while (x == -1): op.choices_num = [0] * 120 x = op.judge( ("是否发动技能【瞬身】减少飞雷神(%d)抵消此伤害?" % (self.mark_pos[user.pos])), 360, 30, ["确定", "取消"], 400, 30, 0) if (x == 0): print("%s发动技能【瞬身】抵消了伤害" % (self.name)) self.mark_pos[user.pos] -= 1 self.attack_dis = max(self.mark_pos) return 0 if (self.equip[1].id == 35): if (num > 1): print("%s使用了[%s]" % (self.name, cd.card_nm[self.equip[1].id])) num = 1 st = [ "%s被掌力击退,向后直跌了%d步,", "%s中了一击,吐出%d口鲜血,", "%s眉头一皱,只知这一掌下去功力已失了%d成," ] tmp = st[random.randint(0, 2)] print(tmp % (self.name, num)) self.hp -= num while (self.hp < 1): if (self.dying() == 0): break else: self.hp += 1 if (self.hp < 1): self.died() return num pl.upload([4, user, num, self, type]) return num
def prepare(self): print(self.name, "的准备阶段") if (len(self.skill_name) < 3): if (self.hp == 1): print("%s发动技能【魂姿】减少1点体力上限并获得了技能【英魂】,【英姿】" % (self.name)) self.skill_name = [("激昂", 1, 0), ("英魂", 1, 0), ("英姿", 1, 0)] self.skill_init() self.max_hp -= 1 self.hp = min(self.hp, self.max_hp) if (len(self.skill_name) >= 3): num = self.max_hp - self.hp if (num < 1): return x = -1 while (x == -1): op.choices_num = [0] * 120 x = op.judge(("是否发动技能【英魂】?"), 360, 30, ["确定", "取消"], 400, 30, 0) if (x == 1): return x = -1 self.pl_can_choose = 1 while (x == -1 or sum(self.pl_chosen) < 1): op.choices_num = [0] * 120 x = op.judge( ("请选择一名其他角色发动【英魂】"), 360, 30, ["摸%d弃1" % (num), "摸1弃%d" % (num)], 400, 30, 0) for i in range(len(pl.player_in_game)): item = pl.player_in_game[i] if (self.pl_chosen[i] != 0): for _ in range(num * (1 - x)): item.has_card.append(cd.get_new_card()) if (x == 0): item.throw(1) else: maxn = len(item.has_card) if (maxn >= num): item.throw(num) else: item.throw(maxn) for i in range(4, -1, -1): #实在不够弃装备 if (maxn <= num): break if (item.equip[i].id != 0): tmp = item.equip[i] cd.throw_queue.append(tmp) item.equip[i] = cd.Card(0, 0, 0, i == 0) maxn -= 1 break
def throw_hascard(self,num): if(len(self.has_card)<num): return 0 last = self.can_choose x = 1 self.can_choose = num while (sum(self.chosen) < num or x != 0): op.choices_num = [0] * 120 x = op.judge(("请弃置%d张牌"%(num)), 360, 30, ["确定"], 400, 30, 0) for i in range(len(self.chosen)-1,-1,-1): if (self.chosen[i] == 1): tmp = self.has_card.pop(i) print("%s丢掉了" % (self.name), end="") tmp.show() cd.throw_queue.append(tmp) return 1
def throw(self,num): print(self.name, "的弃牌阶段") if(num <= 0): return print("弃置",num,"张") self.can_choose = num x = 1 while (sum(self.chosen) < num or x != 0): op.choices_num = [0] * 120 x = op.judge(("请弃置%d张牌"%(num)), 360, 30, ["确定"], 400, 30, 0) for i in range(len(self.chosen)-1,-1,-1): if (self.chosen[i] == 1): tmp = self.has_card.pop(i) print("%s丢掉了" % (self.name), end="") tmp.show() cd.throw_queue.append(tmp) for item in self.has_card: item.show() print()
def multi_need(self,need_id): #print("需要", self.name, "出:") #for i in need_id: # print(cd.card_nm[i],end=" ") print() op.delay(1000) for i in range(0,len(self.has_card)): if(self.has_card[i].id in need_id): op.choices_num = [0] * 120 x = op.judge(("是否响应打出【%s】?" % (cd.card_nm[self.has_card[i].id])), 380, 30, ["确定", "取消"], 420, 30, 0) if (x != 0): break print("%s打出了%s"%(self.name,cd.card_nm[self.has_card[i].id])) tmp = self.has_card.pop(i) cd.throw_queue.append(tmp) #op.play(self) return tmp return 0
def response(self, evt): if (evt[0] == 8): print(self.name, ":深表同情") if(evt[0] == 4): if(evt[3].country == self.country): x = -1 while (x == -1): op.choices_num = [0] * 120 x = op.judge(("是否发动技能【分身】获得%d张牌" % (evt[3].max_hp - evt[3].hp)), 360, 30, ["确定","取消"], 400, 30, 0) if(x == 0): for i in range(evt[3].max_hp - evt[3].hp): print("%s发动技能【分身】获得了" % (self.name)) tmp = cd.get_new_card() tmp.show() print() self.has_card.append(tmp) if (evt[0] == 3): if (evt[1].pos == self.pos and evt[3].id in [1,2, 3,7,8]): if (len(self.has_card) > 0): print("%s发动技能【天照】" % (self.name)) pl.player_in_game[evt[2].pos].lost_hp(1, self)
def need(self,need_id,user): #print("需要",self.name,"出",cd.card_nm[need_id]) op.delay(1000) if(need_id == 4 and self.equip[1].id == 32 and user.equip[0].id != 25): print("%s使用了[%s]" % (self.name, cd.card_nm[self.equip[1].id])) tmp = cd.get_new_card() print("判定结果:", end=" ") tmp.show() print() if(tmp.type == 1 or tmp.type == 3): print("[%s]生效"%(cd.card_nm[self.equip[1].id])) tmp.id = 4 return tmp for i in range(0,len(self.has_card)): if(self.has_card[i].id == need_id): op.choices_num = [0] * 120 x = op.judge(("是否响应%s打出【%s】?"%(user.name,cd.card_nm[need_id])), 380,30,["确定","取消"],420,30,0) if(x != 0): break if (need_id == 4): tmp = ["向后一躲,避开了这一招","片刻之间已侧身避过","忽的跳出,早避开这招"] st = tmp[random.randint(0,2)] print("%s%s," % (self.name, st)) elif (need_id == 18): st = "早就看出端倪,轻松化开" print("%s%s," % (self.name, st)) elif (need_id in [1, 2, 3]): st = self.skill[need_id] print("%s接了一记“%s”" % (self.name, st)) else: st = cd.card_nm[need_id] print("%s打出了%s"%(self.name,st)) tmp = self.has_card.pop(i) cd.throw_queue.append(tmp) #op.play(self) return tmp return 0
print "classification..." result_valid,result_test,number = classification.classification(feature,label,label_number,test,valid) # fn = 'regr.pkl' #'parse.pkl' # with open(fn, 'r') as f: # feature,label,test,ids = pickle.load(f) print "classification OK" print "judging..." # if sub == 0: output.judge(result_valid,result_test,ids_valid,ids_test,items,number) # else: # output.judge(test_result,ids,items,number) print "judge OK" output.tune() # import validate.val() # print >>o, feature, label
def use(now_card: Card, user, aimer, defence=1): tot = len(pl.player_in_game) x = user.pos y = aimer.pos nid = now_card.id throw_queue.append(now_card) op.use_card_arrow(user.seat, aimer.seat) pl.cd_score[x] += 1 pl.upload([2,user,aimer,now_card]) #结算前视为指定目标 if (nid in [1, 2, 3, 7, 8, 9, 10, 16, 17, 18, 19, 20]): if (pl.player_in_game[y].be_used(now_card, user) == 0): pl.upload([3, user, aimer, now_card]) return # op.use_card_arrow(x, y) if (nid > 0 and nid < 4): st = user.skill[nid - 1] print("对%s使出一招“%s”," % (aimer.name, st)) if (user.gender != aimer.gender and user.equip[0].id == 23): print("%s使用了[%s]" % (user.name, card_nm[user.equip[0].id])) if(aimer.auto): if (len(aimer.has_card) > 2): tmp = pl.player_in_game[y].has_card.pop() print("%s丢掉了" % (aimer.name), end="") tmp.show() throw_queue.append(tmp) else: tmp = get_new_card() print("%s得到了" % (user.name), end="") tmp.show() pl.player_in_game[x].has_card.append(tmp) else: x = op.judge(("如何响应%s的%s?"%(user.name,card_nm[23])),380,30,["弃置一张牌","给对方一张牌"],420,30,0) if(x != 0): tmp = get_new_card() print("%s得到了" % (user.name), end="") tmp.show() pl.player_in_game[x].has_card.append(tmp) else: aimer.can_choose = 1 x = 1 while(sum(aimer.chosen)<1 or x!=0): op.choices_num = [0]*120 x = op.judge("请弃置1张牌",380,30,["确定"],420,30,0) for i in range(len(aimer.chosen)): if(aimer.chosen[i] == 1): tmp = pl.player_in_game[y].has_card.pop(i) print("%s丢掉了" % (aimer.name), end="") tmp.show() throw_queue.append(tmp) break added = pl.player_in_game[x].drink in_lost = 0 if (defence == 0): added += (aimer.equip[1].id == 34 and nid == 2) in_lost = added + 1 elif (pl.player_in_game[y].need(4, user) == 0): added += (aimer.equip[1].id == 34 and nid == 2) in_lost = added + 1 else: if (pl.player_in_game[x].be_defenced()): added += (aimer.equip[1].id == 34 and nid == 2) in_lost = added + 1 if (in_lost): if (user.equip[0].id == 24 and len(aimer.has_card) > 1): x = 0 if(user.auto == 0): op.choices_num = [0] * 120 x = op.judge(("是否使用%s?"%(card_nm[24])), 380, 30, ["使用","不使用"], 420, 30, 0) op.has_end, op.has_confirm, op.has_cancel = 0, 0, 0 op.task_queue.clear() op.task_queue.append(op.Button("结束出牌", 750, 400, 30, op.end_stage)) op.task_queue.append(op.Button("确定", 460, 400, 30, op.confirm)) op.task_queue.append(op.Button("取消", 590, 400, 30, op.cancel)) if(x == 0): print("%s使用了[%s]" % (user.name, card_nm[user.equip[0].id])) for _ in range(2): dan_max, dan_pos = 95, -1 for i in range(0, 5): if (danger_lvl[aimer.equip[i].id] < dan_max): dan_max = danger_lvl[aimer.equip[i].id] dan_pos = i if (dan_pos >= 0): tmp_card = pl.player_in_game[y].equip[dan_pos] print("丢弃了%s的" % (aimer.name), end="") tmp_card.show() print(",") if (tmp_card.id == 35): if (pl.player_in_game[y].hp < pl.player_in_game[y].max_hp): print("丢掉了[%s]并回复1点体力" % (card_nm[35])) pl.player_in_game[y].hp += 1 pl.player_in_game[y].equip[dan_pos] = Card(0, 0, 0, dan_pos == 0) continue tmp = random.randint(0, len(aimer.has_card) - 1) tmp_card = aimer.has_card[tmp] print("丢弃了%s的" % (aimer.name), end="") tmp_card.show() print(",") throw_queue.append(tmp_card) # op.play(user) pl.player_in_game[y].has_card.pop(tmp) else: pl.player_in_game[y].lost_hp(in_lost, user,now_card.id - 1) else: if (user.equip[0].id == 28): print("%s使用了[%s]" % (user.name, card_nm[user.equip[0].id])) if (aimer.equip[2].id != 0): print("丢弃了%s的" % (aimer.name), end="") aimer.equip[2].show() pl.player_in_game[y].equip[2] = Card(0, 0, 0, 0) elif (aimer.equip[3].id != 0): print("丢弃了%s的" % (aimer.name), end="") aimer.equip[3].show() pl.player_in_game[y].equip[3] = Card(0, 0, 0, 0) pl.player_in_game[y].lost_hp(in_lost, user,now_card.id - 1) pl.upload([3, user, aimer, now_card]) return print("对%s使出了一记“%s”," % (aimer.name, card_nm[now_card.id])) if (nid == 7): if (defence == 1 and pl.player_in_game[y].need(18, user) != 0): pl.upload([3, user, aimer, now_card]) return if (pl.player_in_game[y].multi_need([1, 2, 3]) == 0): pl.player_in_game[y].lost_hp(1, user) else: use(now_card, aimer, user, 0) elif (nid == 8): if (defence == 1 and pl.player_in_game[y].need(18, user) != 0): return if (len(aimer.has_card) <= 0): return tmp_n = 0 if(len(aimer.has_card)>1): tmp_n = random.randint(0, len(aimer.has_card) - 1) print(tmp_n, len(aimer.has_card)) tmp_card = aimer.has_card[tmp_n] print("%s 亮出了 " % (aimer.name), end="") tmp_card.show() print(",") for i in range(0, len(user.has_card)): if (user.has_card[i].type == tmp_card.type): print("%s接了" % (user.name), end=" ") user.has_card[i].show() print(",") pl.player_in_game[x].has_card.pop(i) added = (aimer.equip[1].id == 34) pl.player_in_game[y].lost_hp(added + 1, user,1) break elif (nid == 9): if (defence == 1 and pl.player_in_game[y].need(18, user) != 0): return dan_max, dan_pos = 95, -1 for i in range(0, 5): if (danger_lvl[aimer.equip[i].id] < dan_max): dan_max = danger_lvl[aimer.equip[i].id] dan_pos = i if (dan_pos >= 0): tmp_card = pl.player_in_game[y].equip[dan_pos] print("丢弃了%s的" % (aimer.name), end="") tmp_card.show() print(",") if (tmp_card.id == 35): if (pl.player_in_game[y].hp < pl.player_in_game[y].max_hp): print("丢掉了[%s]并回复1点体力" % (card_nm[35])) pl.player_in_game[y].hp += 1 throw_queue.append(tmp_card) pl.player_in_game[y].equip[dan_pos] = Card(0, 0, 0, dan_pos == 0) pl.upload([3, user, aimer, now_card]) return if(len(aimer.has_card)<=0):return tmp_n = 0 if (len(aimer.has_card) > 1): tmp_n = random.randint(0, len(aimer.has_card) - 1) print(tmp_n,len(aimer.has_card)) tmp_card = aimer.has_card[tmp_n] throw_queue.append(tmp_card) print("丢弃了%s的" % (aimer.name), end="") tmp_card.show() print(",") pl.player_in_game[y].has_card.pop(tmp_n) elif (nid == 10): if (defence == 1 and pl.player_in_game[y].need(18, user) != 0): pl.upload([3, user, aimer, now_card]) return dan_max, dan_pos = 95, -1 for i in range(0, 5): if (danger_lvl[aimer.equip[i].id] < dan_max): dan_max = danger_lvl[aimer.equip[i].id] dan_pos = i if (dan_pos >= 0): tmp_card = pl.player_in_game[y].equip[dan_pos] print("得到了%s的" % (aimer.name), end="") tmp_card.show() print(",") if (tmp_card.id == 35): if (pl.player_in_game[y].hp < pl.player_in_game[y].max_hp): print("丢掉了[%s]并回复1点体力" % (card_nm[35])) pl.player_in_game[y].hp += 1 pl.player_in_game[y].equip[dan_pos] = Card(0, 0, 0, dan_pos == 0) pl.player_in_game[x].has_card.append(tmp_card) pl.upload([3, user, aimer, now_card]) return if (len(aimer.has_card) <= 0): return tmp_n = random.randint(0, len(aimer.has_card) - 1) print(tmp_n, len(aimer.has_card)) tmp_card = aimer.has_card[tmp_n] print("得到了%s的" % (aimer.name), end="") tmp_card.show() print(",") pl.player_in_game[x].has_card.append(tmp_card) pl.player_in_game[y].has_card.pop(tmp_n) elif (nid == 16): if (defence == 1 and pl.player_in_game[y].need(18, user) != 0): pl.upload([3, user, aimer, now_card]) return used = pl.player_in_game[y].multi_need([1, 2, 3]) if (used != 0): new_aimer = aiming(used, aimer) if (new_aimer != 0): use(used, aimer, new_aimer) pl.upload([3, user, aimer, now_card]) return pl.player_in_game[x].has_card.append(pl.player_in_game[y].equip[0]) print("得到了%s的" % (aimer.name)) pl.player_in_game[y].equip[0].show() pl.player_in_game[y].equip[0] = Card(0, 0, 0, 1) elif (nid == 17): if(aimer.connect == 0): print("横置了%s" % (aimer.name)) else: print("解除了%s的横置" % (aimer.name)) aimer.connect ^= 1 elif (nid == 19): pl.player_in_game[y].judge.append(now_card) elif (nid == 20): pl.player_in_game[y].judge.append(now_card) elif (nid > 21): if (nid > 21 and nid < 32): print("拾起了%s," % (card_nm[now_card.id])) if (pl.player_in_game[x].equip[0].id != 0): pl.player_in_game[x].equip[0].alpha = 255 throw_queue.append(pl.player_in_game[x].equip[0]) pl.player_in_game[x].equip[0] = now_card elif (nid > 31 and nid < 36): print("装上了%s," % (card_nm[now_card.id])) if (pl.player_in_game[x].equip[1].id == 35): if (pl.player_in_game[x].hp < pl.player_in_game[x].max_hp): print("丢掉了[%s]并回复1点体力" % (card_nm[35])) pl.player_in_game[x].hp += 1 if (pl.player_in_game[x].equip[1].id != 0): pl.player_in_game[x].equip[1].alpha = 255 throw_queue.append(pl.player_in_game[x].equip[1]) pl.player_in_game[x].equip[1] = now_card elif (nid > 35 and nid < 39): if (pl.player_in_game[x].equip[2].id != 0): pl.player_in_game[x].equip[2].alpha = 255 throw_queue.append(pl.player_in_game[x].equip[2]) print("骑上了%s," % (card_nm[now_card.id])) pl.player_in_game[x].equip[2] = now_card elif (nid > 38 and nid < 42): if (pl.player_in_game[x].equip[3].id != 0): pl.player_in_game[x].equip[3].alpha = 255 throw_queue.append(pl.player_in_game[x].equip[3]) print("骑上了%s," % (card_nm[now_card.id])) pl.player_in_game[x].equip[3] = now_card elif (nid == 42): if (pl.player_in_game[x].equip[4].id != 0): pl.player_in_game[x].equip[4].alpha = 255 throw_queue.append(pl.player_in_game[x].equip[4]) print("发现了%s," % (card_nm[now_card.id])) pl.player_in_game[x].equip[4] = now_card else: if (nid == 5): if (pl.player_in_game[y].be_used(now_card, user) == 0): pl.upload([3, user, aimer, now_card]) return print("吃了口“%s”," % (card_nm[now_card.id])) pl.player_in_game[x].hp += 1 return elif (nid == 6): if (pl.player_in_game[y].be_used(now_card, user) == 0): pl.upload([3, user, aimer, now_card]) return print("喝了口“%s”," % (card_nm[now_card.id])) pl.player_in_game[x].drink = 1 return elif (nid == 15): if (pl.player_in_game[y].be_used(now_card, user) == 0): pl.upload([3, user, aimer, now_card]) return print("以内功“%s”," % (card_nm[now_card.id])) pl.player_in_game[x].has_card.append(get_new_card()) pl.player_in_game[x].has_card.append(get_new_card()) # elif (nid == 17): # if (pl.player_in_game[y].be_used(now_card, user) == 0): # pl.upload([3, user, aimer, now_card]) # return # print("重铸了“%s”," % (card_nm[now_card.id])) # pl.player_in_game[x].has_card.append(get_new_card()) else: print("%s趁众人不备,用出了“%s”," % (user.name, card_nm[now_card.id])) if (nid == 11): for item in pl.player_in_game: if (item.dead or item.pos == x or item.be_aimed(now_card, user) == 0): continue if (defence == 1 and pl.player_in_game[item.pos].need(18, user) != 0): continue if (pl.player_in_game[item.pos].be_used(now_card, user) == 0): continue op.use_card_arrow(x, item.seat) if (pl.player_in_game[item.pos].need(4, user) == 0): pl.player_in_game[item.pos].lost_hp(1, user) elif (nid == 12): for item in pl.player_in_game: if (item.dead or item.pos == x or item.be_aimed(now_card, user) == 0): continue if (defence == 1 and pl.player_in_game[item.pos].need(18, user) != 0): continue if (pl.player_in_game[item.pos].be_used(now_card, user) == 0): continue op.use_card_arrow(x, item.seat) if (pl.player_in_game[item.pos].multi_need([1, 2, 3]) == 0): pl.player_in_game[item.pos].lost_hp(1, user) elif (nid == 13): for item in pl.player_in_game: y = item.pos if (pl.player_in_game[item.pos].be_used(now_card, user) == 0): continue op.use_card_arrow(x, item.seat) if (item.dead == 0 and item.be_aimed(now_card, user)): pl.player_in_game[y].hp += 1 elif (nid == 14): tmp_card_list = [] for item in pl.player_in_game: if(item.dead == 0): tmp_card_list.append(get_new_card()) tmp_card_list.sort(key= lambda x:x.defence_level) for item in tmp_card_list: print(card_nm[item.id]) for item in pl.player_in_game: y = item.pos if (item.dead == 1 or pl.player_in_game[item.pos].be_used(now_card, user) == 0): continue op.use_card_arrow(x, item.seat) if (item.be_aimed(now_card, user)): tmp_card = tmp_card_list.pop(0) print("%s拿到了%s," % (item.name, card_nm[tmp_card.id])) pl.player_in_game[y].has_card.append(tmp_card) print() pl.upload([3, user, aimer, now_card])