Chapter 2, Listing 2

Listing 2: Der blinde Uhrmacher

Card-Script

	on openCard
		hide cd fld "children"
		pass openCard
	end openCard

Script of cd button "Start"

	on mouseUp
		if the hilite of me is TRUE then
			set the hilite of me to FALSE
			set the name of me to "Start"
		else
			set the hilite of me to TRUE
			set the name of me to "Working"
			initialisiere
			evolution
			set the hilite of me to FALSE
			set the name of me to "Start"
		end if
	end mouseUp

	on initialisiere
		global summe
		put 10000 into summe	-- wüste Vorbesetzung
		put 0 into cd fld "summe"	-- etwas weniger wüst
		put empty into cd fld "parent"
		repeat with i = 1 to satzLaenge()
			put makeLetter() after cd fld "parent"
		end repeat
		put empty into cd fld "children"
		put empty into cd fld "intermediate"
		put 0 into cd field "generation"
	end initialisiere

	on evolution
		global summe
		put FALSE into ende
		put line 1 of cd fld "goal" into ziel
		repeat while NOT ende
		repeat with i = 1 to anzNachkommen()
			-- erst einmal wollen wir sehen, daß
			-- noch etwas passiert:
			set cursor to busy
			put line 1 of cd fld "parent" into¬
			line i of cd fld "children"
			put makeLetter() into char¬
			random(satzLaenge())¬
			of line i of cd fld "children"
			put 0 into zwischensumme
			repeat with j = 1 to satzLaenge()
				if char j of cd fld "goal"¬
				<> char j of line i of¬
				cd fld "children" then
					add 1 to zwischensumme
				end if
			end repeat
			if zwischensumme < summe then
				put zwischensumme into summe
				put line i of cd fld "children" into¬
				cd fld "parent"
				put line i of cd fld "children"¬
				& return after¬
				cd fld "intermediate"
				set the scroll of cd fld¬
				"intermediate" to  9999
				put satzLaenge() - summe into¬
				cd fld "summe"
			end if
		end repeat
		add 1 to item 1 of line 1 of cd fld "generation"
		if summe = 0 then
			beep
			put TRUE into ende
			set cursor to hand
		end if
	end repeat
	end evolution

	--    Funktionen
	function makeLetter
		put random(27) + 63 into zufall
		-- A - Z: ASCII 65 bis 90
		if zufall = 64 then
			-- SPC: ASCII 32
			put 32 into zufall
		end if
		return numToChar of zufall
	end makeLetter

	--    Konstantendeklaration:
	function anzNachkommen
		return 20
	end anzNachkommen

	function satzLaenge
		return 28
	end satzLaenge

© 1997 by Jörg Kantel
Zurück zum Inhaltsverzeichnis