-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.lp
60 lines (46 loc) · 1.35 KB
/
bot.lp
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
# Robots Example Bot
# Name: Example Bot
# Game: Pac-Bot -- eat the dots to clear the board; eat ghosts after power pellet!
# Things in the game: DOT, POWER, WALL, GHOST, FRUIT, EMPTY, PLAYER
# Variables: lives, level, energized, map_width, map_height, player_x, player_y
# Point Sensors: sense_n, sense_s, sense_e, sense_w
# Closest Location (x/y) Sensors: dot, power, fruit, blinky, inky, pinky, clyde
# e.g.: dot_x and dot_y contain the location of the closest dot relative to player
# See 'Intro' tab for more comprehensive documentation!
randmove = 0 # by default we don't want to move randomly
if move is 0 {
randmove = 1 # pick a random direction if we have never moved
}
# if there is a wall directly in front of us, pick a new random direction
if move is east and sense_e is WALL {
randmove = 1
}
if move is west and sense_w is WALL {
randmove = 1
}
if move is north and sense_n is WALL {
randmove = 1
}
if move is south and sense_s is WALL {
randmove = 1
}
# what direction should we go?
if randmove is 1 {
# we want to pick a random direction
rnd = rand % 4
if rnd is 0 {
move = east
}
if rnd is 1 {
move = west
}
if rnd is 2 {
move = north
}
if rnd is 3 {
move = south
}
} else {
# keep going in current direction
move = move # sets new value of move to previous value
}