コード例 #1
0
def stage_page():
    loop_count = 0
    while True:
        loop_count += 1
        # 探测 & 有羽毛
        if explore and check_match([540, 880], [49, 157, 207]):
            click(540, 880, '点击探测', wait=5)

        # 选择已有关卡
        elif check_match([460, 720], [247, 171, 77]):  # 出击按钮
            click(360, 720, '出击', wait=5)

        # 投放羽毛界面
        elif check_match([450, 960], [255, 255, 255]):
            rx, ry = rdm(RX1, RX2), rdm(RY1, RY2)  # 全地图范围
            # rx, ry = rdm(280, 480), rdm(800, 880)  # 指定地区
            click(rx, ry, f'搜索 {rx} {ry}', wait=5)

        # 选择关卡 这里颠倒顺序因为无判断条件
        else:
            click(320, stageY, f'选择关卡 {stage}', wait=3)

        # 确认进入战斗 退出本环节
        if ui.battle():  # 底部蓝色蓄力条
            global battleTm, roundCount
            log.info(CSS('战斗开始!', 'r'))
            battleTm = Timer()  # 开始战斗计时
            roundCount += 1
            break

        screen_capture()  # 更新截图
        if loop_count >= 100:
            raise
コード例 #2
0
def generador_claves(p,q):
    n = p*q 
    phi = (p-1)*(q-1)
    e = rdm(1,phi)
    g = M.gcd(e, phi)
    while g!= 1:
        e = rdm(1, phi)
        g = M.gcd(e, phi)
    
    d =M.inver(e,phi) 
    return (n),(e),(d)
コード例 #3
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
    def give_birth(self, pop):
        # A woman can give birth if it has a partner, is over 20 and less than 35,
        if rdm(100) > pop.birth_prob:
            g = ['F', 'M']
            gender = rdm(2)
            first_name = pop.names.get_randomFirst(gender)
            last_name = self.last_name.split(
            )[-1] + ' ' + self.partner.last_name.split()[-1]

            return Individual(first_name, last_name, 1, g[gender], pop.id_seq,
                              self.area)
        else:
            return False
コード例 #4
0
 def __init__(self, name, price=10, weight=10, flammability=0.5):
     super().__init__(self)
     self.name = name
     self.price = price
     self.weight = weight
     self.flammability = flammability
     self.identifier = rdm(1000000, 9999999)
コード例 #5
0
 def test_legal_names(self):
     '''To make sure our pruduct names are syntactically proper'''
     prods = generate_products()
     x = rdm(0, (len(prods) - 1))
     word = prods[x]
     self.assertIn(word.split(' ')[0], ADJECTIVES)
     self.assertIn(word.split(' ')[1], NOUNS)
コード例 #6
0
 def __take_kick_1(self, con=None):
     logging.debug('status: %s\tfinger: %s\t; usage: %s/%s' % (self.status, self.finger, len(self.staticlist), len(self.conlist)))
     self.ilock.acquire()
     if con:
         self.conlist.append(con)
         con.mark = 0
         self.finger -= 1
         self.ilock.release()
         return self.finger
     if self.status <= 0:
         if self.__inilist(self.sqo, self.cif) != 1:
             self.ilock.release()
             raise RuntimeError('Cannot Initial the Pool!')
     if self.finger >= self.length:
         self.__batch_recovery()
         if self.finger >= self.length:
             for i in xrange(5):
                 time.sleep(round(rdm(),1))
                 if self.finger < self.length:
                     break
             if i >= 4:
                 self.ilock.release()
                 return None
     con = self.conlist.pop(0)
     self.finger += 1
     self.ilock.release()
     return con
コード例 #7
0
def biST(msg):  #this function takes in a list of binary ascii code of strings
    out = []
    for i in msg:
        if rdm() < f:
            out.append(str(int(0 == i)))
        else:
            out.append(str(i))
    return out
