Last active
May 12, 2020 14:27
-
-
Save kenwebb/915111ff5ecefae96a5699d3e09002c2 to your computer and use it in GitHub Desktop.
Two avatars and a stick in a 1d gridcell cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue May 12 2020 10:24:37 GMT-0400 (Eastern Daylight Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Two avatars and a stick in a 1d gridcell cycle | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 915111ff5ecefae96a5699d3e09002c2 | |
Keywords: template | |
My Notes | |
-------- | |
May 8, 2020 | |
Two avatars and a stick walk into a bar and order a round of Coronas ... Ooops, wrong workbook ... | |
This is a model I conceived of in February. | |
I prototyped it on February 21 using Graohviz, and described it to Jen. | |
To review how to use Xholon subtrees: | |
--------- | |
https://gist.github.com/search?q=BehaviorsST | |
The Graphviz .gv text | |
--------------------- | |
// There are 20 gridcells, numbered 0 to 19 | |
// Avatar A is stationary, is located in gridcell 4, and watches for Avatar B | |
// Avatar B is initially located in gridcell 0, and moves one gridcell to the right each timestep | |
// Gridcell 15 comntains a Stick | |
graph G { | |
graph [rankdir=LR, size = "9,9"] | |
node [shape=box] | |
0--1--2--3--4--5--6--7--8--9--10--11--12--13--14--15--16--17--18--19--0 | |
0 [label="0\nB", style=dashed] | |
4 [label="4\nA", style=dotted] | |
15 [label="15\nS", style="setlinewidth(8)"] | |
} | |
TODO | |
---- | |
refactor | |
- use true subtree behviors (where the code is hidden inside a subtree object) | |
- set things up so it's easier to use this workbook as a template to write other similar apps | |
energy | |
- each Avatar should have an energy attribute | |
- an Avatar initially has an energy value of 100 | |
- each timestep, an Avatar: | |
- decreases its energy value by 1, plus | |
- decreases its energy value by 1 for each behavior it executes | |
- ex: each timestep A and B each lose 1 energy because of the passage of time | |
- ex: Avatar A has 1 behavior throughout the simulation, so each timmestep it loses 1 additional energy (total 2) | |
- ex: Avatar B initially has 1 bevavior, but when B gives it an additional behavior, then it has 2 behaviors and then loses a total of 3 energy per timestep | |
source of energy | |
- possibly have a cloneable food source instead of Stick | |
EnergyManager | |
- implement this | |
provide a more expansive environment in another workbook | |
- multiple 1d rows or lanes, where each lane is a separate experiment | |
- many additional JavaScript behaviors to choose from | |
- each is a named script with a DefaultContent | |
functions | |
- does it make sense for the Avatar behaviors to in some way be "functions" as in FP | |
Cycle | |
- Xholon offers various "sibling" options for grids, for example: | |
- Gsc Cycle | |
- Gsw Wheel | |
- where "s" signifies a Sibling neighborhood | |
- these options are untested, and don't work yet with JavaScript and XML | |
- something like the following should work, but doesn't yet work: | |
<GridGenerator rows="1" cols="10" gridType="Gsc" names="Space,FieldRow,CycleCell" columnColor="171c8f" gridViewerParams="PhysicalSystem/Space,20,Test Viewer,true" cellsCanSupplyOwnColor="true"/> | |
References | |
---------- | |
(1) http://webgraphviz.com/ | |
useful for testing the Graphviz graph | |
I used this site to generate the SVG for this workbook | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<CycleCell/> | |
<Stick/> | |
<!-- Avatar behaviors --> | |
<AvaA_Beh1 superClass="script"/> | |
<AvaB_Beh1 superClass="script"/> | |
<AvaB_Beh2 superClass="script"/> | |
<EnergyManager/> <!-- TODO implement this --> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<AvaA_Beh1><DefaultContent><![CDATA[ | |
// Avatar A has a goal: I need a Stick, but I can't move to look for one. | |
// possible states | |
const ST_INIT = 0; | |
const ST_GAVE_BEH_TO_B = 1; | |
const ST_HAVE_STICK = 2; | |
var ava, state, ts, beh = { | |
postConfigure() { | |
ava = this.cnode.parent().parent(); | |
state = ST_INIT; | |
ts = 0; | |
}, | |
act() { | |
var tss = Number($wnd.xh.param("TimeStep")); // do I need this? | |
if (tss > ts) { | |
if ((state != ST_HAVE_STICK) && ava.next() && (ava.next().xhc().name() == "Avatar")) { | |
// get avaB to either look for a stick, or give me the stick that it has found | |
var avaB = ava.next(); | |
var stick = avaB.last(); | |
if (stick && stick.xhc().name() == "Stick") { | |
ava.println("A has taken " + "the stick" + " from B"); | |
ava.append(stick.remove()); | |
state = ST_HAVE_STICK; | |
} | |
else if (state == ST_INIT) { | |
// give the other Avatar a behavior to look for and take a Stick | |
ava.println("A is giving B a new behavior"); | |
state = ST_GAVE_BEH_TO_B; | |
avaB.append('<BehaviorsST><AvaB_Beh2/></BehaviorsST>'); | |
} | |
} | |
} | |
} | |
} | |
//# sourceURL=AvaA_Beh1.js | |
]]></DefaultContent></AvaA_Beh1> | |
<AvaB_Beh1><DefaultContent><![CDATA[ | |
var ava, ts, beh = { | |
postConfigure() { | |
ava = this.cnode.parent().parent(); | |
ts = 0; | |
}, | |
act() { | |
var tss = Number($wnd.xh.param("TimeStep")); | |
if (tss > ts) { | |
ava.action("next;"); | |
ts = tss; | |
} | |
} | |
} | |
//# sourceURL=AvaB_Beh1.js | |
]]></DefaultContent></AvaB_Beh1> | |
<AvaB_Beh2><DefaultContent><![CDATA[ | |
var ava, beh = { | |
postConfigure() { | |
ava = this.cnode.parent().parent(); | |
}, | |
act() { | |
ava.action("if xpath(Stick) take *stick;"); | |
} | |
} | |
//# sourceURL=AvaB_Beh2.js | |
]]></DefaultContent></AvaB_Beh2> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<GridGenerator rows="1" cols="20" gridType="Gmt" names="Space,FieldRow,CycleCell" columnColor="171c8f" gridViewerParams="PhysicalSystem/Space,20,Test Viewer,true" cellsCanSupplyOwnColor="true"/> | |
<!-- Avatar B is the system avatar, so it does not need to be defined here --> | |
<Avatar roleName="A"> <!-- Avatar A is stationary, is located in gridcell 4, and watches for Avatar B --> | |
<BehaviorsST> | |
<AvaA_Beh1/> | |
</BehaviorsST> | |
</Avatar> | |
<Stick/> | |
</PhysicalSystem> | |
<PhysicalSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
$wnd.xh.param("TimeStepInterval","500"); // "500" "100" | |
$wnd.xh.param("AppM","true"); | |
if ($wnd.xh.html["selectTab"]) { | |
$wnd.xh.html.selectTab(0); // display contents of the "out" tab | |
} | |
var akm = `{ | |
"SHIFT":"true", | |
"NOSCROLL":"true", | |
"UP":"go port0;", | |
"DOWN":"go port2;", | |
"LEFT":"prev;", | |
"RIGHT":"next;", | |
"a":"appear", | |
"D":"drop", | |
"d":"drop first", | |
"i":"inventory", | |
"l":"look", | |
"L":"look all", | |
"M":"build <Animate\\tselection='#xhgraph'/>;", | |
"p":"pause", | |
"r":"start", | |
"s":"step", | |
" ":"step", | |
"T":"take", | |
"t":"take nextprev", | |
"v":"vanish", | |
"w":"who;where;", | |
"z":"param transcript toggle;", | |
"?":"help keymap", | |
"/":"help commands" | |
}`; | |
$wnd.xh.avatarKeyMap(akm); | |
// Avatar B initialization | |
// Avatar B is the system avatar | |
// Avatar B is initially located in gridcell 0, and moves one gridcell to the right each timestep | |
// Avatar B has a goal: I like to walk | |
var avaB = $wnd.xh.avatar(); | |
avaB.action('enter;enter space_;enter;enter;become this role B;appear;param transcript true;'); | |
avaB.action('param meteor false;'); | |
avaB.append('<BehaviorsST><AvaB_Beh1></AvaB_Beh1></BehaviorsST>'); | |
avaB.energy = 100; | |
// Avatar A initialization | |
var avaA = this.xpath("../Avatar"); | |
avaA.action('who;enter space_;enter;enter;next;next;next;next;param transcript true;'); | |
avaA.color("green"); | |
avaA.energy = 100; | |
// Stick initialization | |
var stick = this.xpath("../Stick"); | |
stick.color("brown"); | |
var cell = stick.xpath("../Space/FieldRow/CycleCell[16]"); | |
cell.append(stick.remove()); | |
//# sourceURL=PhysicalSystembehavior.js | |
]]></PhysicalSystembehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="648pt" height="28pt" viewBox="0.00 0.00 648.00 28.16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<g id="graph1" class="graph" transform="scale(0.365688 0.365688) rotate(0) translate(4 73)"> | |
<title>G</title> | |
<polygon fill="white" stroke="white" points="-4,5 -4,-73 1769,-73 1769,5 -4,5"></polygon> | |
<!-- 0 --> | |
<g id="node1" class="node"><title>0</title> | |
<polygon fill="red" stroke="black" stroke-dasharray="5,2" points="54,-43.6019 0,-43.6019 0,-2.3981 54,-2.3981 54,-43.6019"></polygon> | |
<text text-anchor="middle" x="27" y="-27.2" font-family="Times,serif" font-size="14.00">0</text> | |
<text text-anchor="middle" x="27" y="-10.4" font-family="Times,serif" font-size="14.00">B</text> | |
</g> | |
<!-- 1 --> | |
<g id="node3" class="node"><title>1</title> | |
<polygon fill="none" stroke="black" points="144,-65 90,-65 90,-29 144,-29 144,-65"></polygon> | |
<text text-anchor="middle" x="117" y="-42.8" font-family="Times,serif" font-size="14.00">1</text> | |
</g> | |
<!-- 0--1 --> | |
<g id="edge2" class="edge"><title>0--1</title> | |
<path fill="none" stroke="black" d="M54.4029,-30.2008C65.6421,-33.266 78.7152,-36.8314 89.919,-39.887"></path> | |
</g> | |
<!-- 2 --> | |
<g id="node4" class="node"><title>2</title> | |
<polygon fill="none" stroke="black" points="234,-66 180,-66 180,-30 234,-30 234,-66"></polygon> | |
<text text-anchor="middle" x="207" y="-43.8" font-family="Times,serif" font-size="14.00">2</text> | |
</g> | |
<!-- 1--2 --> | |
<g id="edge3" class="edge"><title>1--2</title> | |
<path fill="none" stroke="black" d="M144.403,-47.3C155.642,-47.4278 168.715,-47.5763 179.919,-47.7036"></path> | |
</g> | |
<!-- 3 --> | |
<g id="node5" class="node"><title>3</title> | |
<polygon fill="none" stroke="black" points="324,-66 270,-66 270,-30 324,-30 324,-66"></polygon> | |
<text text-anchor="middle" x="297" y="-43.8" font-family="Times,serif" font-size="14.00">3</text> | |
</g> | |
<!-- 2--3 --> | |
<g id="edge4" class="edge"><title>2--3</title> | |
<path fill="none" stroke="black" d="M234.403,-48C245.642,-48 258.715,-48 269.919,-48"></path> | |
</g> | |
<!-- 4 --> | |
<g id="node6" class="node"><title>4</title> | |
<polygon fill="green" stroke="black" stroke-dasharray="1,5" points="414,-69.6019 360,-69.6019 360,-28.3981 414,-28.3981 414,-69.6019"></polygon> | |
<text text-anchor="middle" x="387" y="-53.2" font-family="Times,serif" font-size="14.00">4</text> | |
<text text-anchor="middle" x="387" y="-36.4" font-family="Times,serif" font-size="14.00">A</text> | |
</g> | |
<!-- 3--4 --> | |
<g id="edge5" class="edge"><title>3--4</title> | |
<path fill="none" stroke="black" d="M324.403,-48.3C335.642,-48.4278 348.715,-48.5763 359.919,-48.7036"></path> | |
</g> | |
<!-- 5 --> | |
<g id="node7" class="node"><title>5</title> | |
<polygon fill="none" stroke="black" points="504,-67 450,-67 450,-31 504,-31 504,-67"></polygon> | |
<text text-anchor="middle" x="477" y="-44.8" font-family="Times,serif" font-size="14.00">5</text> | |
</g> | |
<!-- 4--5 --> | |
<g id="edge6" class="edge"><title>4--5</title> | |
<path fill="none" stroke="black" d="M414.403,-49C425.642,-49 438.715,-49 449.919,-49"></path> | |
</g> | |
<!-- 6 --> | |
<g id="node8" class="node"><title>6</title> | |
<polygon fill="none" stroke="black" points="594,-67 540,-67 540,-31 594,-31 594,-67"></polygon> | |
<text text-anchor="middle" x="567" y="-44.8" font-family="Times,serif" font-size="14.00">6</text> | |
</g> | |
<!-- 5--6 --> | |
<g id="edge7" class="edge"><title>5--6</title> | |
<path fill="none" stroke="black" d="M504.403,-49C515.642,-49 528.715,-49 539.919,-49"></path> | |
</g> | |
<!-- 7 --> | |
<g id="node9" class="node"><title>7</title> | |
<polygon fill="none" stroke="black" points="684,-67 630,-67 630,-31 684,-31 684,-67"></polygon> | |
<text text-anchor="middle" x="657" y="-44.8" font-family="Times,serif" font-size="14.00">7</text> | |
</g> | |
<!-- 6--7 --> | |
<g id="edge8" class="edge"><title>6--7</title> | |
<path fill="none" stroke="black" d="M594.403,-49C605.642,-49 618.715,-49 629.919,-49"></path> | |
</g> | |
<!-- 8 --> | |
<g id="node10" class="node"><title>8</title> | |
<polygon fill="none" stroke="black" points="774,-67 720,-67 720,-31 774,-31 774,-67"></polygon> | |
<text text-anchor="middle" x="747" y="-44.8" font-family="Times,serif" font-size="14.00">8</text> | |
</g> | |
<!-- 7--8 --> | |
<g id="edge9" class="edge"><title>7--8</title> | |
<path fill="none" stroke="black" d="M684.403,-49C695.642,-49 708.715,-49 719.919,-49"></path> | |
</g> | |
<!-- 9 --> | |
<g id="node11" class="node"><title>9</title> | |
<polygon fill="none" stroke="black" points="864,-67 810,-67 810,-31 864,-31 864,-67"></polygon> | |
<text text-anchor="middle" x="837" y="-44.8" font-family="Times,serif" font-size="14.00">9</text> | |
</g> | |
<!-- 8--9 --> | |
<g id="edge10" class="edge"><title>8--9</title> | |
<path fill="none" stroke="black" d="M774.403,-49C785.642,-49 798.715,-49 809.919,-49"></path> | |
</g> | |
<!-- 10 --> | |
<g id="node12" class="node"><title>10</title> | |
<polygon fill="none" stroke="black" points="954,-67 900,-67 900,-31 954,-31 954,-67"></polygon> | |
<text text-anchor="middle" x="927" y="-44.8" font-family="Times,serif" font-size="14.00">10</text> | |
</g> | |
<!-- 9--10 --> | |
<g id="edge11" class="edge"><title>9--10</title> | |
<path fill="none" stroke="black" d="M864.403,-49C875.642,-49 888.715,-49 899.919,-49"></path> | |
</g> | |
<!-- 11 --> | |
<g id="node13" class="node"><title>11</title> | |
<polygon fill="none" stroke="black" points="1044,-67 990,-67 990,-31 1044,-31 1044,-67"></polygon> | |
<text text-anchor="middle" x="1017" y="-44.8" font-family="Times,serif" font-size="14.00">11</text> | |
</g> | |
<!-- 10--11 --> | |
<g id="edge12" class="edge"><title>10--11</title> | |
<path fill="none" stroke="black" d="M954.403,-49C965.642,-49 978.715,-49 989.919,-49"></path> | |
</g> | |
<!-- 12 --> | |
<g id="node14" class="node"><title>12</title> | |
<polygon fill="none" stroke="black" points="1134,-67 1080,-67 1080,-31 1134,-31 1134,-67"></polygon> | |
<text text-anchor="middle" x="1107" y="-44.8" font-family="Times,serif" font-size="14.00">12</text> | |
</g> | |
<!-- 11--12 --> | |
<g id="edge13" class="edge"><title>11--12</title> | |
<path fill="none" stroke="black" d="M1044.4,-49C1055.64,-49 1068.72,-49 1079.92,-49"></path> | |
</g> | |
<!-- 13 --> | |
<g id="node15" class="node"><title>13</title> | |
<polygon fill="none" stroke="black" points="1224,-67 1170,-67 1170,-31 1224,-31 1224,-67"></polygon> | |
<text text-anchor="middle" x="1197" y="-44.8" font-family="Times,serif" font-size="14.00">13</text> | |
</g> | |
<!-- 12--13 --> | |
<g id="edge14" class="edge"><title>12--13</title> | |
<path fill="none" stroke="black" d="M1134.4,-49C1145.64,-49 1158.72,-49 1169.92,-49"></path> | |
</g> | |
<!-- 14 --> | |
<g id="node16" class="node"><title>14</title> | |
<polygon fill="none" stroke="black" points="1314,-67 1260,-67 1260,-31 1314,-31 1314,-67"></polygon> | |
<text text-anchor="middle" x="1287" y="-44.8" font-family="Times,serif" font-size="14.00">14</text> | |
</g> | |
<!-- 13--14 --> | |
<g id="edge15" class="edge"><title>13--14</title> | |
<path fill="none" stroke="black" d="M1224.4,-49C1235.64,-49 1248.72,-49 1259.92,-49"></path> | |
</g> | |
<!-- 15 --> | |
<g id="node17" class="node"><title>15</title> | |
<polygon fill="brown" stroke="black" stroke-width="8" points="1404,-69.6019 1350,-69.6019 1350,-28.3981 1404,-28.3981 1404,-69.6019"></polygon> | |
<text text-anchor="middle" x="1377" y="-53.2" font-family="Times,serif" font-size="14.00">15</text> | |
<text text-anchor="middle" x="1377" y="-36.4" font-family="Times,serif" font-size="14.00">S</text> | |
</g> | |
<!-- 14--15 --> | |
<g id="edge16" class="edge"><title>14--15</title> | |
<path fill="none" stroke="black" d="M1314.4,-49C1325.64,-49 1338.72,-49 1349.92,-49"></path> | |
</g> | |
<!-- 16 --> | |
<g id="node18" class="node"><title>16</title> | |
<polygon fill="none" stroke="black" points="1494,-66 1440,-66 1440,-30 1494,-30 1494,-66"></polygon> | |
<text text-anchor="middle" x="1467" y="-43.8" font-family="Times,serif" font-size="14.00">16</text> | |
</g> | |
<!-- 15--16 --> | |
<g id="edge17" class="edge"><title>15--16</title> | |
<path fill="none" stroke="black" d="M1404.4,-48.7C1415.64,-48.5722 1428.72,-48.4237 1439.92,-48.2964"></path> | |
</g> | |
<!-- 17 --> | |
<g id="node19" class="node"><title>17</title> | |
<polygon fill="none" stroke="black" points="1584,-65 1530,-65 1530,-29 1584,-29 1584,-65"></polygon> | |
<text text-anchor="middle" x="1557" y="-42.8" font-family="Times,serif" font-size="14.00">17</text> | |
</g> | |
<!-- 16--17 --> | |
<g id="edge18" class="edge"><title>16--17</title> | |
<path fill="none" stroke="black" d="M1494.4,-47.7C1505.64,-47.5722 1518.72,-47.4237 1529.92,-47.2964"></path> | |
</g> | |
<!-- 18 --> | |
<g id="node20" class="node"><title>18</title> | |
<polygon fill="none" stroke="black" points="1674,-64 1620,-64 1620,-28 1674,-28 1674,-64"></polygon> | |
<text text-anchor="middle" x="1647" y="-41.8" font-family="Times,serif" font-size="14.00">18</text> | |
</g> | |
<!-- 17--18 --> | |
<g id="edge19" class="edge"><title>17--18</title> | |
<path fill="none" stroke="black" d="M1584.4,-46.7C1595.64,-46.5722 1608.72,-46.4237 1619.92,-46.2964"></path> | |
</g> | |
<!-- 19 --> | |
<g id="node21" class="node"><title>19</title> | |
<polygon fill="none" stroke="black" points="1764,-41 1710,-41 1710,-5 1764,-5 1764,-41"></polygon> | |
<text text-anchor="middle" x="1737" y="-18.8" font-family="Times,serif" font-size="14.00">19</text> | |
</g> | |
<!-- 18--19 --> | |
<g id="edge20" class="edge"><title>18--19</title> | |
<path fill="none" stroke="black" d="M1674.4,-39.0992C1685.64,-36.1617 1698.72,-32.7449 1709.92,-29.8166"></path> | |
</g> | |
<!-- 19--0 --> | |
<g id="edge21" class="edge"><title>19--0</title> | |
<path fill="none" stroke="black" d="M1709.9,-17.4909C1675.33,-10.6866 1612.37,-7.10543e-15 1558,0 206,0 206,0 206,0 151.626,-7.10543e-15 88.6744,-10.6866 54.1027,-17.4909"></path> | |
</g> | |
</g> | |
</svg> | |
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
</XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment