adding ai_economist for modding

This commit is contained in:
2023-01-12 16:41:38 +01:00
parent 0479a4f6a4
commit f177f8f0ba
85 changed files with 19373 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
# Copyright (c) 2020, salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root
# or https://opensource.org/licenses/BSD-3-Clause
from .endogenous import endogenous_registry
from .landmarks import landmark_registry
from .resources import resource_registry

View File

@@ -0,0 +1,36 @@
# Copyright (c) 2020, salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root
# or https://opensource.org/licenses/BSD-3-Clause
from ai_economist.foundation.base.registrar import Registry
class Endogenous:
"""Base class for endogenous entity classes.
Endogenous entities are those that, conceptually, describe the internal state
of an agent. This provides a convenient way to separate physical entities (which
may exist in the world, be exchanged among agents, or are otherwise in principal
observable by others) from endogenous entities (such as the amount of labor
effort an agent has experienced).
Endogenous entities are registered in the "endogenous" portion of an agent's
state and should only be observable by the agent itself.
"""
name = None
def __init__(self):
assert self.name is not None
endogenous_registry = Registry(Endogenous)
@endogenous_registry.add
class Labor(Endogenous):
"""Labor accumulated through working. Included in all environments by default."""
name = "Labor"

View File

@@ -0,0 +1,88 @@
# Copyright (c) 2020, salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root
# or https://opensource.org/licenses/BSD-3-Clause
import numpy as np
from ai_economist.foundation.base.registrar import Registry
from ai_economist.foundation.entities.resources import resource_registry
class Landmark:
"""Base class for Landmark entity classes.
Landmark classes describe the entities that exist exclusively in the environment
world. In other words, they represent entities that should not be included in an
agent's inventory and are only observable through observations from the
spatial world.
Landmark classes describe the following properties:
ownable: If each instance of the landmark belongs to an agent. For example, a
"House" is ownable and belongs to the agent that constructs it whereas
"Water" is not ownable.
solid: If the landmark creates a physical barrier to movement (that is,
if agents are prevented from occupying cells with the landmark).
Importantly, if the landmark is ownable, the agent that owns a given
landmark can occupy its cell even if the landmark is solid.
"""
name = None
color = None # array of RGB values [0 - 1]
ownable = None
solid = True # Solid = Cannot be passed through
# (unless it is owned by the agent trying to pass through)
def __init__(self):
assert self.name is not None
assert self.color is not None
assert self.ownable is not None
# No agent can pass through this landmark
self.blocking = self.solid and not self.ownable
# Only the agent that owns this landmark can pass through it
self.private = self.solid and self.ownable
# This landmark does not belong to any agent and it does not inhibit movement
self.public = not self.solid and not self.ownable
landmark_registry = Registry(Landmark)
# Registering each collectible resource's source block
# allows treating source blocks in a specific way
for resource_name in resource_registry.entries:
resource = resource_registry.get(resource_name)
if not resource.collectible:
continue
@landmark_registry.add
class SourceBlock(Landmark):
"""Special Landmark for generating resources. Not ownable. Not solid."""
name = "{}SourceBlock".format(resource.name)
color = np.array(resource.color)
ownable = False
solid = False
@landmark_registry.add
class House(Landmark):
"""House landmark. Ownable. Solid."""
name = "House"
color = np.array([220, 20, 220]) / 255.0
ownable = True
solid = True
@landmark_registry.add
class Water(Landmark):
"""Water Landmark. Not ownable. Solid."""
name = "Water"
color = np.array([50, 50, 250]) / 255.0
ownable = False
solid = True

View File

@@ -0,0 +1,84 @@
# Copyright (c) 2020, salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root
# or https://opensource.org/licenses/BSD-3-Clause
import numpy as np
from ai_economist.foundation.base.registrar import Registry
class Resource:
"""Base class for Resource entity classes.
Resource classes describe entities that can be a part of an agent's inventory.
Resources can also be a part of the world as collectible entities: for each
Resource class with Resource.collectible=True, a complementary
ResourceSourceBlock Landmark class will be created in landmarks.py. For each
collectible resource in the environment, the world map will include a resource
source block channel (representing landmarks where collectible resources are
generated) and a resource channel (representing locations where collectible
resources have generated).
"""
name = None
color = None # array of RGB values [0 - 1]
collectible = None # Is this something that exists in the world?
# (versus something that can only be owned)
craft_recp = None # dict of recource name and amount
craft_labour_base= 0.0
def __init__(self):
assert self.name is not None
assert self.color is not None
assert self.collectible is not None
resource_registry = Registry(Resource)
@resource_registry.add
class Wood(Resource):
"""Wood resource. collectible."""
name = "Wood"
color = np.array([107, 143, 113]) / 255.0
collectible = True
@resource_registry.add
class Stone(Resource):
"""Stone resource. collectible."""
name = "Stone"
color = np.array([241, 233, 219]) / 255.0
collectible = True
@resource_registry.add
class Coin(Resource):
"""Coin resource. Included in all environments by default. Not collectible."""
name = "Coin"
color = np.array([229, 211, 82]) / 255.0
collectible = False
@resource_registry.add
class RawGem(Resource):
"""Raw Gem that can be processed further"""
name = "Raw_Gem"
color = np.array([241, 233, 219]) / 255.0
collectible = True
@resource_registry.add
class Gem(Resource):
"""Proccesed Gem. Craftable."""
name = "Gem"
color = np.array([241, 233, 219]) / 255.0
collectible = False
craft_recp= {"Raw_Gem": 1}
craft_labour_base= 1