设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7618|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。/ b( A# x- a; B' }

; Z" S; i( U* o# ~+ x) B但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" g. l7 D  d2 b# Q/ `7 y7 s
& F. f+ X4 b9 b& L3 m0 k
turtles-own [a b c d k f g h6 G" k) }* e, X' x8 H7 W. Z8 v9 b4 o
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( z) @! x$ e( m
]) A& Z. D3 l2 W6 f; ?) k
to new  h7 c: n; z, ]. z% ~
  ca2 }: K! O& m$ w- F) A+ ]
  crt 5 * num_of_building
4 _, D) Z; ~# m( i  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! q* _) F8 f8 b" r" q9 n
  scatter     ;;keep center-turtle random positions
/ H/ T4 z2 K/ l; y+ F  unit_plan   ;;make up the building plan
9 H- Q+ ^! C3 z' V" ]end
& f. l  p& R# E6 Q* O1 Nto scatter; W! k3 k* ~4 h* ]
ask turtles with [remainder who 5 = 0]
( s, m8 F! q$ b: P- d2 |' `[
% W& X/ Q+ r9 a' |# Lset xcor xcor - 6 + random-float 15' A/ o& J9 B5 G* s$ H+ O0 ^9 Q  O
set ycor ycor - 6 + random-float 15
, ^7 ^0 G* J3 V+ v0 `/ d+ Z3 e]
9 y" c; H" u- x& x; K' oend
( Q6 g9 z! Q! Q$ Y5 D" ito unit_plan ! O+ [; c8 [% D1 ?6 q7 W
ask turtles [) F! [* @8 b: f' W& b8 h
if (remainder who 5 = 1) [set a who + l. [- T) x# T0 U9 S
                          set x ( 0 - Wid / 2 )
/ S9 C  o* M3 Z/ w8 Q                          set y  Dep / 2 ]
, ^2 R" H9 j# |           set b  int (a / 5) * 5
0 Y* ]( b/ w9 b# O, K    setxy ( xcor-of turtle b + x )
) _2 P: `6 ?* D          ( ycor-of turtle b + y )6 x- \7 x, `; |" G2 r$ j
if (remainder who 5 = 2) [set c who
, t0 a$ p+ H1 \- |                          set x ( 0 - Wid / 2 )
8 {6 W" b; |& D: I" p                          set y (0 - Dep / 2 )  ]
$ v% u0 i2 @% T( |                          set d int (c / 5) * 5
. U2 z, h1 Y/ G- Z! O9 c   setxy   ( xcor-of turtle d + x )5 Q  X" r0 v: s
           (ycor-of turtle d + y )   o0 c+ k* U6 Y" S
          : f! |* R6 m5 v; m
            4 i1 |7 o0 q4 Z2 S0 ]
if (remainder who 5 = 3) [set k who" G0 z8 `2 n4 Q9 N
                          set x( Wid / 2)  ! R  c3 M5 J) ~4 S# f- P
                          set y (0 - Dep / 2 ) ]; U9 P/ w3 j9 @. c( p% r
                          set f int (k / 5) * 59 L* J4 o5 {3 }( U
  setxy   ( xcor-of turtle f + x )) s6 f6 X9 l3 E. x
           (ycor-of turtle f + y ) 9 q" Z, V* v* H( c
           
8 E2 {- _* r/ h. K; \8 Y/ Z           
. C. o% `5 o1 K3 ?; ?  B( c: ]if (remainder who 5 = 4) [set g who
2 y, \: U6 Z( A& G9 E, \                          set x Wid / 2
$ U9 z6 c- I- k# g0 D1 ^                          set y  Dep / 2 ]
0 ~4 ^& n: b& b& g. {3 |$ _                          set h  int (g / 5) * 5
6 c/ D( t/ j5 T  setxy   ( xcor-of turtle h + x )* }/ D8 C  E" y  U5 w. h; ~
           (ycor-of turtle h + y ) 1 g- K: W1 a* ^9 v
                          : o: h4 ^; E9 S% @
                          9 D8 y4 E2 v! B+ Z# ?/ h& Q8 w8 O! [
                          ]7 g, a, q% f3 V0 H' ^
end
2 t2 |+ r  ~2 W! Y! g
$ X% H% j, L' T2 h[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  |" k* j; g( \* t; z+ q% i$ U应该是
/ `" V- Z! M' |2 R" w. Iask turtles [
, k+ Y" y" B4 ]! W% k* q! q  Gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! ]- t; Y- n$ G$ x/ k! u3 y
                          set y  Dep / 2
3 ]" q6 @8 \  g           set b  int (who / 5) * 5, q: v0 }+ G! T; A, U
    setxy ( xcor-of turtle b + x )
( u8 e. J( L1 @6 P          ( ycor-of turtle b + y )]]) p7 o4 r$ s2 e& L5 L
end
7 f. `; a6 F+ I" w  i之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-3-6 06:26 , Processed in 0.014751 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表