attached script is turtle parade using asep and turtle graphics
How can I use multi thread in this script
Best regards
anal_circuit_3=: 3 : 0
NB. sumilate 3 times
NB. u 0.55
ANS2=. <''
COUNTER=. 0
while. COUNTER < 3 do.
TMP=. anal_turtle_circuit y
ANS2=. ANS2,<TMP
COUNTER=. >: COUNTER
end.
}.ANS2
)
NB. -----------cut here------------------
NB. ------------------------------------------------
NB. turtle_circuit
NB. circuit parade using ASEP ZRP and turtle graphics
NB. written by Masato Shimura//[EMAIL PROTECTED]
NB. 11/Oct./2007
NB. ------------------------------
NB. * do_turtle_circuit 0.55 NB. p=. 0.55
NB. p is 0.2<---> 0.8
NB. circuit clockwise
NB. enlarge graph plane yourself
NB. ------util---------------------------------
require 'turtle'
NB. --------------------
bare=: ;("1)@,.
bare2=: ;("2)@,.
expand=: 4 : ' ((I. x) i. i. # x){y,0'
expand_box=: 4 : ' ((I. x) i. i. # x){y'
NB. usage:1 0 1 0 1 1 expand_box ({@> 3 4 5 6),<0
loose_box=: 3 : '< |: bare2 |:(L:0) y' NB. remove sikiri
NB. -------turtle display--------------------
do_turtle_circuit=: 3 : 0
NB. u. 0.5 //p is from 0.2 to 0.75
TMP0=. anal_turtle_circuit y
CL0 =. 255 255 255 NB. empty white
CL1 =. 0 255 0 NB. A lime
CL2=. 0 172 0 NB. B like Green
CL3=. 255 0 255 NB. change Lane Fuchsia
NB. CL4=. 192 192 192 NB. forward car Silver
NB. --------------------------
COL0=.(color CL0 fill rt 0),(color CL1 fill rt 0),:color CL3 fill rt 0
NB. Lane A
COL1=.(color CL0 fill rt 0),(color CL2 fill rt 0),:color CL3 fill rt 0
NB. Lane B
NB. ----color and figure-------------
COUNTER=. 0
while. COUNTER < 121 do. NB. TIMES do.
NB. TMP=. (- COUNTER) |."1 ; COUNTER{ TMP0 NB. rotate turtle
TMP=. ; COUNTER{ TMP0 NB. rotate turtle
NB. TMP=.; COUNTER{ TMP0 NB. rotate turtle
CLR1=. {. TMP { COL0 NB. 30 column fixed
CLR0=. {: TMP { COL1 NB. 30 column fixed
NB. construct program for rectangles
NB. RAW=: 1 5
J0=. repeat 6 fd 1 rt 60 NB. Hexagon
CLR2=. CLR0,. >(# CLR0) #<J0
CLR3=. CLR1,. >(# CLR1) #<J0
NB. ----position-------------------
R0=.0 4 66 70 +/ j.3+ 2* >:i.30 NB. tate
R1=. (30{. 6+ 2* i. 60)+/ j.>: 0 3 64 68 NB. yoko
A0=. ({:"1 R1),(|.{: R0),(|. {. "1 R1),{. R0
B0=. (2{"1 R1),(|.2{ R0),(|. 1 { "1 R1),1{ R0
NB. JS=:; RAW +/ j. (2*>:i. 30) NB. i. 60 turtle block (2/3) is important
ht'' NB. hide tuirtle
show ;("1),.(A0 start {CLR2),B0 start {CLR3
COUNTER=. >: COUNTER
end.
)
NB. -----calc -----------------------------------
anal_turtle_circuit=:3 : 0
NB. e.g. u 0.5
ANS=. <TMP =.PX=.(prob_120 y),:prob_120 y
COUNTER=. 0
while. COUNTER < 120 do. NB. 2 min
TMP=. bare ({@> ;_120{"1 TMP) calc_zrp_sub1_circuit {* TMP
COUNTER=.>: COUNTER
ANS=. ANS,<TMP
end.
ANS
)
prob_120=: 3 : '(y * 120)> 120?120'
NB. ----asep engine----------------------
forward_asep_sub1=: 4 : 0
NB. alway same size
NB. calc ASEP
NB. self forward type
NB. x is 0/1 by probability
IND=. 2 = 2(+/)\ y,x
COMPARE=. bare ({@> 1 2) = L:0 +/ y,:IND
+/ bare ({@> _1 0) |."1 L:0 { COMPARE,.0
)
forward_sub2_circuit=: 4 : 0
NB. self run engine for circuit
NB. forward_sub1 is same as straight
TX =. x forward_asep_sub1 y
MKR=. ;({: L:0 y),x NB. 0 0,1 0.0 1,1,1-->2 #. is 0/2/1/3
NB. marker
select. 2 #. MKR NB. binary notation
case. 2 do. NB. 1 0 is 2 --> may go
select. 2 #. 2{. y NB. check last
case. 3 do. 1 forward_sub2_circuit y
NB. 1 1--> 3 is overflow--> top cannot go ahead
NB. not exsist those case??
fcase. do. TX=. _1|. }. TX
NB. only go-ahead and right turn (lotate is writeback }. y to 1)
end. NB. ut same turtles
fcase. do. TX=. }: TX
end.
NB. not forward case// recursive
NB. pecurier circuit /over zone--> assume 1
)
NB. ---zrp engine--------------
calc_zrp_sub1_circuit=: 4 : 0
NB. go to forward forside if free
NB. ] a=. 0;1 calc_zrp_sub1_circuit {PX
NB. x is COUNTER for osae//0 1
NB. x and y is boxed numeric
NB. calc ASEP and ZRP at once
IND_ZRP0=. index_zrp_sub0 L:0 y NB. can xrp
IND_ASEP0=. x forward_sub2_circuit L:0 y NB. space zrp
NB. pecurior circuit problem /
NB. make same number/cut
IND0=. >:@I. L:0 IND_ZRP0
IND=. (IND0 < L:0 |. # L:0 IND_ASEP0) # L:0 IND0
NB. nr is greater than counter lane
ZRP=. (IND e. L:0 I. L:0 -. L:0 |. IND_ASEP0)# L:0 IND
NB. amend pair is one to one make many combinations
AMEND_IND0=.* ; +/ L:0 * L:0 ZRP NB. index exsist ZRP
AMEND_IND=.;(AMEND_IND0 # {@>0 1),L:0{@> L:0 AMEND_IND0 # ZRP
select. +/ AMEND_IND0 NB. both null
case. 0 do. ANS=. bare IND_ASEP0
fcase. do. NB. INDEX is both or either
TMP2=: |.(2)(AMEND_IND)} L:0 |. bare IND_ASEP0
NB. twice reverse
AMEND_IND2=.(;{. L:1 TMP3) ,L:0 <: L:0 ; {: L:1 TMP3=.{@> L:0 AMEND_IND
ANS=. (0) (AMEND_IND2)} L:0 TMP2
end.
($ L:0 IND_ASEP0) {. L:0 {ANS
)
NB. same script
index_zrp_sub0=: 3 : 0
NB. 4th and after
NB. engine of ZRP
NB. find candidate for zrp
NB. NOT ADD NUMBER!
TMP=. y
if. 1={. y do. TMP=. 0,}. y end.
NB. top 0 0 0 is all cut /so top is dummy 1
TMP1=. ; +/ L:0 TMP0=. (-. TMP)<;.1 TMP NB. cut index is 0
if. 1={. y do. if. 3= {. TMP1 do. TMP1=. 4,}.TMP1 end.end.
NB. reverse dummy if 3
TMP2=. 4<:/ TMP1
select. +/ TMP2
case. 0 do. CAND=. 0# # y NB. nothing candidate
fcase. do.
IND0=.0,L:0 |. (L:0)3<:/ L:0 i.@ #@ }. L:0 (4<:/ TMP1)# TMP0
BASE=. (# L:0 TMP0) # (L:0) 0 NB. same-box all 0
CAND=. ; IND0(I. TMP2)} BASE NB. replace candidate
if. 1={. y do. if.1={. TMP2 do. CAND=. 1,}.CAND end. end. NB. back to 1
end. NB. select/end
CAND
)
NB. --------EOF------------------------
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm