设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7217|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 j% d: S- }7 y, b4 x
! f9 ]) A5 @$ o2 y' [; V2 s但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. q/ q4 B! B& h3 y. R
/ L. [5 m( V: |3 d) Bturtles-own [a b c d k f g h! D0 l; o( K7 w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  T& R! P6 M: G% U4 S]
" I; T& @$ I2 i% {to new0 ~+ D0 l* q7 ^
  ca$ U) \$ b' |- [) e6 j7 r7 w
  crt 5 * num_of_building4 s, z/ m: l. H: k% L
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% k6 X$ b0 R/ F- B) j& y5 Z
  scatter     ;;keep center-turtle random positions
, Z5 a- b  F& }- b6 _/ d- j, |  unit_plan   ;;make up the building plan
1 j3 Y  O! c+ D" w6 }' @6 f; Cend/ g3 N- j: Z7 `: ~: E3 `
to scatter; Z) k2 O5 S7 _, O) `' L, {0 F
ask turtles with [remainder who 5 = 0]/ Q% ~5 e: _3 t4 [4 l
[/ [( G& O2 A; s8 T
set xcor xcor - 6 + random-float 15( J" K8 }3 o' K1 r) @( d) Q- ^
set ycor ycor - 6 + random-float 151 e4 D, a8 \4 ^- B3 q& K
]
8 ~5 U/ w3 C* [& y* E9 vend
* v  Y& L  D! v* S$ Sto unit_plan / C# L7 O+ e2 ^% W1 r! t! \" t: f
ask turtles [
/ x8 Y7 o7 h' I% ^2 Sif (remainder who 5 = 1) [set a who
9 |& Y- m# y, T9 _                          set x ( 0 - Wid / 2 ) $ l: \9 h9 }( R0 _3 `
                          set y  Dep / 2 ]
9 j9 n) G6 K8 k' W" e" M           set b  int (a / 5) * 5
+ `! L' Y0 K+ q; X4 l$ ~    setxy ( xcor-of turtle b + x )
, Y  N. J1 S4 Q. `! |$ `! ]' i          ( ycor-of turtle b + y ); k7 t5 N4 b* M# D, t& G# m
if (remainder who 5 = 2) [set c who
( C  a% F+ {+ k, f8 [6 E                          set x ( 0 - Wid / 2 ) ; e. o. J& N; k5 C8 j9 _
                          set y (0 - Dep / 2 )  ]
8 g5 ]  d' g8 a. c) M; a) m                          set d int (c / 5) * 5
$ t3 ]/ [# J$ c: n   setxy   ( xcor-of turtle d + x ): s3 V) `& I( h5 H
           (ycor-of turtle d + y )
4 b  y4 ?: n% T; d4 N          7 I: P* M4 K- R1 a0 L
            
$ ]% {8 Z/ {) M  xif (remainder who 5 = 3) [set k who
! d3 s2 K1 U% ~, d                          set x( Wid / 2)  ' d! n2 m7 O. ]3 `4 U
                          set y (0 - Dep / 2 ) ]
5 ]9 S; |, ]* s+ I                          set f int (k / 5) * 5
. M6 c8 x2 p. p8 E$ F  setxy   ( xcor-of turtle f + x )5 h+ b, C7 a0 ]) I0 T# ~
           (ycor-of turtle f + y )
4 ]4 o* \/ t. {) E% t- ^3 J           
* e0 V8 v4 s9 b. Z7 E             S9 `1 i" o, B
if (remainder who 5 = 4) [set g who5 X4 _7 N/ p3 |; g: \. {7 p. u
                          set x Wid / 2 + V/ `4 s  W1 Y  L/ i
                          set y  Dep / 2 ]) k4 ~" M' T* i! w
                          set h  int (g / 5) * 5
* w  B& J& N. P" {8 T/ M' e  setxy   ( xcor-of turtle h + x )" c/ ~/ e/ a2 X9 K! Z6 j
           (ycor-of turtle h + y )   ^0 D+ k1 r8 K$ t5 F
                          
& T/ `/ A& a: m. P4 R0 y1 T- e' M                          
: R/ p. E1 V. ~" J  X                          ]
0 Y7 K7 C. {0 k9 ^5 D1 Cend
) ?3 I4 x# S; D$ S# U; Z- c
6 J+ [# ^2 g$ k[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- z7 V6 A* o+ X6 Y) Y, W5 W. H. X, f5 K
应该是
* m- z) Q" L" H$ jask turtles [8 Y1 X% q6 M1 h
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 e8 |3 @: s5 C6 o1 n$ g: y
                          set y  Dep / 2
: {4 h3 D9 y! H5 ?: I6 n           set b  int (who / 5) * 5: K! y; x1 R7 i3 z/ |8 v
    setxy ( xcor-of turtle b + x )8 k  W2 Q) r- ~) \9 i
          ( ycor-of turtle b + y )]]
# X. {" T7 D# v5 Eend
8 w3 Y: O, w$ Q, Y* f' Z; C之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-18 20:08 , Processed in 0.015538 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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