设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8423|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。$ N4 [8 [1 T9 v$ s9 y" V
5 J3 o# }5 w/ E9 |: R. L+ U
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 a; |7 [" }( S% L7 u) _8 e2 q9 E! E0 W2 \
turtles-own [a b c d k f g h
& N2 W# x; c9 a+ _6 n7 v$ K' R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  c% ?, C# D& {$ b2 @; }/ k' D]+ F$ d  n2 L6 ^$ T& o* k. a9 l3 `
to new
: [5 y* V$ ]6 D3 S  ca
) Y# \+ |+ _  ]3 P! `; F1 p. x1 a8 m! c  crt 5 * num_of_building
# A0 I: K9 p' K3 T1 ^' R- T8 g  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 E9 a" n/ E' H8 S' r& j( m
  scatter     ;;keep center-turtle random positions 9 M: B7 X; s% R' U
  unit_plan   ;;make up the building plan
  L2 z- \: j# \& rend
. z" e8 T* e9 x* A4 A; \to scatter
/ f* ~+ c) j0 C8 zask turtles with [remainder who 5 = 0]+ L( w  r9 H$ l, c5 m3 ^9 D0 c9 ^
[
8 Q3 h  C$ }8 Jset xcor xcor - 6 + random-float 15
: @% h1 f( D! ^6 Nset ycor ycor - 6 + random-float 15& J# ?' k& l  R2 J9 ^% z
]0 e& L2 j. Z2 ?2 e2 V" }4 d2 }1 e
end" _3 @2 S  Q$ }5 Z# O9 b: P
to unit_plan
7 P3 U. o/ C7 D% p: F, b( Task turtles [/ \8 t6 ?/ z& e/ q
if (remainder who 5 = 1) [set a who
7 ~! X3 `2 _' l+ G                          set x ( 0 - Wid / 2 ) ) A; z# h8 d' N  J0 n, e
                          set y  Dep / 2 ]5 m+ p% e: b0 Z" o
           set b  int (a / 5) * 5, b: k/ g" W1 a1 q4 o
    setxy ( xcor-of turtle b + x )
+ @/ ]* ]. E0 B. M4 c( _          ( ycor-of turtle b + y )
! t3 h1 r) ~5 |, x/ H. xif (remainder who 5 = 2) [set c who
! h+ u+ ~8 f' |+ n                          set x ( 0 - Wid / 2 ) $ h) f' [2 A. D5 V
                          set y (0 - Dep / 2 )  ]
7 ~5 C0 Z# p& o& r                          set d int (c / 5) * 5
7 V0 R  P+ ~% j' D: o8 B9 P   setxy   ( xcor-of turtle d + x )% q3 C+ y, C, q0 K* U! D; a1 J
           (ycor-of turtle d + y )
3 w$ ?% M, q4 m' i  M1 ^         
- d) s' y8 R4 X/ Y' t            * A( U' F0 y; U2 y7 @$ ~/ Q
if (remainder who 5 = 3) [set k who
: B7 v, [; ~% F) Q+ s0 j                          set x( Wid / 2)  
$ U* j2 b! a5 W9 a8 h" |2 D                          set y (0 - Dep / 2 ) ]( l8 z% r2 F- u% i* t- q+ `+ a/ @. U9 z$ D
                          set f int (k / 5) * 5, r, j7 H8 b# L8 W0 _8 h
  setxy   ( xcor-of turtle f + x ). c9 n0 Y  F2 z6 K" d
           (ycor-of turtle f + y )
! ^0 l7 n  m% [! r0 a3 q$ y           
) I  C( g( H5 k. h0 M: F6 b4 i           
1 R- ]; @% ^/ ?# M9 L7 I: eif (remainder who 5 = 4) [set g who
! L5 A" I8 N* `" g0 r/ s4 o- J                          set x Wid / 2
- |. d( Z+ W8 z" S5 a, n                          set y  Dep / 2 ]2 }( ]5 M: j' B  k
                          set h  int (g / 5) * 5
- a' H9 k. g' s$ Y  setxy   ( xcor-of turtle h + x )
* ]$ G; p2 ~5 v* L- D& _: l           (ycor-of turtle h + y )
5 J& B4 t; ]3 p7 y                          # O0 e; O  Z- W1 J
                          4 |! H/ B: X, S/ Z- g
                          ]
: l1 t7 l0 Q! Jend1 @6 I! G8 K# F. `. k& z

& x& X. [& n8 U[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,1 ^) ~6 @/ k& q' |5 b& z3 _, X
应该是
+ f8 F8 Z# p! Jask turtles [0 |* P( Q9 b" r3 _; Z* q; s
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
5 }8 D6 n4 r9 s/ L. q                          set y  Dep / 2
. u* [0 ~, G6 \/ B0 C8 U           set b  int (who / 5) * 5
- R. R; Z1 ]  E2 X; p7 r( U$ k    setxy ( xcor-of turtle b + x )
' |0 I& ]& n* k% K; ^0 j          ( ycor-of turtle b + y )]]# U: C7 N, i* C* [# z% C
end
: T# |, {' O! H4 v6 I0 I; T. Z5 h之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-24 21:45 , Processed in 0.013751 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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