[Edu-sig] GvR question

Dan Schellenberg schellenberg at gmail.com
Wed May 4 02:56:57 CEST 2005


While not strictly a Python posting, I think this question may be of 
interest to this list.  I have decided to use GvR (Guido van Robot) as 
an introductory unit in my computer science course, and therefore have 
recently spent some time running through the premade lessons at 
http://gvr.sourceforge.net/lessons/rfrank/

On lesson 17 http://gvr.sourceforge.net/lessons/rfrank/step17/  I have 
been unable to contrive a solution that I think my students would 
understand at this stage.  The problem is very straightforward, but the 
difficulty comes in assigning a proper while loop to the code block 
that defines how long Guido continues to pick up garbage (ie. none of 
the built in conditionals provide a good boolean for this problem, 
though right_is_clear is workable, just not eloquent).  I have solved 
the problem using the aforementioned right_is_clear conditional in the 
while loop (see first example below), and have also solved it (much 
more eloquently in my opinion) using recursion.  However, I would like 
to have a more eloquent solution without having to use recursion, as I 
am not sure that I want to introduce that concept at this stage.  Below 
are my two solutions.  Anyone have an idea on how to improve the 
readability of these solutions for the students?


Non-recursive solution:

> define turnright:
> 	do 3:
> 		turnleft
>
> define go_south_west_corner:
> 	while not_facing_south:
> 		turnleft
> 	while front_is_clear:
> 		move
> 	turnright
> 	while front_is_clear:
> 		move
> 	turnright
>
> define go_north_east_corner:
> 	while not_facing_north:
> 		turnleft
> 	while front_is_clear:
> 		move
> 	turnright
> 	while front_is_clear:
> 		move
>
> define pickup_column:
> 	while front_is_clear:
> 		while next_to_a_beeper:
> 			pickbeeper
> 		move
> 	while next_to_a_beeper:
> 		pickbeeper
>
> 		
> go_south_west_corner
>
> while right_is_clear:
> 	pickup_column
> 	
> 	if facing_north:
> 		turnright
> 		if front_is_clear:
> 			move
> 			turnright
> 		else:
> 			go_north_east_corner
> 			while any_beepers_in_beeper_bag:
> 				putbeeper
> 			go_south_west_corner
> 			turnoff
> 	elif facing_south:
> 		turnleft
> 		if front_is_clear:
> 			move
> 			turnleft
> 		else:
> 			go_north_east_corner
> 			while any_beepers_in_beeper_bag:
> 				putbeeper
> 			go_south_west_corner
> 			turnoff


Recursive solution:

> define turnright:
> 	do 3:
> 		turnleft
>
> define go_south_west_corner:
> 	while not_facing_south:
> 		turnleft
> 	while front_is_clear:
> 		move
> 	turnright
> 	while front_is_clear:
> 		move
> 	turnright
>
> define go_north_east_corner:
> 	while not_facing_north:
> 		turnleft
> 	while front_is_clear:
> 		move
> 	turnright
> 	while front_is_clear:
> 		move
>
> define pickup_column:
> 	while front_is_clear:
> 		while next_to_a_beeper:
> 			pickbeeper
> 		move
> 	while next_to_a_beeper:
> 		pickbeeper
> 	if facing_north:
> 		turnright
> 		if front_is_clear:
> 			move
> 			turnright
> 			pickup_column
> 		else:
> 			go_north_east_corner
> 			while any_beepers_in_beeper_bag:
> 				putbeeper
> 			go_south_west_corner
> 			turnoff
> 	elif facing_south:
> 		turnleft
> 		if front_is_clear:
> 			move
> 			turnleft
> 			pickup_column
> 		else:
> 			go_north_east_corner
> 			while any_beepers_in_beeper_bag:
> 				putbeeper
> 			go_south_west_corner
> 			turnoff
>
> 		
> go_south_west_corner
> pickup_column


--
Dan Schellenberg
schellenberg at gmail.com
http://www.educationaltechnology.ca/dan/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2373 bytes
Desc: not available
Url : http://mail.python.org/pipermail/edu-sig/attachments/20050503/4705a0a7/smime.bin


More information about the Edu-sig mailing list