コード例 #8
0
ファイル: 0010.py プロジェクト: Pacico/python
def main():
    verify_size=(300,100)
    font_lib=glob.glob('c:Windows\Fonts\\*.ttf')
    img=Image.new('RGB',verify_size,'white')
    draw=ImageDraw.Draw(img)
    global verify
    verify=''

    #噪点处理
    def pointcolor():
        return(rdm(100,150),rdm(100,150),rdm(100,150))
    for w in xrange(300):
               for h in xrange(100):
                   draw.point((w,h),fill=pointcolor())

    img=img.filter(ImageFilter.BLUR)
    draw=ImageDraw.Draw(img)

    #加入验证字符
    for i in range(1,5):
        text=random.choice(string.letters+'123456789')
        textcolor=(rmcolor())
        font=ImageFont.truetype(random.choice(font_lib),rdm(70,90))
        x=rdm(40,50) #随机字符位置
        draw.text((x*i,10),fill=textcolor,text=text,font=font)
        verify+=text

    #随机划线
    line_times=rdm(0,3)
    k=1
    while k<=1:
        k+=1
        draw.line(((rdm(0,300),rdm(0,100)),(rdm(0,300),rdm(0,100))),fill=rmcolor(),width=1)
    img.show()
コード例 #9
0
def main():
    verify_size=(300,100)
    font_lib=glob.glob('c:Windows\Fonts\\*.ttf')
    img=Image.new('RGB',verify_size,'white')
    draw=ImageDraw.Draw(img)
    global verify
    verify=''

    #噪点处理
    def pointcolor():
        return(rdm(100,150),rdm(100,150),rdm(100,150))
    for w in xrange(300):
               for h in xrange(100):
                   draw.point((w,h),fill=pointcolor())

    img=img.filter(ImageFilter.BLUR)
    draw=ImageDraw.Draw(img)

    #加入验证字符
    for i in range(1,5):
        text=random.choice(string.letters+'123456789')
        textcolor=(rmcolor())
        font=ImageFont.truetype(random.choice(font_lib),rdm(70,90))
        x=rdm(40,50) #随机字符位置
        draw.text((x*i,10),fill=textcolor,text=text,font=font)
        verify+=text

    #随机划线
    line_times=rdm(0,3)
    k=1
    while k<=1:
        k+=1
        draw.line(((rdm(0,300),rdm(0,100)),(rdm(0,300),rdm(0,100))),fill=rmcolor(),width=1)
    
    img.save('F:\Trinick\Script\ShowMeTheCode\\010result.jpg')
コード例 #10
0
ファイル: Game.py プロジェクト: Me-k-01/Projet_Python
    def placeMine(self, i=None, j=None) :
        n, p = self.n, self.p
        mineToPlace = self.nMine
        def blankMatrice(n, p):
            matrice = []
            for i in range(n):
                matrice.append([])
                for j in range(p):
                    matrice[i].append({
                        "value": 0,
                        "visible": False,
                        "flagged": False
                    }) # state: 0 = invisible | 1 = visible
            return matrice

        def addToAdj(m, x, y):

            container = [-1, 0, 1]
            for k in container:
                for h in container:
                    i = y+h
                    j = x+k
                    if ( 0 <= i < n and 0 <= j < p and m[i][j]["value"] >= 0):
                        m[i][j]["value"] += 1
            return m

        self.m = blankMatrice(self.n, self.p)

        while mineToPlace > 0:
            x, y = rdm(self.n), rdm(self.p)

            if i == None:
                i = -1
                j = -1


            if not ( ( y-1 <= i <= y+1) and ( x-1 <= j <= x+1) ):  # Quand la bombe est assez loin du curseur
                case = self.m[y][x]
                if case["value"] >= 0:
                    case["value"] = -1
                    self.m = addToAdj(self.m, x, y)

                    mineToPlace -= 1
コード例 #11
0
    def __init__(self, sym, level):
        self.sym = sym  # Operand used in the equation
        self.level = level  # The level of dificulty of the equation (1, 2 or 3)

        # Define the range of the 2 integer used in the equation
        if self.level == 1:
            self.a, self.b = 1, 10
        elif self.level == 2:
            self.a, self.b = 10, 20
        elif self.level == 3:
            self.a, self.b = 20, 30

        # Calls the random.randint() method to intialise 2 randoms
        # integers within a range described in the "__init__" method
        self.rdm_0, self.rdm_1 = rdm(self.a, self.b), rdm(self.a, self.b)

        # Defines the operator used in the equation
        if self.sym == "+":
            self.answer = self.rdm_0 + self.rdm_1
        elif self.sym == "-":
            self.answer = self.rdm_0 - self.rdm_1
コード例 #12
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
 def find_partner(self, pop):
     for person in pop.singles_list:
         age_gap = abs(person.age - self.age)
         if (person.area == self.area and person.gender != self.gender
                 and person != self and age_gap <= 10 and person.age > 18
                 and self.age > 18):
             # candidate lives in the same area and is single
             if rdm(100) > pop.partner_prob:
                 self.partner = person
                 person.partner = self
                 # print(self.full_name,"found",self.partner.full_name,"!!")
                 return True
     return False
コード例 #13
0
def pickRandom(l):
    if l is None:
        return None
    cnt = 0
    cur = l
    while cur:
        cnt += 1
        cur = cur.next
    idx = rdm(1, cnt)
    cnt = 0
    while cnt < idx:
        res = l
        l = l.next
        cnt += 1
    return res
コード例 #14
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
    def __init__(self, start_indiviudals=50):
        self.people = []
        self.singles_list = []
        self.names = names()
        self.id_seq = 1
        self.nr_people = 0

        self.partner_prob = 95
        self.birth_prob = 70

        g = ['F', 'M']
        for i in range(start_indiviudals):
            # Female is 0, Male is 1
            gender = rdm(2)
            first_name = self.names.get_randomFirst(gender)
            last_name = self.names.get_randomLast()
            age = rdm(15, 50)

            new_person = Individual(first_name, last_name, age, g[gender],
                                    self.id_seq, rdm(n_areas))
            self.people.append(new_person)
            self.singles_list.append(new_person)
            self.id_seq += 1
            self.nr_people += 1
コード例 #15
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
    def aging(self, factor=1):
        for person in self.people:
            person.age += factor
            if person.age > 20 and person not in self.singles_list:
                self.singles_list.append(person)
            if person.age > 80 and rdm(100) > 75:
                # Person dies
                self.people.remove(person)
                try:
                    self.singles_list.remove(person)
                except:
                    pass
                self.nr_people -= 1

                person.status = 'Dead'
                # print(person.full_name+'['+str(person.id)+'] has died...')
                if not isinstance(person.partner, str):
                    person.partner.partner = 'None'
コード例 #16
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
 def __init__(self,
              first_name,
              last_name,
              age,
              gender,
              id_seq1,
              area=rdm(n_areas)):
     self.id = id_seq1
     self.first_name = first_name
     self.last_name = last_name
     self.full_name = first_name + " " + last_name
     self.gender = gender
     self.age = age
     self.partner = 'None'
     self.area = area
     self.children = []
     self.nr_children = 0
     self.parent = []
     self.status = 'Alive'
コード例 #17
0
 def __take_kick(self, con=None):
     if con:
         self.conlist.append(con)
         self.finger -= 1
         return self.finger
     if self.status <= 0:
         if self.inilist(self.sqo, self.cif) != 1:
             raise RuntimeError('Cannot Initial the Pool!')
     self.ilock.acquire()
     if self.finger >= self.length:
         self.__batch_recovery()
         if self.__finger >= self.length:
             for i in xrange(5):
                 time.sleep(round(rdm(), 1))
                 if self.finger < self.length:
                     break
             if i >= 4:
                 self.ilock.release()
                 return None
     con = self.conlist.pop(0)
     self.finger += 1
     self.ilock.release()
     return con
コード例 #18
0
        print('\n1)Facile')
        print('2)Moyen')
        print('3)Difficile')
        print('4)Personnalise')
        Diff=input()

        #On essaye de convertir Diff en Integer. Si ca marche pas, c'est que
        #le joueur a mis des lettres, et ca lui dit
        try:
            Diff=int(Diff)
        except Exception as e:
            print('Il semblerait que tu n\'ais pas renseigne un nombre...')
            continue

        if int(Diff)==1:
            nombremyst=rdm(1,100)
            Max='100 : '
        elif int(Diff)==2:
            nombremyst=rdm(1,200)
            Max='200 : '
        elif int(Diff)==3:
            nombremyst=rdm(1,400)
            Max='400 : '
        elif int(Diff)==4:
            nbrmax=input('Quelle est la valeur maximale de ton nombre mystere ? ')
            nbrmax=nbrmax[:10]
            try:
                nbrmax=int(nbrmax)
            except Exception as e:
                print('Il semblerait que tu n\'ais pas renseigne un nombre...')
                continue
