Dibawah ini adalah script Netlogo Planarity diatas:
;; inisialisasi
turtles-own [
bits ;; list of 0's and 1's
fitness
]
globals [
kura
level
penyelesaian
potongan
winner
]
;; mengatur level
to setup
clear-all
set-default-shape turtles "butterfly" ;; jenis turtle
ask patches [ set pcolor green] ;; warna patch
setup-level
end
;; untuk menambah label turtle tiap level + 1
to-report labelx?
report ( level >= 1 )
end
;; tambahan
to setup-level
reset-ticks
set penyelesaian level + 5
set level level + 1
clear-turtles
set kura 4 + level ;penentuan banyak turtle
create-turtles 4 + level [
set color pink
set size 2
setxy random-xcor random-ycor
;;
set bits n-values kura [one-of [0 1]]
calculate-fitness
]
ask turtles[
print (word "TURTLE = " self)
print (word "KROMOSOM = " bits)
print (word "FITNESS = " fitness)
]
update-display
print (word "FITNESS MAX = " winner)
while [count links = count turtles] [
ask one-of turtles [
ask one-of other turtles [ attempt-link ]
]
]
ask turtles [
ask other turtles [ attempt-link ]
]
while [solved?] [ scramble ]
display
end
to attempt-link
create-link-with myself [
set color red
if any-intersections? [ die ]
]
end
to scramble
layout-circle turtles (world-width / 2 - 1)
end
to-report turtle-plus [n] ;; turtle procedure
report turtle ((who + n) mod count turtles)
end
to go
if labelx?
[
ask turtle 0 [set label "0"]
]
if mouse-down? [
let grabbed min-one-of turtles [distancexy mouse-xcor mouse-ycor]
while [mouse-down?] [
ask grabbed [ setxy mouse-xcor mouse-ycor ]
display
]
tick
if solved? [
user-message "You are winner. Let's continue!"
setup-level
]
if ticks > count turtles[
user-message "You are lost!"
reset-ticks
;;set penyelesaian level + 1
;; set level level + 1
clear-turtles
create-turtles 4 + level [
set color pink
set size 2
setxy random-xcor random-ycor
]
while [count links < count turtles] [
ask one-of turtles [
ask one-of other turtles [ attempt-link ]
]
]
ask turtles [
ask other turtles [ attempt-link ]
]
while [solved?] [ scramble ]
display
]
]
end
to-report solved?
report all? links [not any-intersections?]
end
to-report any-intersections?
report any? other links with [crossed? self myself]
end
to-report crossed? [link-a link-b]
set potongan count links
let a1 [end1] of link-a
let a2 [end2] of link-a
let b1 [end1] of link-b
let b2 [end2] of link-b
let nodes (turtle-set a1 a2 b1 b2)
;;menampilkan label turtle di awal level
ask turtle 0 [set label "0"]
ask turtle 1 [set label "1"]
ask turtle 2 [set label "2"]
ask turtle 3 [set label "3"]
ask turtle 4 [set label "4"]
;; menampilkan label jika level + 1
if penyelesaian > 5 [ask turtle 5 [set label "5"]]
if penyelesaian > 6 [ask turtle 6 [set label "6"]]
if penyelesaian > 7 [ask turtle 7 [set label "7"]]
if penyelesaian > 8 [ask turtle 8 [set label "8"]]
if penyelesaian > 9 [ask turtle 9 [set label "9"]]
if penyelesaian > 10 [ask turtle 10 [set label "10"]]
if 4 > length remove-duplicates [list xcor ycor] of nodes
[ report false ]
if 4 > length remove-duplicates [list xcor ycor] of nodes
[ report true ]
report [subtract-headings towards a2 towards b1 < 0 xor
subtract-headings towards a2 towards b2 < 0] of a1
and [subtract-headings towards b2 towards a1 < 0 xor
subtract-headings towards b2 towards a2 < 0] of b1
set a1 7
set penyelesaian count a1
end
; fitnes
to calculate-fitness ;; turtle procedure
set fitness length (remove 0 bits)
end
to update-display
set winner max-one-of turtles [fitness]
end
; Copyright 2007 Uri Wilensky. All rights reserved.
; The full copyright notice is in the Information tab.
0 komentar:
Post a Comment