Skip to content

Strategies

Chenzs108 edited this page Feb 6, 2024 · 1 revision

It's a key design to a role's behavior. A Strategy is a kind of logic to determine the next action according to the game status.

strategy-uml

The name method returns the strategy name used in the src/config.json file.

The action_lvls method returns an array containing the level of recommendation for every action.

Assume:

action-level

Then action_lvls returns:

action-vector

I have implemented five kinds of strategies. They can be combined together.

Random Move

Random is the default strategy. All valid actions except stay will get random recommendation levels.

Move Away & Move Close

MoveAway and MoveClose only consider the next one step. They use the following estimate function to maximize or minimize the distance between the agent and enemy.

def dist(src: tuple[int, int], dest: tuple[int, int]) -> float:
    return abs(src[0] - dest[0]) + abs(src[1] - dest[1])

Wall Density

WallDensity tries to find a direction where the density of walls is lower.

wall-density

A* Search

AStar tries to find the shortest path from the enemy to the agent, as the blue path shows.

At first, the enemy knows nothing about terrains, so AStar assumes that all tiles are grass and finds an ideal path.

beginning

After the enemy learns terrains from its movements, AStar will become more accurate.

Clone this wiki locally