I decided to stick with Swift Playground for the time being. Although I wanted to give up, I decided to take another crack at solving the challenge. Looking at the expected solution provided guidance, but I didn't just copy and paste the code. Instead I experimented with various moveForward() commands to move Byte around. That was perhaps my biggest mental block. I didn't realize that I needed to access each switch, toggle it, and then return to the center tile, rinse() and repeat(). 😍
/*First, we must turn off the portal, otherwise Byte will fall through it and not get to any of those switches
*/
greenPortal.isActive = false
/*Define a function to move Byte forward 3 tiles
*/
func moveThree() {
for i in 1...3 {
moveForward()
}
}
/*Define a function that causes Byte to move back to the center tile, on which is the deactivated green portal thingy
*/
func returnToCenter() {
//Bring Byte back to center tile
//from any Toggle it happens to
//be on currently
//Two turns will orient Byte in
//the direction opposite to which it
//moved to the switch
turnRight()
turnRight()
moveThree()
}
/*Write code to do all of the following:
- Toggle switch on left side of puzzle
- Toggle switch at far end of puzzle
- Toggle switch at right side of puzzle
- After each task is complete, return Byte
to the center tile, rotate him 90 degrees
and repeat
- Finally, with Byte back on the center tile,
- reactivate the green portal, which will teleport
- him to the finish line (or tile)
*/
//Get Byte to the center tile
moveThree()
/*The following code applies for all three tiles
*/
for tile in 1...3 {
turnLeft()
moveThree()
toggleSwitch()
returnToCenter()
}
/*Byte has toggled all three switches
so it's time to finish up
*/
greenPortal.isActive = true
I am glad I stuck with the challenged and worked out how to complete the assigned task. Not sure if my solution is the most streamlined, but it does seem to work.
Thanks again for your kind assistance and guidance.