Programmin' Pac-Man
Setting
You play as Pac-Man. You want to collect pellets, fruit, and power pellets before anybody else, all while avoiding ghosts.
Rules
- Every valid Pac-Man will be in a single maze. The player with the highest cumulative score after 10 games will win.
- A game is over when all Pac-Men are dead, all pellets are gone, or 500 turns have passed
- If a Pac-Man dies, he continues to play as a ghost
- Eating a Power pellet will make you invincible for 10 turns, and allows you to eat Ghosts
- Eating a Ghost will teleport the ghost to a random location
- Ghosts cannot eat anything except Pac-Men, and do not get any points
- Eating the following items as Pac-Man will get you the following points:
- Pellet: 10
- Power Pellet: 50
- Fruit: 100
- Ghost: 200
The Maze
If there are n Pac-Men, then a maze of size sqrt(n)*10
by sqrt(n)*10
will be generated using Prim's algorithm (due to it's low river factor), then braided completely, giving preference to already existing dead ends. Furthermore, this braiding can be done across the edges, so that there are a few pathways from top to bottom and from left to right.
There will be:
2n
Ghosts4n
Power Pellets2n
Fruitn
Pac-Men in spots where connected neighbors squares are empty.- All remaining empty spots will be filled with pellets
Hence, an initial map with 10 players will look something like this (Ghosts = green, Pellets = aqua, fruit = red, Pac-Man = yellow):
Input/Output
At the beginning of the game, You will be given a single line of characters, representing the walls in every square of the map. For each square, starting with the top left, moving right, and wrapping to the next line, you will be given a hex digit representing the wall situation:
0: No walls
1: North wall
2: East wall
3: East & North wall
4: South wall
5: South & North wall
6: South & East wall
7: Won't occur
8: West wall
9: West & North wall
A: West & East wall
B: Won't occur
C: West & South wall
D: Won't occur
E: Won't occur
F: Won't occur
Put simply, North=1, East=2, South=4, and West=8, added together.
Then, each turn, you will be given your current position and the items in your line of sight (if you are a Pac-Man. All ghosts receive all squares from -5 to +5 from their relative position). Your line of sight will be based on the direction you travelled last turn. If you travelled north, you will be given all squares directly North, East, and West of you until a wall cuts off your view plus a single square Northwest and Northeast, if no wall cuts off your view. If you choose not to move, you will be given the squares in all 8 directions.
For the visual, I
means invisible, V
means visible, P
means Pac-Man(assuming Pac-Man is facing north):
|I I|V|I|
|I V|V V|
|V V P|I|
|I I|I|I|
Each square will be given by a coordinate, and then it's contents. It's contents are represented by the following characters:
P
: 1 or more Pac-ManG
: 1 or more Ghostso
: PelletO
: Power pelletF
: Piece of FruitX
: Nothing
If there is a ghost and something else on a square, G
will be returned.
Hence, if you were on square 23,70
, you just moved north, the square above you is a dead end and contains a Power pellet, and you have walls on both sides of you, your input would be:
23,70X 22,70O
On your current square, it will show a G
if you are a Ghost, a P
if there is another Pac-Man on your square, otherwise an X
Then you will return the following items via STDOUT:
A single character representing a direction (N
orth, E
ast, S
outh, W
est, or X
Stay).
Previous to passing in a direction, you may also pass in any coordinate as x,y
, and the walls of that square will be passed back (as described above)
The program must be continuously running until Q
is passed to it via STDIN.
Programs will be restarted for each game.
Accessing other information outside of what is passed to STDIN (including other Pac-Men's data or the data held by the host program) is not allowed.
Failure to return a move within 1000 ms will terminate the program (Running on my fairly decent Win8 machine). You will be given 2 seconds to process the initial maze layout when it is given
Host will be written in Python, and code to test your bot is forthcoming.
Exceptional cases
- If multiple Pac-Men end up on the same location, neither get the contents of the current square, unless exactly 1 of them is invincible, in which case, the invincible Pac-Man will receive the pellet.
- A Pac-Man eaten by a Ghost will not be teleported somewhere else. If two Pac-Men are on a square, and one is invincible, the ghost will be teleported.
- Being teleported as a Ghost prevents you from moving for 1 turn. When playing as a Ghost, you simply will have your turn skipped
- Attempting to move through a wall will be interpreted as "Stay"
Each of the initial ghosts will receive one of the 4 personality traits, as described here, with the following modification:
- The bugs described will not be duplicated
- They will all be active from the beginning
- They are vulnerable only to the player who ate the pellet
- They will indefinitely switch from scatter to chase, each having a fixed number of turns before switch
- Upon switching to chase, they will find the nearest Pac-Man to chase, and will chase that Pac-Man for the duration of their chase. (If there is a tie for closeness, the Pac-Man will be picked pseudorandomly)
- Blinky won't speed up
- Inky will pick the nearest ghost to base his calculations off of after switching to chase.
- Clyde will find all players 8 squares away, then follow the furthest player.
- All ghosts except Clyde won't target a player farther than 5 squares away
I will accept compilable code from a standard language or an .exe (with accompanying code).
Programming Tips
You may with my controller. You need to put a /bots/your_bot_name/ folder in the same directory as the program. Within the folder, you need to add a command.txt containing a command to execute your program (ex: python my_bot.py
), and the your bot.
The controller code is on Github (Python code, requires Pygame if you want graphics.) Tested on windows and linux
SCORES
ghostbuster: 72,840 points
pathy: 54,570 points
shortsighted: 50,820 points
avoidinteraction: 23,580 points
physicist: 18,330 points
randomwalk: 7,760 points
dumbpac: 4,880 points