Ejemplo n.º 1
0
    def perform_test(self, status_dict):
        """Test that the heuristic on leafs is consistent with the utility"""

        # Build models
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        # Simulate a final status
        status.turn = status.max_turns

        heuristic_tuple = self.heuristic.heuristic(status)
        utility_tuple = utility(status)

        # Check that heuristic and utility are consistent
        for i in range(4):
            for j in range(4):
                if utility_tuple[i] > utility_tuple[j]:
                    self.assertGreater(heuristic_tuple[i], heuristic_tuple[j])
                elif utility_tuple[i] == utility_tuple[j]:
                    self.assertAlmostEqual(
                        heuristic_tuple[i],
                        heuristic_tuple[j]
                    )
                else:
                    self.assertLess(heuristic_tuple[i], heuristic_tuple[j])
Ejemplo n.º 2
0
    def test_utility_value_yupgvpr5_2400(self):
        """Test the utility value on yupgvpr5 2400"""

        # Build models
        status_dict = get_status_samples_dict()["yupgvpr5"][2400]
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        utility_tuple = utility(status)

        self.assertEqual(utility_tuple, (8, -8, -8, 8))
Ejemplo n.º 3
0
    def test_utility_value_nztclzmi_0(self):
        """Test the utility value on nztclzmi 0"""

        # Build models
        status_dict = get_status_samples_dict()["nztclzmi"][0]
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        utility_tuple = utility(status)

        self.assertEqual(utility_tuple, (0, 0, 0, 0))
Ejemplo n.º 4
0
    def perform_test(self, status_dict):
        """Test that the utility is a zero sum tuple"""

        # Build models
        map_obj = Map(status_dict["game"]["board"]["tiles"])
        status = Status(status_dict["game"], map_obj)

        utility_tuple = utility(status)

        self.assertAlmostEqual(
            sum(utility_tuple), 0,
            msg="Utility is {utility}, but the sum is non-zero: {sum}".format(
                utility=utility_tuple,
                sum=sum(utility_tuple)
            )
        )