设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8061|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" a( C& Y' j' h  K' n2 U
6 L/ W! ^0 D4 T1 z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 u5 J( _' V3 q8 e: |( x- O# ?! B- y+ a8 y
turtles-own [a b c d k f g h% w5 l% O, Y6 U8 P' n7 m
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 p5 b4 p0 o/ i# |" U
]
1 w& d+ {  M9 b: V! nto new3 \8 {! }) C6 H1 `" R8 M9 A; K9 B$ T/ ]
  ca
9 @2 O$ l: G) O; u  crt 5 * num_of_building
1 I- @: c0 k7 L' h4 y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 ?$ c- g0 s  ^& h
  scatter     ;;keep center-turtle random positions
( y- W* _, n' w5 b5 p/ g7 y  unit_plan   ;;make up the building plan; q1 L7 ^( l& x5 \7 _
end
/ ?7 }2 f! _- ?9 a" \to scatter
) I+ j# O, a# [7 b; G' H2 v# Gask turtles with [remainder who 5 = 0]
0 V" c9 A* p+ L' t[( \" c% D& i- X. N! v1 z5 Y! I
set xcor xcor - 6 + random-float 15' k3 @) x& k( s5 S$ w
set ycor ycor - 6 + random-float 15
; {; U& [& q" m8 y' `' ~]
6 A+ U$ m/ U& u8 Y8 ^$ i" ~end  `  J8 v; X8 t9 I. n9 p3 d
to unit_plan
! G& t  s, O6 B: mask turtles [& C7 F2 @) C" c9 Q) z  Y
if (remainder who 5 = 1) [set a who , Z! Y  D  t! H, E0 r; Q/ G
                          set x ( 0 - Wid / 2 ) 6 E! h# b) v1 O* s0 g& W$ X
                          set y  Dep / 2 ]; Y: |' X, _& Z2 `
           set b  int (a / 5) * 57 [3 y5 _) z, J1 K8 b, O
    setxy ( xcor-of turtle b + x )
' m7 H# I$ G" `  k          ( ycor-of turtle b + y )
% Z% [+ Y9 [3 F% t6 V: F  Mif (remainder who 5 = 2) [set c who/ D  Q8 I, B  q" q) H
                          set x ( 0 - Wid / 2 ) 6 U- z0 e! _1 g/ @
                          set y (0 - Dep / 2 )  ]
6 Y; x* [. _, k3 h* z2 h& X3 I/ f  A# {                          set d int (c / 5) * 5
2 l8 N3 g$ j& b- K; n- s   setxy   ( xcor-of turtle d + x )' D7 o5 E% J, n' L9 L/ T
           (ycor-of turtle d + y )
  G) J- m3 T* v! B$ W         
- n: G! l0 C5 j# ?; [" a            
2 _& M+ j& T- o5 L1 a8 s) L5 rif (remainder who 5 = 3) [set k who  u+ \$ h2 ?2 y7 \% u7 p
                          set x( Wid / 2)  
7 ]9 o1 A( @) I: I3 R) z9 o                          set y (0 - Dep / 2 ) ]" w: ~- d4 P3 N$ S# M
                          set f int (k / 5) * 5
% R( \: b3 `% ]7 m8 M  setxy   ( xcor-of turtle f + x )
. D5 `1 o& ~1 `, L# [6 z           (ycor-of turtle f + y )
- j! c- v$ x0 O6 ?7 Z7 v& Y! Q           " y5 c* C& f( G" t/ T
           + C% ?8 X# Y+ |# @9 {3 B) E
if (remainder who 5 = 4) [set g who7 @$ A, Z6 [5 Y: f9 M- `3 Y1 M
                          set x Wid / 2 4 t3 @: |9 w, V/ S" q0 M, D7 Y) o) c
                          set y  Dep / 2 ]
: N. f, [) D" R2 A( S3 Y                          set h  int (g / 5) * 5
8 H- T/ `* G0 u- M1 h  setxy   ( xcor-of turtle h + x )4 `' H' K9 l( D0 B( p/ V0 `3 j
           (ycor-of turtle h + y ) 5 N4 j; I! u4 ^  {
                          
9 s  n4 F, k6 O/ _3 h! |3 [5 W: w9 {                          1 P* e$ h$ a/ I- M
                          ]
: t% N& x/ h: V+ o3 \: T9 Yend' b6 Z9 B. [! ~5 A8 C8 m: {, G2 O
/ v! O# E( X6 m$ P$ }8 E" o
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 Q. H0 r3 K6 r" ]; Z* d( C
应该是
' h9 W1 ]( m8 g5 L9 T. K1 oask turtles [
% T- B4 `6 F( [' ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
, E  W$ `( k8 C* [1 \! g  |8 j$ B                          set y  Dep / 2 2 ^5 i# {% H8 M2 |- h. r
           set b  int (who / 5) * 5
+ B8 T2 a8 B$ M3 B    setxy ( xcor-of turtle b + x )9 L- n) A" Z( z% v4 H, P5 E
          ( ycor-of turtle b + y )]]
9 d, ~0 m, C) P  {/ Yend
$ o8 C1 W8 M3 H之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-2 16:46 , Processed in 0.015214 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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