예제 #1
0
    def testFunction_getCombinationsWithAllRightColor(self):
        evaluator = Evaluator(Colorcombination([0, 1, 2, 3]))
        attempts = Attempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        with self.assertRaises(ValueError):
            attempts.getCombinationWithAllRightColors()

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 2, 3]),
                                              Evaluation(1, 3, True))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 2, 3]), True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 6, 5, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 2, 3]), True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 3, 2]),
                                              Evaluation(0, 4, True))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 2, 3]), True)

        attempts.clearAttempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 3, 2]),
                                              Evaluation(0, 4, True))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 3, 2]), True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 3, 2]), True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 2, 3]),
                                              Evaluation(1, 3, True))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 3, 2]), True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 6, 5, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationWithAllRightColors() == Colorcombination(
                [0, 1, 3, 2]), True)
예제 #2
0
    def testFunction_getLastAttempt(self):
        evaluator = Evaluator(Colorcombination([0, 1, 2, 3]))
        attempts = Attempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 5, 6, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getLastAttempt() == evaluatedCombi, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getLastAttempt() == evaluatedCombi, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 7, 0]),
                                              Evaluation(1, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getLastAttempt() == evaluatedCombi, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getLastAttempt() == evaluatedCombi, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 2, 0]),
                                              Evaluation(1, 2, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getLastAttempt() == evaluatedCombi, True)
예제 #3
0
    def testFunction_addEvaluatedCombination(self):
        evaluator = Evaluator(Colorcombination([0, 1, 2, 3]))
        attempts = Attempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 5, 6, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getNumberOfAttempts() == 1, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getNumberOfAttempts() == 2, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 7, 0]),
                                              Evaluation(1, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getNumberOfAttempts() == 3, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getNumberOfAttempts() == 4, True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 2, 0]),
                                              Evaluation(1, 2, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getNumberOfAttempts() == 5, True)

        attempts.clearAttempts()
        self.assertEqual(attempts.getNumberOfAttempts() == 0, True)
예제 #4
0
 def __init__(self, lengthOfGuess, numberOfColors, masterCombination,
              maxNumberOfAttempts):
     self.__gameIsRunning = False
     self.__validator = Validator(lengthOfGuess, numberOfColors)
     self.__masterCombination = masterCombination
     self.__validator.validateCombination(masterCombination)
     self.__evaluator = Evaluator(masterCombination)
     self.attempts = Attempts()
     self.__maxNumberOfAttempts = maxNumberOfAttempts
     self.__validator.validateMaxNumberOfAttempts(maxNumberOfAttempts)
     #self.player = HumanPlayer()
     #self.player = NPC_random(lengthOfGuess, numberOfColors, self.attempts)
     #self.player = NPC_hardCoded(lengthOfGuess, numberOfColors, self.attempts)
     self.player = NPC_csp(lengthOfGuess, numberOfColors, self.attempts)
예제 #5
0
    def testFunction_checkIfCombinationExist(self):
        attempts = Attempts()

        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 0, 1])),
            False)
        attempts.addEvaluatedCombination(
            EvaluatedCombination(Colorcombination([0, 0, 1]),
                                 Evaluation(0, 0, False)))
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 0, 1])),
            True)

        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 0])),
            False)
        attempts.addEvaluatedCombination(
            EvaluatedCombination(Colorcombination([0, 1, 0]),
                                 Evaluation(1, 0, False)))
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 0])),
            True)

        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 1])),
            False)
        attempts.addEvaluatedCombination(
            EvaluatedCombination(Colorcombination([0, 1, 1]),
                                 Evaluation(1, 1, False)))
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 1])),
            True)

        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 0, 0])),
            False)
        attempts.addEvaluatedCombination(
            EvaluatedCombination(Colorcombination([1, 0, 0]),
                                 Evaluation(1, 0, False)))
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 0, 0])),
            True)

        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 0, 0])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 0, 1])),
            True)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 0])),
            True)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 1])),
            True)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 0, 0])),
            True)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 0, 1])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 1, 0])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([1, 1, 1])),
            False)

        attempts.clearAttempts()
        attempts.addEvaluatedCombination(
            EvaluatedCombination(Colorcombination([0, 2, 3, 1]),
                                 Evaluation(1, 0, False)))
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 2, 3, 1])),
            True)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 2, 1, 3])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 3, 2, 1])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 3, 1, 2])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 2, 3])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([0, 1, 3, 2])),
            False)
        self.assertEqual(
            attempts.checkIfCombinationExist(Colorcombination([2, 0, 3, 1])),
            False)
예제 #6
0
    def testFunction_getCombinationsWithNoRightColor(self):
        evaluator = Evaluator(Colorcombination([0, 1, 2, 3]))
        attempts = Attempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(attempts.getCombinationsWithNoRightColor() == [],
                         True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 5, 6, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 7, 0]),
                                              Evaluation(1, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 2, 5]),
                                              Evaluation(0, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 6, 5, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7]),
                Colorcombination([4, 6, 5, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 6, 5, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7]),
                Colorcombination([4, 6, 5, 7])
            ], True)

        evaluatedCombi = EvaluatedCombination(Colorcombination([0, 1, 2, 3]),
                                              Evaluation(0, 4, True))
        attempts.addEvaluatedCombination(evaluatedCombi)
        self.assertEqual(
            attempts.getCombinationsWithNoRightColor() == [
                Colorcombination([4, 5, 6, 7]),
                Colorcombination([4, 6, 5, 7])
            ], True)
예제 #7
0
    def testError_validateForNoObviousRrrors(self):
        sud = Validator(4, 8)
        attempts = Attempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 5, 6, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if not debriefing:
            self.fail()

        attempts.clearAttempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 7, 0]),
                                              Evaluation(1, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 6, 7, 0]),
                                              Evaluation(1, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 2, 0]),
                                              Evaluation(1, 2, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([4, 5, 6, 7]),
                                              Evaluation(0, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([1, 2, 5, 0]),
                                              Evaluation(3, 0, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if not debriefing:
            self.fail()

        attempts.clearAttempts()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 7, 0]),
                                              Evaluation(1, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([1, 3, 2, 0]),
                                              Evaluation(3, 1, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if debriefing:
            self.fail()

        evaluatedCombi = EvaluatedCombination(Colorcombination([5, 1, 2, 0]),
                                              Evaluation(1, 2, False))
        attempts.addEvaluatedCombination(evaluatedCombi)
        debriefing = sud.validateForNoObviousErrors(attempts)
        if not debriefing:
            self.fail()