Posts

Post not yet marked as solved
8 Replies
yep, that's the fix. i figured it out as well
Post not yet marked as solved
12 Replies
i like the idea of level count. I was inpired by it. then i belived i took a different approach to solve the problem.
Post not yet marked as solved
12 Replies
i ah... i think i did it in a wrong way. Since i know that the character can jump, so i just ask one charactor jump and sweep the map for required gems. and it worked.but if the character can't jump at all, then i haven't figured out how to solve it yet.=====update======for the sake of seeking the true, i just did my thought through version which uses two experts, no jumping. and i'm super lazy, so i created several functions for the computer to determind what to do. i only lower or raise the level like several time until task complete. in a word, i let it automate.
Post not yet marked as solved
12 Replies
i've done 2 versions since the game asked me to exhaust all resource acquired previously. so here are my two solutions:==============cheating code==============let xp=Expert() let ch=Character() world.place(xp, facing:.north, atColumn: 0, row: 4) world.place(ch, facing:.north, atColumn: 2, row: 0) var countGem=0 func aCycle(){ for i in 1...6{ if countGem < totalGems { if ch.isOnGem{ ch.collectGem() countGem += 1 } ch.jump() } } } func halfMission(){ aCycle() ch.turnRight() ch.jump() ch.turnRight() aCycle() ch.turnLeft() ch.jump() ch.turnLeft() aCycle() } halfMission() ch.turnLeft() ch.turnLeft() halfMission()===============thought through code========let totalGems = randomNumberOfGems let xp1 = Expert() let xp2 = Expert() var levelCount=0 //count where the levels are, to determind to move up or down var gemCount=0 world.place(xp1, facing:.north, atColumn:0, row:4) world.place(xp2, facing:.north, atColumn:3, row:0) // place expert 1 and 2 on the map func collectCount (){ if xp2.isOnGem{ xp2.collectGem() gemCount += 1 } } //create a function that determins whether isOnGem, then collect and countGem func solveSpot(){ if xp2.isOnGem{ collectCount() } if !xp2.isBlockedLeft{ xp2.turnLeft() xp2.moveForward() collectCount() xp2.turnLeft() xp2.turnLeft() xp2.moveForward() xp2.turnLeft() } if !xp2.isBlockedRight{ xp2.turnRight() xp2.moveForward() collectCount() xp2.turnRight() xp2.turnRight() xp2.moveForward() xp2.turnRight() } else if xp2.isBlockedLeft && xp2.isBlockedRight { } if !xp2.isBlocked{xp2.moveForward()} else if xp2.isBlocked {xp2.turnLeft() xp2.turnLeft() //turn around at the end of the road } } //this function solve each row, if it's not block left or right, go and check gems, yes gem? get it and return, no gem? just return. func solveColumn(){ for i in 1...7 { if gemCount < totalGems { solveSpot() } } } //solve the whole column automatically func upCycle(){ xp1.turnLockUp() levelCount += 1 solveColumn() } //move the lock up and solve a column automatically func downCycle(){ xp1.turnLockDown() levelCount -= 1 solveColumn() } //move the lock down and solve a column automatically while gemCount < totalGems { xp1.turnLockUp() if levelCount == 1{ for i in 1...3 { upCycle() } } if levelCount == 3{ for i in 1...3 { downCycle() } } } //b4 required gems are collected, move up level then sweep the whole 3 column for accessible avilable gems. then at the end, if still need more gems, move down and repeat the cycle.
Post not yet marked as solved
12 Replies
hi, regarding this, i had another problem.when calling the method "moveForward()" i have to define which instance is using it, so it would be" expertOne.moveForward()"but if i want to create a new function, to tell the instance to move forward a certain number of steps, i would write:let expertOne = Expert()func moveSteps(steps : Int){for i in 1...steps {expertOne.moveForward()}}however if i have two or more instance of Expert(), i don't want to make different functions for each instance, so is there a way to code like this:func moveSteps(who: [some-data-type], steps: Int){for i in 1...steps {who.moveForward()}}so that everytime i can just callmoveSteps (who: expertTwo; steps: 4)then expertTwo will execute "expertTwo.moveForward()" 4 times,my code was definitely unacceptable, it's just for discussion sake. Any idea if i can realize this? like letting String becoming an instance name? Much appriciated.