World

Items

Items

Here are defined abstract classes for items, tools and item-stacks

class Item(item_id: int, name: str, required_tools: Optional[list] = None)

Bases: object

Item are to represent objects that could be present in an inventory

item_id

Unique item identification number.

Type

int

name

Item name.

Type

str

max_stack

Maximum number of this item per stack.

Type

int

class ItemStack(item: crafting.world.items.Item, size: int = 1)

Bases: crafting.world.items.Item

ItemStack are to represent stackable objects that could be present in an inventory.

item

Item object that will be stacked.

Type

Item

item_id

Unique item identification number.

Type

int

name

Item name.

Type

str

required_tools

List of tools that can be used to gather the item. If None (Default), the item can be gathered without requirement.

size

Number of items in stack.

Type

int

class Tool(item_id: int, name: str, required_tools: Optional[list] = None)

Bases: crafting.world.items.Item

Tool are to represent special usable items.

item_id

Unique item identification number.

Type

int

name

Tool name.

Type

str

max_stack

Maximum number of tools per stack.

Type

int

use(item: Optional[crafting.world.items.Item] = None)List[crafting.world.items.ItemStack]

Use the tool on the (optional) given item.

Parameters

item – Item to use the tool on.

Returns

The list of found item stacks.

Recipes

Recipe are to represent transformations of items.

Recipes are initiated using an input-output design but they can also affect and be affected by the Zone in which the craft is done.

class Recipe(recipe_id: int, inputs: Optional[List[crafting.world.items.ItemStack]] = None, outputs: Optional[List[crafting.world.items.ItemStack]] = None, needed_properties: Optional[dict] = None, added_properties: Optional[dict] = None)

Bases: object

Recipe are to represent transformations of items.

Recipes are initiated using an input-output design but they can also affect and be affected by the Zone in which the craft is done.

recipe_id

Unique recipe identification number.

Type

int

inputs

List of consumed items.

Type

list of ItemStack

outputs

List of created items.

Type

list of ItemStack

needed_properties

Zone properties needed for the craft to be done.

Type

dict

added_properties

Zone properties modified by the craft if successful.

Type

dict

has_enought(inventory: crafting.player.inventory.Inventory)

Check if the inventory contains the necessary materials

Parameters

inventory – The inventory to check.

Returns

True if the inventory has enough materials, False otherwise.

has_properties(zone: crafting.world.zones.Zone)

Check if the zone has the necessary propreties

Parameters

zone – The zone to check.

Returns

True if the zone has the necessary propreties, False otherwise.

can_craft(inventory: crafting.player.inventory.Inventory, zone: crafting.world.zones.Zone)bool

Check if the craft can be performed

Parameters
  • inventory – Inventory to transform.

  • zone – Zone in which the crafting is done.

Returns

True if the craft can be performed, False otherwise.

craft(inventory: crafting.player.inventory.Inventory, zone: crafting.world.zones.Zone)bool

Use the recipe using an inventory in a zone

Parameters
  • inventory – Inventory to transform.

  • zone – Zone in which the crafting is done.

Returns

True if successful, False otherwise

World

A World stiches together every non-player parts of the environment.

class World(items: List[crafting.world.items.Item], recipes: List[crafting.world.recipes.Recipe], zones: List[crafting.world.zones.Zone], searchable_items: Optional[List[crafting.world.items.Item]] = None, resources_path: Optional[str] = None, font_path: Optional[str] = None)

Bases: object

A crafting World containing items, recipes and zones.

action(action_type: str, identification: int)int

Return the action_id from action_type and identification.

action_from_id(action_id: int)str

Describe the action_id effects.

zone_id_from_observation(observation)

Return the player zone from an observation.

properties_from_observation(observation)

Return the zone proprietes from an observation.

get_all_options()Dict[str, crafting.option.Option]

Return a dictionary of handcrafted options to get each item, zone and property.

get_requirements_graph()networkx.classes.digraph.DiGraph

Build the world requirements graph.

Returns

The world requirements graph as a networkx DiGraph.

draw_requirements_graph(ax)

Draw the requirement graph on a given Axes.

Parameters

ax – Axes to draw on.

Returns

The Axes with requirements_graph drawn on it.

Zones

Zone

Gives an abstract way of doing spacialization. The Zones have special properties for finding or crafting items.

class Zone(zone_id: int, name: str, items: List[crafting.world.items.Item], properties: Optional[dict] = None)

Bases: object

Zones are to represent abstract places in the world.

Zone have specific properties that can change how items can be gathered and how craftings are done.

By default

zone_id

Unique zone identification number.

Type

int

name

Zone name.

Type

str

items

Dictionary associating an item_id with the tools needed to gather it and how efficient it is.

Type

dict

properties

Dictionary of properties.

Type

dict

can_search_for(item: crafting.world.items.Item, tool: Optional[crafting.world.items.Tool] = None)bool

Check if the item can be found using a tool

Parameters
  • item – The item to look for.

  • tool – The tool to use in search.

Returns

True if the item can be found, False otherwise.

search_for(item: crafting.world.items.Item, tool: Optional[crafting.world.items.Tool] = None)List[crafting.world.items.ItemStack]

Searches for the given item using a tool

Parameters
  • item – The item to look for.

  • tool – The tool to use.

Returns

The found item stacks.