# -*- coding:utf-8 -*-
#Filename:猜数字(改编)
import appuifw,e32
import random
#算法
class Bingle:
"""
Generate a random answer,and record guess times,and judge it
"""
A,B=(0,0) #Match falg
AttemptTimes=8 #Geuss times
Answer=[0,0,0,0] #The Answer
def BuildAnswer(self):
random.seed()
while 1:
digit = random.randint(0, 9999)
self.Answer[0]=digit/1000
self.Answer[1]=digit%1000/100
self.Answer[2]=digit%100/10
self.Answer[3]=digit%10
if self.Answer[0]!=self.Answer[1] and self.Answer[0]!=self.Answer[2] and self.Answer[0]!=self.Answer[3] and self.Answer[1]!=self.Answer[2] and self.Answer[1]!=self.Answer[3] and self.Answer[2]!=self.Answer[3]:
return
def __init__(self):
Answer=[0,0,0,0]
AttemptTimes=0
self.BuildAnswer()
def IsTryStringOK(self,TryString):
if TryString.isdigit() and len(TryString)==4:
if TryString[0]!=TryString[1] and TryString[0]!=TryString[2] and TryString[0]!=TryString[3] and TryString[1]!=TryString[2] and TryString[1]!=TryString[3] and TryString[2]!=TryString[3]:
return 1
return 0
def Judge(self,TryString):
for i in range(4):
if(TryString[i]==str(self.Answer[i])):
self.A=self.A+1
#Filename:猜数字(改编)
import appuifw,e32
import random
#算法
class Bingle:
"""
Generate a random answer,and record guess times,and judge it
"""
A,B=(0,0) #Match falg
AttemptTimes=8 #Geuss times
Answer=[0,0,0,0] #The Answer
def BuildAnswer(self):
random.seed()
while 1:
digit = random.randint(0, 9999)
self.Answer[0]=digit/1000
self.Answer[1]=digit%1000/100
self.Answer[2]=digit%100/10
self.Answer[3]=digit%10
if self.Answer[0]!=self.Answer[1] and self.Answer[0]!=self.Answer[2] and self.Answer[0]!=self.Answer[3] and self.Answer[1]!=self.Answer[2] and self.Answer[1]!=self.Answer[3] and self.Answer[2]!=self.Answer[3]:
return
def __init__(self):
Answer=[0,0,0,0]
AttemptTimes=0
self.BuildAnswer()
def IsTryStringOK(self,TryString):
if TryString.isdigit() and len(TryString)==4:
if TryString[0]!=TryString[1] and TryString[0]!=TryString[2] and TryString[0]!=TryString[3] and TryString[1]!=TryString[2] and TryString[1]!=TryString[3] and TryString[2]!=TryString[3]:
return 1
return 0
def Judge(self,TryString):
for i in range(4):
if(TryString[i]==str(self.Answer[i])):
self.A=self.A+1