dev:program_ulam
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:program_ulam [2015/05/31 03:39] – [Provider, Signal and Request] xychen | dev:program_ulam [2016/01/14 07:13] (current) – ackley | ||
---|---|---|---|
Line 18: | Line 18: | ||
Similarly, the first letter of every variable name, and of the name of every function or method (both terms mean the same thing in ULAM), must be a **lowercase** letter. | Similarly, the first letter of every variable name, and of the name of every function or method (both terms mean the same thing in ULAM), must be a **lowercase** letter. | ||
+ | |||
+ | ==== EventWindow Indices ==== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | The '' | ||
+ | |||
+ | In general, when code is referring to individual fixed sites within the event window, the 1D coordinate system is used (see the ' | ||
Line 28: | Line 36: | ||
EventWindow ew; | EventWindow ew; | ||
Void behave(){ | Void behave(){ | ||
- | ew[1]=ew[0]; | + | ew[1]=ew[0]; |
} | } | ||
} | } | ||
Line 173: | Line 181: | ||
The '' | The '' | ||
- | ===== Provider, Signal and Request | + | ===== Interaction between three Elements |
- | We have tried several elements. Here we implemented a game played by three elements: '' | + | We have tried several elements |
<code - Provider.ulam> | <code - Provider.ulam> | ||
/** | /** | ||
Line 314: | Line 322: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Node Elements ===== | ||
+ | We have some cool features in the new MFM simulator. One of them is that an Atom can change its color dynamically. We made this little '' | ||
+ | |||
+ | {{: | ||
+ | <code - Node.ulam> | ||
+ | /** | ||
+ | Node is a demo element. | ||
+ | \color #986 | ||
+ | \symbol Nd | ||
+ | \symmetries normal | ||
+ | */ | ||
+ | element Node{ | ||
+ | typedef Unsigned(6) SiteNum; | ||
+ | typedef Int(16) Coord; | ||
+ | typedef Unary(1) FireFlag; | ||
+ | typedef Int(4) Weight; | ||
+ | typedef Unsigned(8) ARGB[4]; | ||
+ | typedef Unsigned(8) ColorValue; | ||
+ | |||
+ | DebugUtils du; | ||
+ | EventWindow ew; | ||
+ | Once oc; | ||
+ | AtomUtils au; | ||
+ | Weight wa; | ||
+ | Weight wm; | ||
+ | Weight wb; | ||
+ | FireFlag fire; | ||
+ | Weight thresh; | ||
+ | ColorValue red; | ||
+ | ColorValue grn; | ||
+ | ColorValue blu; | ||
+ | |||
+ | Int getSum(){ | ||
+ | Int sum; | ||
+ | C2D mcd; | ||
+ | WindowServices ws; | ||
+ | ws.reset(1, | ||
+ | for(Int slot=ws.next(); | ||
+ | if(ew[slot] is Node){ | ||
+ | Atom a=ew[slot]; | ||
+ | Node you=(Node) a; | ||
+ | mcd=ew.getCoord((SiteNum)slot); | ||
+ | Coord mx=mcd.getX(); | ||
+ | Coord my=mcd.getY(); | ||
+ | if(mx< | ||
+ | if(my< | ||
+ | sum=sum+wa*you.fire; | ||
+ | }else if(my==0){ | ||
+ | sum=sum+wm*you.fire; | ||
+ | }else if(my> | ||
+ | sum=sum+wb*you.fire; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return sum; | ||
+ | } | ||
+ | FireFlag getFire(Int s){ | ||
+ | if(s> | ||
+ | return 1; | ||
+ | } | ||
+ | return 0; | ||
+ | } | ||
+ | Void initSelf(){ | ||
+ | Random rd; | ||
+ | Weight w; | ||
+ | wa=(Weight)rd.between((Int)w.minof, | ||
+ | wm=(Weight)rd.between((Int)w.minof, | ||
+ | wb=(Weight)rd.between((Int)w.minof, | ||
+ | thresh=(Weight)rd.between((Int)w.minof, | ||
+ | } | ||
+ | Void changeColor(){ | ||
+ | Random rd; | ||
+ | red=rd.between(0, | ||
+ | grn=rd.between(0, | ||
+ | blu=rd.between(0, | ||
+ | } | ||
+ | ARGB getColor(Unsigned selector){ | ||
+ | ColorUtils cu; | ||
+ | ARGB ret=cu.color(0xff00ff00u); | ||
+ | if(fire==1){ | ||
+ | ret[1]=red; | ||
+ | ret[2]=grn; | ||
+ | ret[3]=blu; | ||
+ | }else{ | ||
+ | ret=cu.color(0xff090806u); | ||
+ | } | ||
+ | return ret; | ||
+ | } | ||
+ | Void behave(){ | ||
+ | Int msum; | ||
+ | if(oc.new()){ | ||
+ | initSelf(); | ||
+ | du.printContext(); | ||
+ | } | ||
+ | msum=getSum(); | ||
+ | fire=getFire(msum); | ||
+ | changeColor(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We use a '' | ||
+ | |||
+ | In the '' | ||
+ | |||
+ | Like other Neurons, our '' | ||
+ |
dev/program_ulam.1433043559.txt.gz · Last modified: 2015/05/31 03:39 by xychen