En:St-black/whiteballs
Aus EnigmaWiki
Available languages: Deutsch, English, Русский
st-blackballs und st-whiteballs
The two stones st-blackballs and st-whiteballs can do much more than what is immediately obvious.
They can process a signal sent to them in a certain way and send a signal out again.
There is a kind of application, which you find several times. A grid of doors is laid out, which open and close according to certain rules when touching these stones. Into the field, which is surrounded by 4 doors, a st-blackballs (or st-whiteballs) is put. Then the touched door opens, and the perpendicularly neighboring doors close.
The following piece of code generates such grids:
--- GRIDCODE ------------------------------------------------------------------- function set_ballstones(x0,y0,w,h,black) if black == 1 then stone = "st-blackballs" else stone = "st-whiteballs" end for i=0, h do for j=0, w do set_stone(stone,x0+2*j,y0+2*i) end end end function set_sensors(x0,y0,w,h,type) if type == 1 then sensor = "it-sensor" else sensor = "it-inversesensor" end local i,j local c = 0 for i=0, h do for j=0, w-1 do set_stone("st-door-h",x0+1+2*j,y0+2*i) set_item(sensor,x0+1+2*j,y0+2*i) dostring("Signal(\"it("..tostring(x0+1+2*j).." "..tostring(y0+2*i)..")\",\"st("..tostring(x0+2*j).." "..tostring(y0+2*i)..")\")") dostring("Signal(\"it("..tostring(x0+1+2*j).." "..tostring(y0+2*i)..")\",\"st("..tostring(x0+2+2*j).." "..tostring(y0+2*i)..")\")") c = c+1 end end for i=0, h-1 do for j=0, w do set_stone("st-door-v",x0+2*j,y0+1+2*i) set_item(sensor,x0+2*j,y0+1+2*i) dostring("Signal(\"it("..tostring(x0+2*j).." "..tostring(y0+1+2*i)..")\",\"st("..tostring(x0+2*j).." "..tostring(y0+2*i)..")\")") dostring("Signal(\"it("..tostring(x0+2*j).." "..tostring(y0+1+2*i)..")\",\"st("..tostring(x0+2*j).." "..tostring(y0+2+2*i)..")\")") c = c+1 end end end -- Wrapper: function set_grid(x0,y0,w,h,black,type) set_ballstones(x0,y0,w,h,black) set_sensors(x0,y0,w,h,type) end --- END GRIDCODE ---------------------------------------------------------------
Analysis
The grid consists of a lattice of st-blackballs (or st-whiteballs) and between 2 such stones in each case a horizontal or vertical door (st-door). On the same field as the door it also has a sensor item (it-sensor).
Now if the door is struck, the item on the same field implements its Action/target pair. (This is a special characteristic of doors!)
Now the sensor sends a signal to the two stones that form the door jambs. These distribute the signal (if it comes from the ball colour to which they also belong) to the 4 adjacent doors. These doors are then accordingly opened or closed.
A level that makes use of the code above could look something like this:
It is to be noted that neither black nor white can arrive at the other side, unless the other actor opens the doors "from the inside".

