Skip to main content

A Way to Reward Agent Which Constructed Voxel World (Minecraft) by Shannon Entropy

· 11 min read
Wei Ji

Evaluate resources

We can evaluate scarcity of resources intuitively; the more rare it is, the more value it is. But scarcity of economics are measured by supply and demand, it can't be a unit which had clearly definition. We can get probability of resources generated on map, but the probability wasn't enough to measured agent, it needed been processed additionally.

Shannon Entropy and Shannon Information

The nature of Shannon entropy is mathematics quantity which well known "uncertainty of phenomenon".1

H(X)=E[I(X)]=E[ln(P(X))]\mathrm H (X) = \mathrm{E}[\mathrm{I}(X)] = \mathrm{E}[-\ln(\mathrm{P}(X))]

and II is Shannon Information, it be defined as:

I(X)=log2P(X)I(X) = - \log_2 \mathrm{P}(X)

We can noted the meaning of log2pi-\log_2 p_i is "the lower the probability of an event, the greater the information carried when the event occurs", so Shannon entropy is expected value of Shannon information, can be express by:

H(X)=ipilog2pi\mathrm H (X) = - \sum_i p_i \log_2 p_i

Formula of Crafting

To describe pattern of items changes easily, which caused by crafting or another mechanism in the game, I borrow the form of chemical equation:

aX+bYPcZaX + bY \xrightarrow[P]{} cZ

a,b,ca,b,c:amount of materials or products X,YX,Y:materials, items would vanished after crafting process ZZ:products PP:the path of crafting, item(s) won't vanished after crafting process

Information of Items

The nature of Minecraft World are a bunch of digital data, so were reasonably considered it as a string of information, and quantify it as Shannon Entropy or Information. For a block which status was uncertain, the value is:

H(X)=E(I)=ipilog2pi\mathrm H (X) = \mathrm{E} ( \mathrm{I}) = - \sum_i p_i \log_2 p_i

and pip_i is probability of (some type of) block generated in map, therefore we can get information of block of certain type by:

Ix=log2pxI_x = -\log_2 p_x

Information of Crafting

It could calculation entropy of nature resources by probability of generated in the map, but most of items are obtained by crafting in Minecraft, when I mention "crafting" are meaning "the mechanism can be expressed by formula of crafting in the game". Need to gain entropy of non-nature items through calculation.

Let do a crafting example:

X+YWZX + Y \xrightarrow[W]{} Z

X,Y,WX,Y,W represents three different types of blocks, can be treated as three randomly independently event, and their probability of exists in map are pX,pY,pWp_X, p_Y, p_W, so we can get probability of event ZZ happened was multiplied by probabilities, also was summing by information of probabilities:

IZ=log2(pXpYpW)=log2pXlog2pYlog2pW=IX+IY+IW\begin{align} I_Z &= -\log_2(p_X p_Y p_W) \\ &= -\log_2 p_X -\log_2 p_Y -\log_2 p_W \\ &= I_X + I_Y + I_W \end{align}

The Ratio Between Material(s) and Product(s)

When the ratio isn't 1, total number of items would changed.

mXPnYmX \xrightarrow[P]{} nY

and:

HY=mnHXH_Y = \frac{m}{n}H_X

Crafting Path

The item(s) won't vanished as crafting path in the process, so:

XWYΔI=IW\begin{array}{l} X \xrightarrow[W]{} Y & \Delta I = I_W \end{array}

Multiple Crafting Path

When there are multiple path to gain item(s), it can been treats as a parallel system, therefore, the information of products can be expressed by:

I=log2[1i(1pi)]I = -\log_2 [1 - \prod_i(1-p_i)]

The Items with Zero Entropy

The probability of items dropped by monster, are affected by probability of monster generation, and its not related space, but time, so:

HΔt=0=limp0+plogp=0H |_{\Delta t = 0}= -\lim_{p \rightarrow0^+} p\log p = 0

or consider it could been generated in infinity time, the probability of generation is 1, therefor:

Ht=log(1)=0H |_{t \rightarrow \infty} = -\log(1) = 0

Information of Environment

We must define "system", when quantified information of system, so need to defined a range of space and how many blocks or items contained in the space.There are 3 kind of definition of system which common been used under below:

  1. Complete System
    • Blocks, items in inventory block, item entity dropped and items in player inventory, which contained in a limited space.
  2. Block System
    • Blocks and items in inventory block, which contained in a limited space.
  3. Player System
    • Items in the player inventory.

We can quantify entropy of system through rules has been created, and intervening variables can been gain by making statistics on map. We can expect the entropy of environment would changed through behavior of agent, therefore those changes could be one of index of evaluated the agent.

Table of Items Information

The following information evaluation value is for reference only, there are not included every items in the game, and process are not very rigorous. The goal is demonstrated the theory of this article, anyone are interested can finished the table by self.

Natual Resource

Using Cuberite 1.7.X-linux642 to generate map and making statistics by plugin3. There were sampling 10 times, and remove map file to generate new seed every time. To simplify data, I merged yellow flower and red flower, removed flowing water, flowing lava, cobblestone, torch, flame, monster spawner, chest and dead bush, replace them by air.

BlockCountProbabilityInformationEntropy
Air1514640790.75060490.41387440.3106562
Bedrock7882240.00390628.00002870.0312495
Brown Mushroom6480.000003218.24842480.0000586
Cactus110.000000124.12884320.0000013
Clay87900.000043614.48662740.0006310
Coal Ore3459620.00171459.18802080.0157526
Cobweb19980.000009916.62393400.0001646
Diamond Ore196290.000097313.32757580.0012964
Dirt23478570.01163526.42536170.0747603
Double Plant142420.000070613.79041070.0009733
Fence85430.000042314.52774780.0006151
Flower40140.000019915.61744990.0003107
Gold Ore436970.000216512.17302820.0026360
Grass4716460.00233738.74092990.0204303
Gravel5345010.00264888.56044170.0226750
Iron Ore3953360.00195928.99555500.0176237
Lapis Lazuli Ore176900.000087713.47762840.0011815
Leaves3827790.00189699.04212270.0171522
Lily Pad1220.000000620.65753750.0000125
Obsidian23900.000011816.36547990.0001938
Rail25280.000012516.28449410.0002040
Red Mushroom9740.000004817.66049690.0000852
Redstone Ore1601170.000793510.29950790.0081725
Sand2722200.00134909.53386130.0128615
Sandstone1098880.000544610.84260050.0059045
Snow30330.000015016.02174510.0002408
Still Lava1580880.000783410.31790650.0080834
Still Water32819080.01626405.94217150.0966437
Stone408120300.20225072.30578370.4663463
Sugar Canes410.000000222.23072280.0000045
Tallgrass668180.000331111.56032570.0038279
Vines11790.000005817.38492680.0001016
Wood Plank127620.000063213.94870800.0008822
Wood556140.000275611.82511440.0032591

Products

Wood Plank

Wood4 Wood Plank\text{Wood} \xrightarrow[]{} 4 \text{ Wood Plank} IWP=14IW=0.2511.8=2.95\begin{align} I_{WP} &= \frac1{4} I_{W} = 0.25 \cdot 11.8\\ &= 2.95 \end{align}

Crafting Table

4 Wood PlankCrafting Table4 \text{ Wood Plank} \xrightarrow[]{} \text{Crafting Table} ICT=4IWP=42.95=11.8\begin{align} I_{CT} &= 4 I_{WP} = 4 \cdot 2.95 \\ &= 11.8 \end{align}

Stick

2 Wood Plank4 Stick2 \text{ Wood Plank} \xrightarrow[]{} 4 \text{ Stick} IS=24IWP=0.52.95=1.475\begin{align} I_{S} &= \frac{2}{4} I_{WP} = 0.5 \cdot 2.95 \\ &= 1.475 \end{align}

Wooden Pickaxe

3 Wood Plank+2 StickCrafting Table Wooden Pickaxe3 \text{ Wood Plank} + 2 \text{ Stick} \xrightarrow[\text{Crafting Table}]{} \text{ Wooden Pickaxe} IWPickaxe=3IWPlank+2IS+ICT=32.95+21.475+11.8=23.6\begin{align} I_{\text{WPickaxe}} &= 3 I_{\text{WPlank}} + 2 I_{S} + I_{CT}\\ &= 3 \cdot 2.95 + 2 \cdot 1.475 + 11.8\\ &= 23.6 \end{align}

Cobblestone

To simplify calculation, there's not consider crafting path with another type of pickaxe except wooden one.

 Stone Wooden Pickaxe Cobblestone\text{ Stone } \xrightarrow[\text{Wooden Pickaxe}]{} \text{ Cobblestone} IC=IS+IWP=2.31+23.6=25.91\begin{align} I_{C} &= I_{S} + I_{WP} \\ &= 2.31 + 23.6 \\ &= 25.91 \end{align}

Furnace

8 Cobblestone Crafting Table Furnace8\text{ Cobblestone } \xrightarrow[\text{Crafting Table}]{} \text{ Furnace} IF=8IC+ICT=825.91+11.8=219.08\begin{align} I_{F} &= 8I_{C} + I_{CT} \\ &= 8 \cdot 25.91 + 11.8 \\ &= 219.08 \end{align}

Stone Pickaxe

3 Cobblestone+2 StickCrafting Table Stone Pickaxe3 \text{ Cobblestone} + 2 \text{ Stick} \xrightarrow[\text{Crafting Table}]{} \text{ Stone Pickaxe} ISP=3IC+2IS+ICT=325.91+21.475+11.8=92.48\begin{align} I_{\text{SP}} &= 3 I_{\text{C}} + 2 I_{S} + I_{CT}\\ &= 3 \cdot 25.91 + 2 \cdot 1.475 + 11.8\\ &= 92.48 \end{align}

