comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: Help with tasks
Date: Sat, 07 May 2016 13:43:52 -0400
Date: 2016-05-07T13:43:52-04:00	[thread overview]
Message-ID: <p58sibpeueqg0g552jmnl7onnivpvl79cl@4ax.com> (raw)
In-Reply-To: 410b222c-9443-46b7-8a18-2fc3d05772a9@googlegroups.com

On Sat, 7 May 2016 07:53:28 -0700 (PDT), danifreecs@gmail.com declaimed the
following:

>
>The project: There's a garden with 10 plots, and a locust gets in 1 of the plots, so the gardener wants to kill it with poison. The locust randomly changes plots in a time, and the gardener can spray 1 plot/day (either randomly), which gets clean from poison after that day has passed. The locust dies if it jumps into the sprayed plot, or is in it already. The simulation goes until the locust dies. For the random number generation and the console output use a common protected object. (Monitor)
>
	Well, strictly speaking -- protected objects are not to perform
blocking operations; console output is a potentially blocking operation.

	Now -- using the protected object to hold the state of the plots, with
a separate display task (could be the main program) using a locking access
to retrieve the entire state at once for output/display might work...

	Question: "locust randomly changes plots in a time" is unclear. The
gardener is a one per simulated day, but what is the simulation time frame
for the locust? Also one move per day?

	Is that the actual text of the assignment, or did you paraphrase it?

	If both are one move per day, the whole idea of using tasks and
protected objects becomes moot. Since the poison clears out after a day,
one can assume every day starts with a clean slate. The only way to end is
for the gardener and the locust to move to the same plot (doesn't matter
who moves first since they effectively stay there until the next day). That
is: 

	loop
		gardener: = random(10)
		locust := random(10)
		display "gardener is in plot" gardener
		display "locust is in plot" locust
		exit if gardener = locust
		display "locust survived the day"
		display " "
	end loop
	display "locust is dead"


	If the locust can move multiple times in a day, then you need some sort
of simulation clock (say the locust moves every 6 hours -- the simulation
clock would be modulo 4 [0, 1, 2, 3, 0 ...], and the gardener moves only on
[0] which would also be when the plot(s) clear of the previous poison)

	Still doesn't really need tasks...

	clock := 0
	loop
		if clock = 0 then
			gardener = random(10)
		end if
		locust := random(10)

		-- since the only poisoned plot is the one the gardener is in

		display "gardener is in plot" gardener
		display "locust is in plot" locust
		exit if gardener = locust
		display "locust survived the move"
		display " "
	end loop
	display "locust is dead"
		

	Now, if the poison actually lasts the day of the spraying AND the next
day... Then you need some structure to represent the 10 plots and if they
are poisoned (a value in the range of 0..2 would suffice; when a plot is
sprayed, that entry is set to 2; on each day [still need a simulation
clock] non-zero entries are decremented by 1. If the locust enters a plot
with a non-zero entry, it dies.



	As for a working example? Sorry -- most of the ethical folks won't do
one's homework for them. Show us what you've written, tell us what you
expected it to do, and what it really is doing, and we'll tender
explanations of  what may be in error.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

  reply	other threads:[~2016-05-07 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-07 14:53 Help with tasks danifreecs
2016-05-07 17:43 ` Dennis Lee Bieber [this message]
2016-05-07 18:50 ` Anh Vo
2016-05-07 20:44 ` Jeffrey R. Carter
2016-05-08 12:23 ` danifreecs
2016-05-08 18:28   ` Anh Vo
2016-05-09  2:24 ` rieachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox