Skip to content

Instantly share code, notes, and snippets.

@depy
Created May 18, 2020 19:19
Show Gist options
  • Save depy/d6969158cedc81c6c323d099ed445bf8 to your computer and use it in GitHub Desktop.
Save depy/d6969158cedc81c6c323d099ed445bf8 to your computer and use it in GitHub Desktop.
###############
# Rules #
###############
FIND the most valuable path within range
# I could only do 5 cells away/levels deep before my code was timing out
# Partly because Ruby is not the fastest
# Partly because I started to think about performance too late
IF enemy 1 cell away and possible to eat them
MOVE to their position
# Sometimes my pacs spawn just next to an enemy I could eat
# Majority of first moves I've seen were activating "SPEED" as first move
# This is counter play to the most popular first move
# While they're activating "SPEED" we eat them :)
ELSE IF can activate ability (ability cooldown is 0)
IF there is danger (current pac can be eaten) within X distance (1 or 2 in my case)
SWITCH type to winning one
IF there is a "draw" (enemy has the same type as me) # I think I later abandoned this rule
SWITCH type to winning one
ELSE
SPEED (activate speed ability)
ELSE IF no danger within 1 or 2 tiles && there are big pellets on the map && big pellet distance > 2
MOVE to big pellet position
# the rule about distance > 2 ensures that when the pac is closer to big pellet than that
# it then switches to "auto pilot" (normal path finding - choses the most valuable path)
ELSE IF all paths within search range are worth 0 # no pellets within range
MOVE to the closest pellet on the map
# I literally just used the euclidean distance and it worked decently
# Using manhatan distance might be better
# Precalculating actual path distances between cells would be ideal I guess
ELSE
MOVE to the next cell on the move valuable path return from path finding (5 cells away/levels deep)
################
# Cell scoring #
################
IF cell position == my pac position
RETURN -1
IF cell contains my pac
RETURN -10
IF cell contains enemy pac AND my pac can eat it
RETURN 1
# If I return negative values, then my pacs will avoid enemy pacs
# If I return positive values, then my pacs will chase enemy pacs
# If I return 1 then they will "see" them as normal pellets worth 1 point
IF cell contains enemy pac AND it can eat me
RETURN -10
IF cell contains enemy pac AND it is the same type as me
RETURN -1
# Slightly avoids enemy pacs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment