def selectField(self, ban, koma, motigoma_flag): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() if pos[0] >= 280 and pos[0] < 520: posX = (pos[0] - 280) // 80 + 1 posY = pos[1] // 100 + 1 if motigoma_flag == False: #collect pos that empty or cpu's koma excists pos_lst = util.collectMoveablePos( ban, koma, "player") else: #collect pos that empty pos_lst = util.collectPos(ban, lambda val: val == 0) if [] != filter( lambda lst: lst[0] == posX and lst[1] == posY, pos_lst): return [posX, posY] else: return False
def canTry(self,ban): ou = self.searchSelfOu(ban) pos_lst = util.collectMoveablePos(ban,ou,self.name) for pos in pos_lst: if pos[1] == self.cpu.nari_posY: return util.infoDict(ou,pos,False) return False
def selectKoma(self, ban, screen): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() koma_lst = util.collectKoma(ban, "player") #turn card select_koma = False pos_lst = False for koma in koma_lst: if koma.rect.collidepoint(pos): select_koma = koma pos_lst = util.collectMoveablePos( ban, koma, "player") for koma in self.motigoma.koma_lst: if koma.rect.collidepoint(pos): select_koma = koma pos_lst = util.collectPos(ban, lambda val: val == 0) # Lighting the next step of koma if pos_lst != False: ban.brightFiled(screen, pos_lst) return select_koma
def selectKoma(self,ban,screen): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() koma_lst = util.collectKoma(ban,"player") #turn card select_koma = False pos_lst = False for koma in koma_lst: if koma.rect.collidepoint(pos): select_koma = koma pos_lst = util.collectMoveablePos(ban,koma,"player") for koma in self.motigoma.koma_lst: if koma.rect.collidepoint(pos): select_koma = koma pos_lst = util.collectPos(ban,lambda val:val == 0) if pos_lst !=False: ban.brightFiled(screen,pos_lst) return select_koma
def canTry(self, ban): ou = self.searchSelfOu(ban) pos_lst = util.collectMoveablePos(ban, ou, self.name) for pos in pos_lst: if pos[1] == self.cpu.nari_posY: return util.infoDict(ou, pos, False) return False
def eachMoveablePos(self,ban,koma_lst,owner_name): each_lst = [] for koma in koma_lst: pos_lst = util.collectMoveablePos(ban,koma,owner_name) each_lst.append({"koma":koma,"pos_lst":pos_lst}) return each_lst
def killChecker(self,ban): ou = self.searchSelfOu(ban) enemy_koma_lst = self.collectEnemyKoma(ban) self_koma_lst = self.collectSelfKoma(ban) enemy_each_lst = self.eachMoveablePos(ban,enemy_koma_lst,self.enemyName) self_each_lst = self.eachMoveablePos(ban,self_koma_lst,self.name) ou_moveable_lst = util.collectMoveablePos(ban,ou,self.name) checking_koma = self.isChecked(ban,ou,enemy_each_lst) if checking_koma: killable_lst = self.searchKillable(checking_koma,self_each_lst) killableOuDict = self.hasOu(killable_lst) #commanded checking_koma's pos? if(self.isCommandedKoma(ban,checking_koma)): #ou cant't kill cheker,so remove ou killable dict print "ou can't kill cheker" killable_lst.remove(killableOuDict) if killable_lst != []: #if killable more than 1 remove ou #if killableOuDict and len(killable_lst)>1: rand_num = random.randint(0,len(killable_lst)-1) killable_dict = killable_lst[rand_num] killable_koma = killable_dict["koma"] killable_pos = killable_dict["pos"] return util.infoDict(killable_koma,killable_pos,False) else: return False else:return False
def eachMoveablePos(self, ban, koma_lst, owner_name): each_lst = [] for koma in koma_lst: pos_lst = util.collectMoveablePos(ban, koma, owner_name) each_lst.append({"koma": koma, "pos_lst": pos_lst}) return each_lst
def selectField(self,ban,koma,motigoma_flag): if motigoma_flag == False: #collect pos that empty or cpu's koma excists pos_lst = util.collectMoveablePos(ban,koma,"cpu") else: #collect pos that empty pos_lst = util.collectPos(ban,lambda val:val == 0) if pos_lst == []: return False else: rand_num = random.randint(0,len(pos_lst)-1) return pos_lst[rand_num]
def selectField(self, ban, koma, motigoma_flag): if motigoma_flag == False: #collect pos that empty or cpu's koma excists pos_lst = util.collectMoveablePos(ban, koma, "cpu") else: #collect pos that empty pos_lst = util.collectPos(ban, lambda val: val == 0) if pos_lst == []: return False else: rand_num = random.randint(0, len(pos_lst) - 1) return pos_lst[rand_num]
def escapeOu(self,ban): ou = self.searchSelfOu(ban) koma_lst = self.collectEnemyKoma(ban) each_lst = self.eachMoveablePos(ban,koma_lst,self.enemyName) ou_moveable_lst = util.collectMoveablePos(ban,ou,self.name) if self.isChecked(ban,ou,each_lst): #escape_lst = self.getEscapLst(ban,ou,each_lst,ou_moveable_lst) escape_lst = self.removeDengerusPos(ou_moveable_lst,ban) if escape_lst != []: rand_num = random.randint(0,len(escape_lst)-1) return util.infoDict(ou,escape_lst[rand_num],False) else: return False else:return False
def escapeOu(self, ban): ou = self.searchSelfOu(ban) koma_lst = self.collectEnemyKoma(ban) each_lst = self.eachMoveablePos(ban, koma_lst, self.enemyName) ou_moveable_lst = util.collectMoveablePos(ban, ou, self.name) if self.isChecked(ban, ou, each_lst): #escape_lst = self.getEscapLst(ban,ou,each_lst,ou_moveable_lst) escape_lst = self.removeDengerusPos(ou_moveable_lst, ban) if escape_lst != []: rand_num = random.randint(0, len(escape_lst) - 1) return util.infoDict(ou, escape_lst[rand_num], False) else: return False else: return False
def selectField(self,ban,koma,motigoma_flag): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() if pos[0] >= 280 and pos[0] < 520: posX = (pos[0]-280)/80+1 posY = pos[1]/100+1 if motigoma_flag == False: #collect pos that empty or cpu's koma excists pos_lst = util.collectMoveablePos(ban,koma,"player") else: #collect pos that empty pos_lst = util.collectPos(ban,lambda val:val == 0) if [] != filter(lambda lst:lst[0] == posX and lst[1] == posY,pos_lst): return [posX,posY] else: return False
def killChecker(self, ban): ou = self.searchSelfOu(ban) enemy_koma_lst = self.collectEnemyKoma(ban) self_koma_lst = self.collectSelfKoma(ban) enemy_each_lst = self.eachMoveablePos(ban, enemy_koma_lst, self.enemyName) self_each_lst = self.eachMoveablePos(ban, self_koma_lst, self.name) ou_moveable_lst = util.collectMoveablePos(ban, ou, self.name) checking_koma = self.isChecked(ban, ou, enemy_each_lst) if checking_koma: killable_lst = self.searchKillable(checking_koma, self_each_lst) killableOuDict = self.hasOu(killable_lst) #commanded checking_koma's pos? if (self.isCommandedKoma(ban, checking_koma)): #ou can't kill cheker,so remove ou killable dict print("ou can't kill cheker") killable_lst.remove(killableOuDict) if killable_lst != []: #if killable more than 1 remove ou #if killableOuDict and len(killable_lst)>1: rand_num = random.randint(0, len(killable_lst) - 1) killable_dict = killable_lst[rand_num] killable_koma = killable_dict["koma"] killable_pos = killable_dict["pos"] return util.infoDict(killable_koma, killable_pos, False) else: return False else: return False