コード例 #19
0
    couleur=''
    chxcouleur = False
    while not chxcouleur:
        couleur=input('\nQuelle couleur choisis-tu ? Rouge/Noir ')
        couleur=fonctions.Minuscule(couleur)
        if couleur=='rouge' or couleur=='noir':
            chxcouleur=True
        else:
            print('La couleur specifiee n\'est pas valide !')

    coulleur=1
    if couleur=='rouge':
        coulleur=1
    else:
        coulleur=2
    croupier=rdm(1,2)
    if coulleur==croupier:
        Argent=Argent+mise*3
        print('\nGagne ! Tu as maintenant %s euros !'%Argent)
    else:
        boolfuite=False
        print('\nEt merde... T\'as perdu !!')

        while not boolfuite:
            fuite=input('\nTu veux tenter de te barrer ? (Oui/Non)')
            fuite=fonctions.Minuscule(fuite)
            if fuite!='oui' and fuite!='non':
                print('Ta reponse n\'est pas valide !')
            else:
                boolfuite=True
        if fuite=='oui':
コード例 #20
0
ファイル: 0010.py プロジェクト: Pacico/python
 def pointcolor():
     return(rdm(100,150),rdm(100,150),rdm(100,150))
コード例 #21
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
 def relocate(self, new_area=rdm(n_areas)):
     return new_area
コード例 #22
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
 def get_randomLast(self):
     return self.last_names[rdm(self.nr_Lnames)]
コード例 #23
0
ファイル: main.py プロジェクト: franciscoaze/WORLD
 def get_randomFirst(self, gender):
     # Female is 0, Male is 1
     if gender:
         return self.first_namesM[rdm(self.nr_Fnames)].title()
     else:
         return self.first_namesF[rdm(self.nr_Fnames)]
コード例 #24
0
        ret[by:by+h, bx:bx+w, c] * (1.0 - fore_alpha(fy, h, fx, w))

    return ret
    
    
    




if __name__ == '__main__':
    
    back = cv2.imread("land.jpg")
    fore = cv2.imread("phppg.png", -1)
    
    sh = fore.shape
    b  = np.full_like(fore, 255, np.uint8)
    bb = mix_image(b, fore, (0, 0))
    
    cv2.imshow('fore', bb)
    cv2.imshow('back', back)
    
    from random import random as rdm
    w, h, d = back.shape
    
    for i in range(10):
        back = mix_image(back, fore, (w * 1.2 * (rdm() - 0.2),h * 1.2 * (rdm() - 0.2)))
        
    cv2.imshow('mixed', back)
    cv2.imwrite('mixed.png', back)
    cv2.waitKey(0)
コード例 #25
0
        if verbose: print "Size ratio: " + str(size_ratio)
        if verbose: print '--------------------------------------------------'
        export.append({
            "id": assert_name,
            "pass": assert_pass,
            "str_to_test": str_to_test,
            "encrypted": encrypted,
            "decrypted": decrypted,
            "size_ratio": size_ratio
        })


test_quantity = int(sys.argv[1])
# test_quantity = 0
# print sys.argv

while test_quantity > 0:
    test_quantity -= 1
    assert_crypto(random_string(60), random_string(rdm(1, 10000)),
                  random_string(rdm(1, 10000)), False)

print "Tests results: " + str(asserts_total) + " total tests. " + str(
    asserts_passed) + ' passed, ' + str(asserts_failed) + ' failed.'
try:
    if sys.argv[3] == "--save":
        f = open('lastUnitTestsResults.json', 'w')
        f.write(json.dumps(export))
        f.close()
        print "Successfully exported as lastUnitTestsResults.json"
except:
    pass
コード例 #26
0
ファイル: mix_image.py プロジェクト: zuxfoucault/PyCV-time
    for c in range(0, 3):
        ret[by:by+h, bx:bx+w, c] = \
        fore[fy:fy+h, fx:fx+w, c] * fore_alpha(fy, h, fx, w) +\
        ret[by:by+h, bx:bx+w, c] * (1.0 - fore_alpha(fy, h, fx, w))

    return ret


if __name__ == '__main__':

    back = cv2.imread("land.jpg")
    fore = cv2.imread("phppg.png", -1)

    sh = fore.shape
    b = np.full_like(fore, 255, np.uint8)
    bb = mix_image(b, fore, (0, 0))

    cv2.imshow('fore', bb)
    cv2.imshow('back', back)

    from random import random as rdm
    w, h, d = back.shape

    for i in range(10):
        back = mix_image(back, fore,
                         (w * 1.2 * (rdm() - 0.2), h * 1.2 * (rdm() - 0.2)))

    cv2.imshow('mixed', back)
    cv2.imwrite('mixed.png', back)
    cv2.waitKey(0)
コード例 #27
0
 def pointcolor():
     return(rdm(100,150),rdm(100,150),rdm(100,150))
コード例 #28
0
def random_string(count):
    ret = ""
    while len(ret) < count:
        ret += allowed[rdm(0, len(allowed) - 1)]
    return ret
コード例 #29
0
vd_ball = sphere(display=scenev,pos=(0,0,0),radius = vrms/30, color=color.red)
x_axis = curve(display=scenev, pos=[(-1.4*vrms,0,0), (1.4*vrms,0,0)], radius=vrms/100)
y_axis = curve(display=scenev, pos=[(0,-1.4*vrms,0), (0,1.4*vrms,0)], radius=vrms/100)

vv = vector(0, 0, 0)

count=0

while true:
    t+=dt
    rate(10000)
    v_array+=q*E*dt/m
    pos_array+=v_array*dt
    outside=abs(pos_array)>=L
    if outside[N-1,0] or outside[N-1,1] or outside[N-1,2]:        atoms[N-1].retain=0
    pos_array[outside]=-pos_array[outside]
    vv+=vector(sum(v_array,0)/N)
    if int(t/dt)%2000==0:
        tau=t*N/(counter)
        print tau,vv/t*dt,q*E*tau/m
        vd_ball.pos=vv/t*dt
    for i in range(N):
        atoms_v[i].pos,atoms[i].pos=v_array[i],pos_array[i]
        if random.uniform(0,1)>prob:pass
        else:
            theta,phi=pi*rdm(),2*pi*rdm()
            v_array[i]=[vrms*sin(theta)*cos(phi), vrms*sin(theta)*sin(phi), vrms*cos(theta)];
            counter += 1
    atoms[N-1].retain=2000
コード例 #30
0
import random as rdm

print(rdm.random())

# 2
from random import randint as rdi, random as rdm

print(rdi(5, 89))

print(rdm())

# Podemos importar todas as funções de um módulo utilizando o *
from random import *
# import random -> diferente, pois quando importa * não é necessário usar o nome do modulo separado por ponto

print(random())

"""
# Costumamos a utilizar tuple para colocar múltiplos imports de um mesmo módulo
from random import (random as rdm, randint as rdi, shuffle as shf, choice as
                    chc)

print(rdm())
print(rdi(1, 55))

lista = [1, 2, 3, 4]
shf(lista)
print(lista)

print(chc('Hello World'))
コード例 #31
0
from random import random as rdm

random = lambda digit: int(rdm() * digit)

array = lambda size=10, digit=10: [random(digit) for e in range(size)]


def test(Sort):
    arr = array(20, 1000)
    Sort().sort(arr)
    print(Sort.__name__, arr, sep='\t')


class Sorter(object):
    def sort(arr):
        pass


# 冒泡排序
class BubbleSort(Sorter):
    def sort(self, arr):
        for i in range(len(arr) - 1, 0, -1):
            for j in range(0, i):
                if arr[j] > arr[j + 1]:
                    tmp = arr[j]
                    arr[j] = arr[j + 1]
                    arr[j + 1] = tmp


# 选择排序
class SelectSort(Sorter):
コード例 #32
0
ファイル: mix_image.py プロジェクト: ALitTLeQ/PyCV-time
        ret[by:by+h, bx:bx+w, c] * (1.0 - fore_alpha(fy, h, fx, w))

    return ret
    
    
    




if __name__ == '__main__':
    
    back = cv2.imread("land.jpg")
    fore = cv2.imread("phppg.png", -1)
    
    sh = fore.shape
    b  = np.full_like(fore, 255, np.uint8)
    bb = mix_image(b, fore, (0, 0))
    
    cv2.imshow('fore', bb)
    cv2.imshow('back', back)
    
    from random import random as rdm
    w, h, d = back.shape
    
    for i in range(10):
        back = mix_image(back, fore, (w * 1.2 * (rdm() - 0.2),h * 1.2 * (rdm() - 0.2)))
        
    cv2.imshow('mixed', back)
    cv2.imwrite('mixed.png', back)
    cv2.waitKey(0)