Beispiel #1
0
    def test_loop_3(self):
        w = dummy_world()

        city_dict = {
            0: city.City({"name": "City A"}),
            1: city.City({"name": "City B"}),
            2: city.City({"name": "City C"}),
            3: city.City({"name": "City D"}),
            4: city.City({"name": "City E"}),
            5: city.City({"name": "City F"}),
            6: city.City({"name": "City G"}),
            7: city.City({"name": "City H"}),
        }

        for k, v in city_dict.items():
            v.id = k
            v.team = k
            v.goods = {r: 0 for r in sad_rules.res_list}
            v.wealth = 300

            # City connections
        city_dict[0].connections = {1: 50, 3: 80}
        city_dict[1].connections = {0: 50, 2: 50}
        city_dict[2].connections = {1: 50, 3: 80}
        city_dict[3].connections = {0: 80, 2: 80}

        # Goods
        city_dict[0].goods["Grain"] = -100
        city_dict[3].goods["Grain"] = -100
        city_dict[2].goods["Grain"] = 150

        # city_dict[0].goods['Wool'] = -100
        # city_dict[1].goods['Wool'] = 100

        team_dict = {
            0: team.Team({"name": "Team A"}),
            1: team.Team({"name": "Team B"}),
            2: team.Team({"name": "Team C"}),
            3: team.Team({"name": "Team D"}),
        }

        for k, v in team_dict.items():
            v.techs = {}

            # 	Relations
            # ------------------------
        w._relations = {
            0: {
                1: {"visitor": 1, "host": 0, "border": team.border_states.index("Open"), "taxes": 8},
                2: {"visitor": 2, "host": 0, "border": team.border_states.index("Open"), "taxes": 8},
                3: {"visitor": 3, "host": 0, "border": team.border_states.index("Open"), "taxes": 12},
            },
            1: {
                0: {"visitor": 0, "host": 1, "border": team.border_states.index("Open"), "taxes": 8},
                2: {"visitor": 2, "host": 1, "border": team.border_states.index("Open"), "taxes": 8},
                3: {"visitor": 3, "host": 1, "border": team.border_states.index("Open"), "taxes": 12},
            },
            2: {
                1: {"visitor": 1, "host": 2, "border": team.border_states.index("Open"), "taxes": 8},
                0: {"visitor": 0, "host": 2, "border": team.border_states.index("Open"), "taxes": 8},
                3: {"visitor": 3, "host": 2, "border": team.border_states.index("Open"), "taxes": 12},
            },
            3: {
                1: {"visitor": 1, "host": 3, "border": team.border_states.index("Open"), "taxes": 8},
                2: {"visitor": 2, "host": 3, "border": team.border_states.index("Open"), "taxes": 8},
                0: {"visitor": 0, "host": 3, "border": team.border_states.index("Open"), "taxes": 8},
            },
        }

        w._cities = city_dict

        w.mass_get_checker.add("mass_get_team_techs")
        w.mass_get_checker.add("mass_get_team_deities")
        w.mass_get_checker.add("mass_get_team_evolutions")

        # Build caches
        w.tax_cache = {}
        for t1 in team_dict.keys():
            for t2 in team_dict.keys():
                if t1 == t2:
                    w.tax_cache[(t1, t2)] = 0
                else:
                    w.tax_cache[(t1, t2)] = w.get_taxes(t1, t2)

                    # Build a distance cache, K1 going to K2
        w.distance_cache = {}
        for k1, c1 in city_dict.items():
            for k2, c2 in city_dict.items():
                if k1 == k2:
                    w.distance_cache[(k1, k2)] = 0
                else:
                    if k2 in c1.connections:
                        w.distance_cache[(k1, k2)] = 1 + (sad_rules.distance_percentage * c1.connections[k2] / 100)

                        # Now for some testing, lets make sure we're getting the right buys/sells from the first loop
        sad_f.find_buys(w, city_dict, verbose=False)
        sad_f.approve_buys(w, city_dict, verbose=False)

        self.assertEqual([("Grain", [2, 1, 0], 100), ("Grain", [2, 3], 50)], city_dict[2].sells)

        # Now we need to actually execute the buys
        sad_f.execute_buys(w, city_dict, verbose=False)

        # Now make sure the goods/wealth are correct
        self.assertAlmostEqual(city_dict[0].wealth, 183.24, places=2)
        self.assertAlmostEqual(city_dict[1].wealth, 308.64, places=2)
        self.assertAlmostEqual(city_dict[2].wealth, 464.0, places=2)
        self.assertAlmostEqual(city_dict[3].wealth, 243.96, places=2)

        # City A has -15 grain because it couldn't afford the full 100, City C started with 110 so has +25 grain
        self.assertAlmostEqual(city_dict[0].goods["Grain"], 0, places=2)
        self.assertAlmostEqual(city_dict[1].goods["Grain"], 0, places=2)
        self.assertAlmostEqual(city_dict[2].goods["Grain"], 0, places=2)
        self.assertAlmostEqual(city_dict[3].goods["Grain"], -50, places=2)
Beispiel #2
0
    def ttest_loop_1(self):
        w = dummy_world()

        city_dict = {
            0: city.City({"name": "City A"}),
            1: city.City({"name": "City B"}),
            2: city.City({"name": "City C"}),
            3: city.City({"name": "City D"}),
        }

        for k, v in city_dict.items():
            v.id = k
            v.team = k
            v.goods = {r: 0 for r in sad_rules.res_list}
            v.wealth = 100

            # City connections
        city_dict[0].connections = {1: 50, 3: 80}
        city_dict[1].connections = {0: 50, 2: 50}
        city_dict[2].connections = {1: 50, 3: 80}
        city_dict[3].connections = {0: 80, 2: 80}

        # Goods
        city_dict[0].goods["Grain"] = -100
        city_dict[2].goods["Grain"] = 110

        # city_dict[0].goods['Wool'] = -100
        # city_dict[1].goods['Wool'] = 100

        team_dict = {
            0: team.Team({"name": "Team A"}),
            1: team.Team({"name": "Team B"}),
            2: team.Team({"name": "Team C"}),
            3: team.Team({"name": "Team D"}),
        }

        for k, v in team_dict.items():
            v.techs = {}

            # 	Relations
            # ------------------------
        w._relations = {
            0: {
                1: {"visitor": 1, "host": 0, "border": team.border_states.index("Open"), "taxes": 10},
                2: {"visitor": 2, "host": 0, "border": team.border_states.index("Open"), "taxes": 10},
                3: {"visitor": 3, "host": 0, "border": team.border_states.index("Open"), "taxes": 10},
            },
            1: {
                0: {"visitor": 0, "host": 1, "border": team.border_states.index("Open"), "taxes": 10},
                2: {"visitor": 2, "host": 1, "border": team.border_states.index("Open"), "taxes": 10},
                3: {"visitor": 3, "host": 1, "border": team.border_states.index("Open"), "taxes": 10},
            },
            2: {
                1: {"visitor": 1, "host": 2, "border": team.border_states.index("Open"), "taxes": 8},
                0: {"visitor": 0, "host": 2, "border": team.border_states.index("Open"), "taxes": 10},
                3: {"visitor": 3, "host": 2, "border": team.border_states.index("Open"), "taxes": 12},
            },
            3: {
                1: {"visitor": 1, "host": 3, "border": team.border_states.index("Open"), "taxes": 10},
                2: {"visitor": 2, "host": 3, "border": team.border_states.index("Open"), "taxes": 10},
                0: {"visitor": 0, "host": 3, "border": team.border_states.index("Open"), "taxes": 10},
            },
        }

        w._cities = city_dict

        w.mass_get_checker.add("mass_get_team_techs")
        w.mass_get_checker.add("mass_get_team_deities")
        w.mass_get_checker.add("mass_get_team_evolutions")

        # Build caches
        w.tax_cache = {}
        for t1 in team_dict.keys():
            for t2 in team_dict.keys():
                if t1 == t2:
                    w.tax_cache[(t1, t2)] = 0
                else:
                    w.tax_cache[(t1, t2)] = w.get_taxes(t1, t2)

                    # Build a distance cache, K1 going to K2
        w.distance_cache = {}
        for k1, c1 in city_dict.items():
            for k2, c2 in city_dict.items():
                if k1 == k2:
                    w.distance_cache[(k1, k2)] = 0
                else:
                    if k2 in c1.connections:
                        w.distance_cache[(k1, k2)] = 1 + (sad_rules.distance_percentage * c1.connections[k2] / 100)

                        # Now for some testing, lets make sure we're getting the right buys/sells from the first loop
        sad_f.find_buys(w, city_dict, verbose=False)

        self.assertEqual([("Grain", [2, 1, 0], 84.09097218016095)], city_dict[2].sells)