Esempio n. 1
0
def run(agent, exact):
    black, white = 0, 0
    history = []
    guess = agent.start()
    while True:
        black, white = evaluate(guess, exact)
        history.append((guess, (black, white)))
        print ' '.join(map(str, guess)) , ' -- ', black , white
        if (black, white)==(4, 0):
            break
        guess = agent.guess(guess, black, white)
    return len(history)
Esempio n. 2
0
def human_game():
    exact = random_hand()
    while True:
        in_ = raw_input()
        if in_=='end':
            print 'not valid'
            continue

        guess = [int(l) for l in in_ if l.isdigit()]
        if not valid(guess):
            print 'not valid'
            continue

        result = evaluate(guess, exact)
        if result==(4, 0):
            print 'right!', exact
            return

        print result
Esempio n. 3
0
def test_evaluate():
    assert evaluate((1,2,3,4), (2,1,3,6))==(1,2)
    assert evaluate((1,2,3,4), (1,2,3,4))==(4,0)
    assert evaluate((1,2,3,4), (5,6,7,8))==(0,0)
    assert evaluate((1,2,3,4), (2,3,5,6))==(0,2)
Esempio n. 4
0
 def genetic_choice_func(E, constraints):
     return min(E, key=lambda comb: mm.evaluate(constraints, comb))
Esempio n. 5
0
 def guess(self, number, black, white):
     self._pool = tuple(exact
                        for exact in self._pool
                        if evaluate(number, exact)==(black, white))
     return choice(self._pool)