Iron Ore Item

To simplify calculation, there's not consider crafting path with another type of pickaxe except stone one.

 Iron Ore Stone Pickaxe Iron Ore Item\text{ Iron Ore } \xrightarrow[\text{Stone Pickaxe}]{} \text{ Iron Ore Item} IIOI=IIO+ISP=9.00+92.48=101.48\begin{align} I_{IOI} &= I_{IO} + I_{SP} \\ &= 9.00 + 92.48 \\ &= 101.48 \end{align}

Coal

To demonstrate calculation of parallel system, there's consider crafting path with wooden and stone pickaxe.

 Coal Ore Wooden(Stone) Pickaxe Coal\text{ Coal Ore } \xrightarrow[\text{Wooden(Stone) Pickaxe}]{} \text{ Coal} IC1=ICO+IWP=9.18+23.6=32.78\begin{align} I_{C1} &= I_{CO} + I_{WP} \\ &= 9.18 + 23.6 \\ &= 32.78 \end{align} IC2=ICO+ISP=9.18+92.48=101.66\begin{align} I_{C2} &= I_{CO} + I_{SP} \\ &= 9.18 + 92.48 \\ &= 101.66 \end{align} p1=2I1=232.78=1.355928353111010p2=2I2=2101.66=2.496264731271031p=1(1p1)(1p2)=1.3559287026511010p_1 = 2^{-I_1} = 2^{-32.78} = 1.35592835311 \cdot 10^{-10} \\ p_2 = 2^{-I_2} = 2^{-101.66} = 2.49626473127 \cdot 10^{-31} \\ p = 1 - (1-p_1)(1-p_2) = 1.355928702651 \cdot 10^{-10} IC=log2p=32.78I_C = -\log_2 p = 32.78

Iron Ingot

 Iron Ore Item+18 CoalFurnace Iron Ingot\text{ Iron Ore Item} + \frac1{8} \text{ Coal} \xrightarrow[\text{Furnace}]{} \text{ Iron Ingot} III=IIOI+18IC+IF=101.48+0.12532.78+219.08=324.6575\begin{align} I_{II} &= I_{IOI} + \frac1{8} I_{C} + I_{F} \\ &= 101.48 + 0.125 \cdot 32.78 + 219.08\\ &= 324.6575 \end{align}

The Table

It is summary those value are calculated or mention in this article, and just as I said, this article didn't calculated all information of items in the game, therefore the table are unfinished:

Block/ItemInformation (bit)Block/ItemInformation (bit)
Iron Ingot324.66Lapis Lazuli Ore13.48
Furnace219.08Diamond Ore13.33
Iron Ore Item101.48Gold Ore12.17
Stone Pickaxe92.48Wood11.83
Coal32.78Crafting Table11.80
Cobblestone25.91Tallgrass11.56
Cactus24.13Sandstone10.84
Wooden Pickaxe23.60Still Lava10.32
Sugar Canes22.23Redstone Ore10.30
Lily Pad20.66Sand9.53
Brown Mushroom18.25Coal Ore9.19
Red Mushroom17.66Leaves9.04
Vines17.38Iron Ore9.00
Cobweb16.62Grass8.74
Obsidian16.37Gravel8.56
Rail16.28Bedrock8.00
Snow16.02Dirt6.43
Flower15.62Still Water5.94
Fence14.53Wood Plank2.95
Clay14.49Stone2.31
Wood Plank13.95Stick1.48
Double Plant13.79Air0.41

Conclusion

Just like James Lovelock said4:

I’d look for an entropy reduction, since this must be a general characteristic of life.

We can quantify extropy which agent created by reform the environment, to measue the policy:

ΔHπ,t=HoHπ,tπ=argminπΔHπ,t\Delta H_{\pi,t} = H_o - H_{\pi,t} \\ \pi^* = \arg \min_{\pi} \Delta H_{\pi,t}
tags: The Key Of Huanche

Footnotes

  1. 信息熵是什么? - 知乎. (返朴). Retrieved 2020-05-31, from https://www.zhihu.com/question/22178202/answer/667876061

  2. Releases · cuberite/cuberite. (cuberite). Retrieved 2020-05-31, from https://github.com/cuberite/cuberite/releases/download/1.7EOL/Cuberite-linux64.tar.gz

  3. FlySkyPie/cuberite-block-counter: To make statistics of blocks. Retrieved 2020-05-31, from https://github.com/FlySkyPie/cuberite-block-counter

  4. Lovelock, James (1979). GAIA – A New Look at Life on Earth. Oxford University Press. ISBN 978-0-19-286218-1.