Advertisement
Guest User

Karel Challenges

a guest
Oct 27th, 2018
2,705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. Just press ctrl+f and type in #.#.#
  2. ---------------------------
  3. 2.1.1
  4. // The Starting Function
  5. function start() {
  6. gotoBall();
  7. returnSpot();
  8. }
  9.  
  10. // Function To Goto Ball
  11. function gotoBall(){
  12. turnLeft();
  13. fourMove();
  14. turnRight();
  15. move();
  16. move();
  17. takeBall();
  18. }
  19.  
  20. // Function To Return Back
  21. function returnSpot(){
  22. turnAround();
  23. move();
  24. move();
  25. turnLeft();
  26. fourMove();
  27. turnLeft();
  28. putBall();
  29. }
  30.  
  31. // Function To Move Four Times
  32. function fourMove(){
  33. move();
  34. move();
  35. move();
  36. move();
  37. }
  38.  
  39. ---------------------------
  40. 2.1.2
  41. /* This program will have Karel run around the racetrack
  42. * 8 times. */
  43. function start() {
  44. tennisBalls();
  45. }
  46.  
  47. function goAround(){
  48. while (noBallsPresent()){
  49. move();
  50. if (frontIsBlocked()){
  51. tennisBalls();
  52. turnLeft();
  53. move();
  54. }
  55. }
  56. }
  57.  
  58. function tennisBalls(){
  59. for (var i = 0; i < 32; i++) {
  60. while(frontIsClear()) {
  61. move();
  62. }
  63. putBall();
  64. turnLeft();
  65. }
  66. }
  67.  
  68. ---------------------------
  69. 2.1.3
  70. // Main starting function.
  71. function start() {
  72. while(frontIsClear()) {
  73. buildTower();
  74. turnAround();
  75. climbDown();
  76. move();
  77. if(frontIsClear()) {
  78. move();
  79. }
  80. }
  81. if(frontIsBlocked()) {
  82. turnAround();
  83. if(frontIsClear()) {
  84. move();
  85. }
  86. if(noBallsPresent()) {
  87. turnAround();
  88. if(frontIsClear()) {
  89. move();
  90. }
  91. buildTower();
  92. turnAround();
  93. climbDown();
  94. }
  95. if(ballsPresent()) {
  96. turnAround();
  97. if(frontIsClear()) {
  98. move();
  99. }
  100. }
  101. if(frontIsClear()) {
  102. turnAround();
  103. move();
  104. }
  105. }
  106. if(notFacingEast()) {
  107. turnAround();
  108. }
  109. }
  110.  
  111. function buildTower() {
  112. putBall();
  113. turnLeft();
  114. move();
  115. putBall();
  116. move();
  117. putBall();
  118. }
  119.  
  120. function climbDown() {
  121. move();
  122. move();
  123. turnLeft();
  124. }
  125.  
  126. ---------------------------
  127. 2.1.4
  128. // Function To Clean Up All The Balls
  129. function start() {
  130. ballsTaken();
  131. while(leftIsClear()) {
  132. endUpFacingEast();
  133. ballsTaken();
  134. if(rightIsClear()){
  135. endUpFacingWest();
  136. ballsTaken();
  137. } else {
  138. turnAround();
  139. }
  140. }
  141. }
  142.  
  143. function ballsTaken() {
  144. if(ballsPresent()) {
  145. takeBall();
  146. }
  147. while(frontIsClear()) {
  148. move();
  149. if(ballsPresent()) {
  150. takeBall();
  151. }
  152. }
  153. }
  154.  
  155. function endUpFacingEast() {
  156. turnLeft();
  157. move();
  158. turnLeft();
  159. }
  160.  
  161. function endUpFacingWest() {
  162. turnRight();
  163. move();
  164. turnRight();
  165. }
  166.  
  167. ---------------------------
  168. 2.1.5
  169. function start(){
  170. move();
  171. while(ballsPresent()) {
  172. takeBall();
  173. move();
  174. putBall();
  175. putBall();
  176. turnAround();
  177. move();
  178. turnAround();
  179. }
  180. move();
  181. while(ballsPresent()) {
  182. takeBall();
  183. turnAround();
  184. move();
  185. putBall();
  186. turnAround();
  187. move();
  188. }
  189. turnAround();
  190. move();
  191. move();
  192. turnAround();
  193. }
  194.  
  195. function fakeOne() {
  196. move();
  197. }
  198.  
  199. // My fake code
  200. function fakeTwo() {
  201. move();
  202. }
  203.  
  204. // My fake code
  205. function fakeThree() {
  206. move();
  207. }
  208.  
  209. ---------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement