Exemple #1
0
	def addNew(self):

		self.syncKey = True

		self.answer = maths.weightedRandomIndex([0.5, 0.5]) # 0.5 for 0 i.e wrong answer
		leftid = maths.randint(0,3)
		leftnameid = maths.randint(0,3)

		if self.answer == 0:
			rightid_pdf = popList(leftid, 0.2) + [0.4] + popList(3-leftid, 0.2) # 0.4 chance left color = right color
			rightid = leftnameid
			while rightid == leftnameid:
				rightid = maths.weightedRandomIndex(rightid_pdf)
			rightnameid = maths.randint(0,3)
		else:
			rightid = leftnameid
			rightnameid_pdf = popList(leftid, 0.2) + [0.4] + popList(3-leftid, 0.2)
			rightnameid = maths.weightedRandomIndex(rightnameid_pdf)

		self.rightBtn.label.text = self.colornames[rightnameid]
		self.rightBtn.label.color = self.colors[rightid] + [255]
		self.leftBtn.label.text = self.colornames[leftnameid]
		self.leftBtn.label.color = self.colors[leftid] + [255]

		self.syncKey = False
    def genExpression(self, size):
        '''
		generates an expression
		'''
        oprPDF = [0.35, 0.20, 0.30, 0.15]
        numRange = [(1, 9), (9, 15), (15, 25)]
        numPDF = [0.5, 0.4, 0.1]

        n1 = round(maths.weightedRandomRange(numPDF, numRange))
        if size == 1:
            return str(n1)
        if size > 2:
            print('Not implemented')
        # size = 2
        if maths.isPrime(n1):
            opr = self.operators[maths.weightedRandomIndex(
                [0.4, 0.25, 0.33, 0.02])]
        else:
            opr = self.operators[maths.weightedRandomIndex(oprPDF)]
        n2 = maths.getSecondOperand(n1,
                                    opr,
                                    multiplyLimit=200,
                                    numPDF=numPDF,
                                    numRange=numRange)

        return str(n1) + ' ' + opr + ' ' + str(n2)
Exemple #3
0
	def addNew(self):

		self.syncKey = True
		#     [5, 6, 7, 8, 9, 10]
		pdf = [0.3, 0.4, 0.15, 0.05, 0.05, 0.05]
		wlen = maths.weightedRandomIndex(pdf) + 5
		pos = randint(0, len(self.data[wlen])-1)
		word = self.data[wlen][pos]
		scrabbled = scrabbleWord(word)
		while word == scrabbled:
			scrabbled = scrabbleWord(word)
		self.answer = randint(0,3)
		poss = [pos]
		leftPoint = 0 if (pos-5 < 0) else pos-5
		rightPoint = len(self.data[wlen]) - 1 if (pos + 5 > len(self.data[wlen]) - 1) else pos + 5

		for i in range(4):
			if i == self.answer:
				self.choices[i].label.text = word.upper()
			else:
				pos = poss[0]
				while pos in poss or checkAnagram(self.data[wlen][pos], word) == True:
					pos = randint(leftPoint, rightPoint)
				self.choices[i].label.text = self.data[wlen][pos].upper()
				poss += [pos]


		self.lblQuestion.text = scrabbled.upper()
		self.syncKey = False
Exemple #4
0
    def genExpression(self, size):
        '''
		Generate the expression
		'''
        oprPDF = [0.35, 0.20, 0.30, 0.15]
        numRange = [(1, 9), (9, 19), (19, 35)]
        numPDF = [0.5, 0.35, 0.15]

        if size == 2:
            exp = self.genExpression2(oprPDF)
        elif size == 3:
            exp1 = self.genExpression2(oprPDF)
            ans1 = eval(''.join(str(i) for i in exp1))
            opr = self.operators[maths.weightedRandomIndex(
                [0.4, 0.2, 0.3, 0.1])]
            exp2 = maths.getSecondOperand(ans1,
                                          opr,
                                          multiplyLimit=150,
                                          numPDF=numPDF,
                                          numRange=numRange)
            exp = ['('] + exp1 + [')'] + [opr, exp2]
        elif size == 4:
            exp1 = self.genExpression2(oprPDF)
            exp2 = self.genExpression2(oprPDF)
            exp = ['('] + exp1 + [')'] + ['+'] + ['('] + exp2 + [')']

        expStr = ' '.join(str(i) for i in exp)
        return (expStr, round(eval(expStr)))
    def addNew(self):

        self.syncKey = True
        #     [5, 6, 7, 8, 9, 10]
        pdf = [0.3, 0.4, 0.15, 0.05, 0.05, 0.05]
        wlen = maths.weightedRandomIndex(pdf) + 5
        pos = randint(0, len(self.data[wlen]) - 1)
        word = self.data[wlen][pos]
        scrabbled = scrabbleWord(word)
        while word == scrabbled:
            scrabbled = scrabbleWord(word)
        self.answer = randint(0, 3)
        poss = [pos]
        leftPoint = 0 if (pos - 5 < 0) else pos - 5
        rightPoint = len(self.data[wlen]) - 1 if (
            pos + 5 > len(self.data[wlen]) - 1) else pos + 5

        for i in range(4):
            if i == self.answer:
                self.choices[i].label.text = word.upper()
            else:
                pos = poss[0]
                while pos in poss or checkAnagram(self.data[wlen][pos],
                                                  word) == True:
                    pos = randint(leftPoint, rightPoint)
                self.choices[i].label.text = self.data[wlen][pos].upper()
                poss += [pos]

        self.lblQuestion.text = scrabbled.upper()
        self.syncKey = False
Exemple #6
0
	def addNew(self):

		self.syncKey = True

		self.answer = maths.weightedRandomIndex([0.5, 0.5])

		if self.answer == 1:
			col = self.previous
			shape = self.previous_shape
			while shape == self.previous_shape:
				shape = maths.randint(0, 3)
		else:
			col = self.previous
			while col == self.previous:
				col = maths.randint(0, 3)
			shape = maths.randint(0, 3)

		cshape = self.shapes[shape]

		self.previous = col
		self.previous_shape = shape
		self.curshape.delete()

		if cshape == 'square':
			self.curshape = draw.square(self.width//2 - 75, 300, 150, color=self.colors[col])
		elif cshape == 'hexagon':
			self.curshape = draw.hexagon(self.width//2 - 75, 300, 75, color=self.colors[col])
		elif cshape == 'triangle':
			self.curshape = draw.triangle(self.width//2 - 75, 300, 150, color=self.colors[col])
		else:
			self.curshape = draw.circle(self.width//2 - 75, 300, 75, color=self.colors[col])
		self.curshape.draw()

		self.syncKey = False
    def genInequality(self):
        '''
		Generates a random inequality for this game
		'''
        chComparator = maths.weightedRandomIndex([0.2, 0.4, 0.4])
        leftSize = maths.weightedRandomIndex([0.15, 0.85]) + 1
        rightSize = maths.weightedRandomIndex([0.15, 0.85]) + 1

        lhs = self.genExpression(leftSize)
        rhs = self.genExpression(rightSize)

        ans = eval('(' + lhs + ')' + self.comparators[chComparator] + '(' +
                   rhs + ')')

        return (lhs + '  ' +
                self.comparators[chComparator].replace('==', '=') + '  ' + rhs,
                ans)
Exemple #8
0
	def genInequality(self):
		'''
		Generates a random inequality for this game
		'''
		chComparator = maths.weightedRandomIndex([0.2, 0.4, 0.4])
		leftSize = maths.weightedRandomIndex([0.15, 0.85]) + 1
		rightSize = maths.weightedRandomIndex([0.15, 0.85]) + 1

		lhs = self.genExpression(leftSize)
		rhs = self.genExpression(rightSize)

		ans = eval( '(' + lhs + ')' + 
					self.comparators[chComparator] +
					'(' + rhs + ')' 
				)

		return (lhs + '  ' + self.comparators[chComparator].replace('==', '=') + '  ' + rhs , ans)
Exemple #9
0
	def addNew(self):
		self.syncKey = True

		size = maths.weightedRandomIndex([0.55, 0.35, 0.10]) + 2 # expr of size 2,3 or 4
		exp = self.genExpression(size)

		self.lblExp.text = exp[0]
		self.lblExp.draw()
		self.answer = str(exp[1])

		self.syncKey = False
Exemple #10
0
	def genExpression2(self, oprPDF):
		index = maths.weightedRandomIndex(oprPDF)
		numRange = [(1,9) , (9,19) , (19,35)]
		numPDF = [0.5, 0.35, 0.15]
		n1 = round(maths.weightedRandomRange(numPDF, numRange))
		opr = self.operators[index]
		n2 = maths.getSecondOperand(n1, opr, multiplyLimit = 100, numPDF = [0.2, 0.4, 0.3], numRange = numRange)
		if opr == '+':
			numPDF = [0.2, 0.4, 0.4]
			n1 = round(maths.weightedRandomRange(numPDF, numRange))

		return [n1, opr, n2]
Exemple #11
0
	def genExpression(self, size):
		'''
		generates an expression
		'''
		oprPDF = [0.35, 0.20, 0.30, 0.15]
		numRange = [(1,9) , (9,15) , (15,25)]
		numPDF = [0.5, 0.4, 0.1]

		n1 = round(maths.weightedRandomRange(numPDF, numRange))
		if size == 1:
			return str(n1)
		if size > 2:
			print('Not implemented')
		# size = 2
		if maths.isPrime(n1):
			opr = self.operators[ maths.weightedRandomIndex([0.4, 0.25, 0.33, 0.02]) ]
		else:
			opr = self.operators[ maths.weightedRandomIndex(oprPDF) ]
		n2 = maths.getSecondOperand(n1, opr, multiplyLimit = 200, numPDF = numPDF, numRange = numRange)

		return str(n1) + ' ' + opr + ' ' + str(n2)
Exemple #12
0
    def addNew(self):
        self.syncKey = True

        size = maths.weightedRandomIndex([0.55, 0.35, 0.10
                                          ]) + 2  # expr of size 2,3 or 4
        exp = self.genExpression(size)

        self.lblExp.text = exp[0]
        self.lblExp.draw()
        self.answer = str(exp[1])

        self.syncKey = False
Exemple #13
0
    def genExpression2(self, oprPDF):
        index = maths.weightedRandomIndex(oprPDF)
        numRange = [(1, 9), (9, 19), (19, 35)]
        numPDF = [0.5, 0.35, 0.15]
        n1 = round(maths.weightedRandomRange(numPDF, numRange))
        opr = self.operators[index]
        n2 = maths.getSecondOperand(n1,
                                    opr,
                                    multiplyLimit=100,
                                    numPDF=[0.2, 0.4, 0.3],
                                    numRange=numRange)
        if opr == '+':
            numPDF = [0.2, 0.4, 0.4]
            n1 = round(maths.weightedRandomRange(numPDF, numRange))

        return [n1, opr, n2]
Exemple #14
0
    def addNew(self):

        self.syncKey = True

        self.answer = maths.weightedRandomIndex([0.5, 0.5])

        if self.answer == 1:
            col = self.previous
            shape = self.previous_shape
            while shape == self.previous_shape:
                shape = maths.randint(0, 3)
        else:
            col = self.previous
            while col == self.previous:
                col = maths.randint(0, 3)
            shape = maths.randint(0, 3)

        cshape = self.shapes[shape]

        self.previous = col
        self.previous_shape = shape
        self.curshape.delete()

        if cshape == 'square':
            self.curshape = draw.square(self.width // 2 - 75,
                                        300,
                                        150,
                                        color=self.colors[col])
        elif cshape == 'hexagon':
            self.curshape = draw.hexagon(self.width // 2 - 75,
                                         300,
                                         75,
                                         color=self.colors[col])
        elif cshape == 'triangle':
            self.curshape = draw.triangle(self.width // 2 - 75,
                                          300,
                                          150,
                                          color=self.colors[col])
        else:
            self.curshape = draw.circle(self.width // 2 - 75,
                                        300,
                                        75,
                                        color=self.colors[col])
        self.curshape.draw()

        self.syncKey = False
Exemple #15
0
	def genExpression(self, size):
		'''
		Generate the expression
		'''
		oprPDF = [0.35, 0.20, 0.30, 0.15]
		numRange = [(1,9) , (9,19) , (19,35)]
		numPDF = [0.5, 0.35, 0.15]

		if size == 2:
			exp = self.genExpression2(oprPDF)
		elif size == 3:
			exp1 = self.genExpression2(oprPDF)
			ans1 = eval(''.join(str(i) for i in exp1))
			opr = self.operators[ maths.weightedRandomIndex([0.4, 0.2, 0.3, 0.1]) ]
			exp2 = maths.getSecondOperand(ans1, opr, multiplyLimit = 150, numPDF = numPDF, numRange = numRange)
			exp = ['('] + exp1 + [')'] + [opr, exp2]
		elif size == 4:
			exp1 = self.genExpression2(oprPDF)
			exp2 = self.genExpression2(oprPDF)
			exp = ['('] + exp1 + [')'] + ['+'] + ['('] + exp2 + [')']

		expStr = ' '.join( str(i) for i in exp )
		return (expStr, round(eval(expStr)))