Now that the board is constructed, you will place pawns on the board, check whether a pawn exists at a particular tile coordinate, and remove a pawn from the board.
Start with the following scenario. Given a tile_coordinate, determine whether there is a pawn there, and, if there is, retrieve it. The idea is as follows:
The board holds an array of
creative_proppawns.Iterate through the existing pawns and obtain each pawn location as a tile coordinate.
If there is a pawn at the given tile coordinate, retrieve it.
If there is not, the function fails.
Determine Tile Coordinate Equality
This requires that you have the ability to test whether two tile_coordinate's are equal. This is necessary because our custom tile coordinate data type is not a subtype of Verse's built-in comparable type. As a result, you need to manually define what it means for two tile coordinates to be equal. First, create a AreTileCoordinatesEqual function in the DataTypesmodule to determine this:
using { /Verse.org/Simulation }
DataTypes<public> := module:
...
UtilityFunctions<public> := module:
...
This function succeeds if and only if each component of the two input tile coordinates are equal as integers.
Get Tile Coordinate of Prop
Working with the pawns requires obtaining the location of a pawn as a tile coordinate. To this end, also write a helper function to get the location of a creative prop as a tile coordinate:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
using { DataTypes }
using { UtilityFunctions }
board<public> := class(creative_device):
This function succeeds if and only if the world location of the input creative prop can be converted to a tile coordinate on the game board. It also uses the function ToTileCoordinate previously defined to convert a world location to a board space location.
Get Pawn from Tile Coordinate
Write the GetPawn function:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
using { DataTypes }
using { UtilityFunctions }
board<public> := class(creative_device):
This function performs the following steps:
It iterates through all existing pawns on the board.
It obtains the pawn's location as a tile coordinate.
If the pawn's location is the same as the input location, it stores it as a found pawn.
It ensures that only a single pawn was found at that location.
It returns that one pawn.
This function succeeds if and only if there is exactly one pawn at the input tile coordinate and that pawn is successfully retrieved from the Pawns array.
Set Pawn at Tile Coordinate
Write a function to place a single pawn on the board. To keep it simple, use creative_prop objects as the pawns and use a SM_Box_asset as the pawn mesh. You can always change these later to custom objects of your choosing. The idea is:
The board holds an array of
creative_proppawns.Given a
tile_coordinate, check if there is already a pawn there.If no pawn exists, place one there.
Write the SetPawn function:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
using { DataTypes }
using { UtilityFunctions }
board<public> := class(creative_device):
This function performs the following steps:
Ensures the input tile coordinate is on the board.
Finds all pawns currently at the input tile coordinate.
Ensures there are no pawns found there.
Attempts to spawn a prop at the input location.
This function succeeds if and only if:
There are no pawns currently at the input tile coordinate.
The input tile coordinate is on the board and can be converted to a world location.
Remove a Pawn
One last function needed is the ability to remove a pawn from the board. This function takes in the creative prop to remove then removes it from the board and the bookkeeping Pawns array.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
using { DataTypes }
using { UtilityFunctions }
board<public> := class(creative_device):
Summary
To summarize, this page has taken you through the following steps:
Place a pawn on the board.
Get a pawn from the board.
Remove a pawn from the board.
Files
using { /Verse.org/Simulation }
DataTypes<public> := module:
tile_coordinate<public> := class<concrete>:
@editable
Left<public>:int = 0
@editable
Forward<public>:int = 0
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
using { DataTypes }
using { UtilityFunctions }
board<public> := class(creative_device):