-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
2.1.4: Super Cleanup Karel.js
61 lines (60 loc) · 1.11 KB
/
2.1.4: Super Cleanup Karel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function start() {
if (frontIsBlocked()){
turnLeft();
}
sweep();
turnAround();
begRow();
turnAround();
for(var i = 0; i < 24; i++){
if (leftIsClear()){
//this just makes the dog go in a circle (didn't want to leave the if statement empty soo...)
turnLeft();
move();
turnRight();
//cleans the row then comes back
cleanup();
}
}
if (facingNorth()){
while (frontIsClear()){
move();
}
}
if (facingSouth()){
turnLeft();
}
if (facingNorth()){
turnRight();
}
if (facingWest()){
turnAround();
}
}
//sweeps the street
function sweep(){
while (frontIsClear()){
if (ballsPresent()){
takeBall();
}
move();
if (frontIsBlocked()){
if (ballsPresent()){
takeBall();
}
}
}
}
//goes back (1,y)
function begRow(){
while (frontIsClear()){
move();
}
}
//**THE ONLY FUNCTION NEEDED TO CLEAN A ROW** (MAIN ONE)
function cleanup(){
sweep();
turnAround();
begRow();
turnAround();
}