예제 #1
0
    def from_dict(cls, d: Dict[str, Any]) -> 'Game':
        """Get class instance from dictionary."""
        configuration = GameConfiguration.from_dict(d["configuration"])
        initialization = GameInitialization.from_dict(d["initialization"])

        game = Game(configuration, initialization)
        for tx_dict in d["transactions"]:
            tx = Transaction.from_dict(tx_dict)
            game.settle_transaction(tx)

        return game
예제 #2
0
    def test_from_dict(self):
        """Test that conversion from dict works as expected."""
        version_id = "1"
        nb_agents = 10
        nb_goods = 10
        tx_fee = 2.5
        agent_pbk_to_name = {
            "tac_agent_0_pbk": "tac_agent_0",
            "tac_agent_1_pbk": "tac_agent_1",
            "tac_agent_2_pbk": "tac_agent_2",
            "tac_agent_3_pbk": "tac_agent_3",
            "tac_agent_4_pbk": "tac_agent_4",
            "tac_agent_5_pbk": "tac_agent_5",
            "tac_agent_6_pbk": "tac_agent_6",
            "tac_agent_7_pbk": "tac_agent_7",
            "tac_agent_8_pbk": "tac_agent_8",
            "tac_agent_9_pbk": "tac_agent_9",
        }
        good_pbk_to_name = {
            "tac_good_0_pbk": "tac_good_0",
            "tac_good_1_pbk": "tac_good_1",
            "tac_good_2_pbk": "tac_good_2",
            "tac_good_3_pbk": "tac_good_3",
            "tac_good_4_pbk": "tac_good_4",
            "tac_good_5_pbk": "tac_good_5",
            "tac_good_6_pbk": "tac_good_6",
            "tac_good_7_pbk": "tac_good_7",
            "tac_good_8_pbk": "tac_good_8",
            "tac_good_9_pbk": "tac_good_9",
        }

        expected_game_configuration = GameConfiguration(
            version_id, nb_agents, nb_goods, tx_fee, agent_pbk_to_name,
            good_pbk_to_name)
        actual_game_configuration = GameConfiguration.from_dict(
            expected_game_configuration.to_dict())

        assert actual_game_configuration == expected_game_configuration