Module pacai.ui.token

Tokens are the atomic unit of frames. A token represents any object that can be on a pacman board (including the walls). A frame really consists of a collection of tokens. It is up to specific views to know how to interpret tokens into displayable objects.

Internally tokens are just ints, so we can do math on them. We typically reserve a range of numbers for some related type of tokens, like all walls or agents. Then, we establish some "base" tokens within each group, like the first red wall or the first yellow pacman. Then, we can add known/computed constants to the base tokens to get a specific token, like a red top-left corner wall or a pacman facing up with an open mouth.

Functions

def getAnimationToken(baseToken, direction, frame)

Get the token for a specific animation frame (for an agent). Animation frames are grouped by direction. The initial frame (0) is always the stopped animation. Then the cardinal directions (NESW) are cycled through. Each direction has ANIMATION_CYCLE number of tokens.

def getWallToken(baseToken, hasWallN, hasWallE, hasWallS, hasWallW)

Given information about a wall's cardinal neighbors, compute the correct type of wall to use. To get the pacman "tubular" look, adjacent walls will look connected and not have a line between them. The computation is similar to POSIX permission bits, all combinations produce unique sums.

def isCapsule(token)
def isFood(token)
def isGhost(token)
def isPacman(token)
def isWall(token)