设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8326|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 N' G' g: q: |8 G/ G7 f% ^4 U/ o9 A. K  x+ ]4 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( T% @  n) V+ g4 O- z7 t0 K1 H8 a. y$ p% C
turtles-own [a b c d k f g h8 M; }) G1 P5 O0 X/ T! \
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" T5 r+ L& O  v( {( C7 B  t& z]
- ]& G6 |' p+ U4 O1 |# jto new9 i% H& M- z* T, S6 t; |+ T
  ca
$ X9 n: C: T4 J8 p9 V$ N  crt 5 * num_of_building& r6 c- {' T4 |; n* E
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]8 H: Q$ |3 |: u3 L
  scatter     ;;keep center-turtle random positions ; n  y) d& o6 V. O9 k( p
  unit_plan   ;;make up the building plan8 |) ]; }& p0 Y1 Z# F( z- q' f' N
end: |: {* h" ?+ d
to scatter
5 D% i8 ^2 y6 h9 ~' y2 J$ a+ oask turtles with [remainder who 5 = 0]0 \+ D; Q4 g  z& ?7 ^7 q
[1 ^8 U, [# ?. U$ }* l$ p9 }2 d: J
set xcor xcor - 6 + random-float 15, U3 l. Z. L* w1 z
set ycor ycor - 6 + random-float 15$ x% t' o& X* L+ V! W" N1 ]; ~6 z
]. j3 g/ q: T: V7 D  _, F6 h
end& R; A$ ^+ Y( d8 B5 }
to unit_plan
2 ]5 b/ }3 S, Q4 A5 Nask turtles [
9 g2 |! H+ O; x/ {if (remainder who 5 = 1) [set a who
$ b& H5 U$ b( d( D                          set x ( 0 - Wid / 2 ) $ f- b3 f1 u3 o! D
                          set y  Dep / 2 ]
# Z  r3 I9 I: M9 }/ d           set b  int (a / 5) * 5/ k& `8 D9 U5 B: g" u, Q
    setxy ( xcor-of turtle b + x )) W1 P0 V1 N9 U8 |. e
          ( ycor-of turtle b + y )8 S! W. {: |& Z% @3 X' h0 J" k: B
if (remainder who 5 = 2) [set c who8 f( e4 S# D' [/ D1 D, c
                          set x ( 0 - Wid / 2 ) 4 O: I5 U+ {, ~: ?$ p( d, u
                          set y (0 - Dep / 2 )  ]
* P& y7 h# _# B% n! G& ~' T  G0 L3 D                          set d int (c / 5) * 5% X" I! e! P" \4 i, ?* G
   setxy   ( xcor-of turtle d + x )/ W  Z! H, e8 O2 p9 q# ?/ c; ^
           (ycor-of turtle d + y )
( n5 E9 e5 z+ i; ]          . z/ W9 v/ w9 }( ^, ^. p2 \
            4 q' h, {- G" M# G6 F' ?* D; |
if (remainder who 5 = 3) [set k who
, W  \: r" b3 u3 g+ V                          set x( Wid / 2)  
& S5 D7 y7 f; Z0 u# a                          set y (0 - Dep / 2 ) ]6 e! o  i1 L: \
                          set f int (k / 5) * 52 }) H, H2 W! I( Y' z
  setxy   ( xcor-of turtle f + x )
* U+ X2 E, g: p7 a* X8 R           (ycor-of turtle f + y ) 0 L( n8 x4 Y' {* l$ Q4 @9 [6 o2 |9 y
           9 a/ ]7 x* f% m
           
/ H' q  k" q3 k0 @* W0 `if (remainder who 5 = 4) [set g who4 ^% q' M* n, D5 L4 D# [  ?  f# V
                          set x Wid / 2
- P2 q! [* v8 w, S" x                          set y  Dep / 2 ]
* E$ p* b  \% s, P. X: |: [                          set h  int (g / 5) * 5+ w! U* F/ ]/ \! o# O
  setxy   ( xcor-of turtle h + x )
" p0 w2 l7 H" r4 c' K: D           (ycor-of turtle h + y ) $ @' D5 T0 C  F5 h; `
                          $ b5 m& u6 u3 L- h9 h
                          
) }8 e  H6 x8 j                          ]6 k. s% j, O. z
end
8 n4 z. w6 z. k
6 O- i/ R. H% [' h9 C4 e9 F[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 q9 g2 d' b( Y3 t% I( }3 k- U
应该是
8 H) J1 g4 P3 _ask turtles [
/ D6 b/ V$ ]( e1 p: L% \7 uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) + J; k! d4 a* X2 X+ e& n* A
                          set y  Dep / 2
9 F' q" q' Q: z% @' J1 h           set b  int (who / 5) * 5
; L( Y1 d- f) ]" K% t. l" n    setxy ( xcor-of turtle b + x )0 T: e6 y6 R0 R! M
          ( ycor-of turtle b + y )]]
) f; u3 W9 t2 C! p4 a- e) Eend: y8 F- r1 _0 X. u) c! p" Z1 c
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-8 06:59 , Processed in 0.015512 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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