In order for the agents to understand the game world, we need to convert the game state into a format that it can digest - we will call this the model's "state space".
Each model architecture will have different structure for the state space, so it is important to clearly define the features that are important to your game and the method to extract them. Developers can either use the built-in feature engineering module or create their own custom features.
Feature Engineering Module
The NRN agents SDK comes with an ability to automatically extract features from a game world. Developers only need to define a configuration so the SDK knows how to access certain values from the game world. Below we show an example getting the following features:
Raycasts that originate from the player and detect enemies around it
Relative position (distance and angle) to a powerup
The state config is comprised of an array of feature configs of the following format:
{
type: string, // Name of the feature type
keys: Record<string, string>, // Keys used to extract values from the game world
setup?: Record<string, any> // Additional setup parameters
}
Features Available
In the configurations below, we use the notation string -> objectType to denote that the value for the key must be a string that points to an object of a particular type.
Raycast
Configuration
{
type: "raycast",
keys: {
origin: string -> { x: number, y: number },
colliders: string -> { x: number, y: number, width: number, height: number }[],
maxDistance: string -> number
},
setup?: { numRays: number }
}
Returns: Array of Length numRays
[
Ray 1, // (1 / numRays) * 360 degrees
Ray 2, // (2 / numRays) * 360 degrees
Ray 3, // (3 / numRays) * 360 degrees
...
Ray N, // 360 degrees
]
Relative Position
Configuration
{
type: "relativePosition",
keys: {
entity1: { x: number, y: number },
entity2: { x: number, y: number },
maxDistance: number
}
}
Returns: Array of Length 3
[
Distance // 0 is farthest, 1 is closest
Sin(Radians) // Direction indication #1
Cos(Radians) // Direction indication #2
]
Relative Position To Cluster
Configuration
{
type: "relativePositionToCluster",
keys: {
origin: { x: number, y: number },
clusterEntities: { x: number, y: number }[],
maxDistance: number
}
}
Returns: Array of Length 3
[
Distance // 0 is farthest, 1 is closest
Sin(Radians) // Direction indication #1
Cos(Radians) // Direction indication #2
]
[
Rescaled value, // Number between 0 and maxPossibleNumber/scaleFactor
]
Normalize
Configuration
{
type: "normalize",
keys: { value: number },
setup: {
mean: number,
stdev: number
}
}
Returns: Array of Length 1
[
Normalized value, // Rescaled number by mean and standard deviation
]
Custom Features
If developers want to create features that are currently not offered by the feature engineering module, then they are able to. Below we showcase how to convert a Pong game world to a state matrix with custom feature engineering: