设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8933|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。: W  Z6 ^9 g5 i. n
# z7 N5 _9 s# w/ S
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ X) W& d, b$ w; `" n
2 x9 z0 ^, w# }" H' d; G8 w
turtles-own [a b c d k f g h
7 N% }# g5 P, x* R1 x# W4 T( X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( \1 {! m# `; F/ s9 B- ]
]
/ q2 N3 z9 v: O: S" ~& D- A  Kto new
" U' h5 A+ G, W6 M5 e: X; ]; w  ca
  o6 ]6 d3 u+ l# p  crt 5 * num_of_building
1 g5 M9 }! N6 Z( E( x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& X# S+ z$ W( Y0 t/ `
  scatter     ;;keep center-turtle random positions
: u; R1 Q4 U9 o" c$ x8 Z8 o  unit_plan   ;;make up the building plan6 f% S9 x7 u: ~' ^  G1 D. `$ O
end6 }; D) p/ ~% `0 X, m& r
to scatter2 b* a  Y5 U) F  e9 o, D8 {
ask turtles with [remainder who 5 = 0]5 [4 |4 N8 K/ i$ j, Q
[
( M$ L0 Y. U; i7 U. n' gset xcor xcor - 6 + random-float 150 s' Y. W* t/ d: f3 z" e% T& V! N
set ycor ycor - 6 + random-float 15
. M! q& L6 m! v1 R]
' ^( V* D! z. Aend" S' t+ t: {  N  J; y) y; H
to unit_plan 7 c! n3 c4 z% e  ?% W* x- Z- R
ask turtles [
- K1 C1 Q0 I$ R2 z5 ~; H: zif (remainder who 5 = 1) [set a who ) X' B8 [, \& C- s: J9 |' u
                          set x ( 0 - Wid / 2 )
0 \; J' Y- H$ ]8 X7 @- Q                          set y  Dep / 2 ]. y3 {) A" a+ f2 N7 [$ A! j6 I. N' S
           set b  int (a / 5) * 5
2 S& N# J3 `% ^" a    setxy ( xcor-of turtle b + x )+ I( U' j* K, N. [( F
          ( ycor-of turtle b + y )
% H+ w$ D: o/ q' ?% Zif (remainder who 5 = 2) [set c who
  U5 R; W- {# _, O$ }7 M. \6 c$ S5 Q                          set x ( 0 - Wid / 2 )
9 C- |6 G, r5 h" `                          set y (0 - Dep / 2 )  ]/ [' M/ n$ g& _/ m! a, C1 X
                          set d int (c / 5) * 5
" b8 y  [. P) U% b! R+ R! d$ _3 b   setxy   ( xcor-of turtle d + x )" q4 G; j& Z( N5 r
           (ycor-of turtle d + y )
0 e% i7 t% e" Y# h* |7 y/ b4 d' ]% O         
& H7 T, v2 m7 v: }- B4 f" s( K            & r& g) }# ]' n  T  f" ~
if (remainder who 5 = 3) [set k who6 `! e, ?- H# m2 K# n. r  T
                          set x( Wid / 2)  - d; x6 F+ A, g6 ]& j3 v0 \9 o2 Q
                          set y (0 - Dep / 2 ) ]3 ^( `; ?! {* d8 u1 h$ T
                          set f int (k / 5) * 5* I) N; H- H7 `: T. }8 ~0 d
  setxy   ( xcor-of turtle f + x )
$ ^  P$ _( }# K+ W" Y" c           (ycor-of turtle f + y ) . z9 v, l1 V! K8 g, K
           
$ c9 q$ Q0 A& F+ S1 k$ Q           
; m) X9 a7 g$ w- Pif (remainder who 5 = 4) [set g who
: f/ \' ?% P6 L' p1 }2 a" A( ~                          set x Wid / 2 5 N9 a" R) L2 C+ Z: T
                          set y  Dep / 2 ]2 F" p& R" G" a
                          set h  int (g / 5) * 5
8 U8 ^" |% I4 c- T( _  setxy   ( xcor-of turtle h + x )' P& `8 E" }% v8 F9 k7 X0 U7 }; b
           (ycor-of turtle h + y )
  r# _; k5 f$ A8 V5 `- O$ d# I                          $ s1 s" s5 T+ q
                          
  V$ q' e; C0 [4 x: a3 N, P                          ]" h* Q0 ~+ ~9 ^, k. m1 ^
end
9 `  j. D/ n/ t0 M3 E3 L7 X! W9 P) O: w; x2 b3 c( V5 f) A
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  R; d3 y. o6 Z' i+ L- @$ N) m应该是
; `) n) _& w' vask turtles [
% r; W8 ?  u) K! S. A' Z' w' Lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   H& `) t+ B. L1 R
                          set y  Dep / 2
9 ]& \0 D6 O! ]' o9 d           set b  int (who / 5) * 5& e" N9 L* M$ }
    setxy ( xcor-of turtle b + x )
" j9 {- c' g5 s6 L$ r: a* S          ( ycor-of turtle b + y )]]: E8 }, Z) e3 [: c
end3 w1 a+ h) w7 b3 G' U7 M* H
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-26 09:29 , Processed in 0.018981 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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