|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ARM. - Array Operations |
ARM Commands Overview |
Top |
MiniRobotLanguage (MRL)
ARM Commands
A comprehensive guide to the ARM commands for managing two-dimensional arrays in MiniRobotLanguage (MRL).
Understanding Two-Dimensional Arrays
Two-dimensional (2D) arrays are a fundamental data structure in programming, particularly useful for storing and organizing data in a structured, tabular format, such as rows and columns. Imagine a chessboard, where each square (or cell) is identified by its row and column indices (e.g., [1,1] for the top-left corner, [8,8] for the bottom-right). This grid-like structure makes 2D arrays ideal for applications like games, image processing, mathematical calculations, and database management. In MiniRobotLanguage, 2D arrays managed by ARM commands are typically emulated within a one-dimensional array, which may be slightly slower but is often negligible in practice. They can be combined with other data structures for complex algorithms, enhancing versatility.
In this case, we again have the three familiar data types:
S - for String,
I - for Integer, and
F - for Floating Point. Here, we are dealing with Extended Precision Floating Point variables.
This is specified once with the ARM NU instruction, and from that point on, this container will have one of these three data types.
You can think of it as a two-dimensional matrix of X and Y values. Where the X and Y values intersect, the corresponding number or string is stored.
#DataTypes #FloatingPoint #Programming #ARM #Matrix
#DataTypes #AssociativeArray #Programming #SmartPackagedRobot #KeyValuePairs
The ARM.Set and some other ARM. - Commands are currently rather slow if a ReDim is needed. Otherwise they will be between 130 and 60 tick.
Sample:
' Very slow due to the needed automatic ReDim
029 0000000003675634 0001 ARM.set|$$ARR|1|1|This is a Text
' Much faster as no ReDim needed
030 0000000000000231 0001 ARM.set|$$ARR|1|1|Another Text
' Even more fast due to caching effects
031 0000000000000064 0001 ARM.set|$$ARR|1|1|Another Text
ARM Command Details
The following sections provide detailed information for each ARM command, including its purpose, typical applications, and a brief example. Each command operates on 2D array handles stored in variables with a maximum length of 5 characters (e.g., $$ARR, $$VAL).
ARM.New
**Purpose and Applications:** Creates a new 2D array and returns a handle. Used to initialize arrays for game boards (e.g., chess), pixel grids in image processing, or matrices in math calculations.
**Example:** ARM.New|$$ARR|i – Creates an integer 2D array with handle $$ARR.
ARM.End
**Purpose and Applications:** Destroys a specific 2D array, freeing memory. Essential for memory management in games, simulations, or data apps after a task completes.
**Example:** ARM.End|$$ARR – Deletes the 2D array with handle $$ARR.
ARM.EndAll
**Purpose and Applications:** Destroys all 2D arrays in memory. Useful for resetting large applications like multi-player games or simulations.
**Example:** ARM.EndAll – Removes all 2D arrays.
ARM.Redim
**Purpose and Applications:** Redimensions a 2D array, adjusting its size. Applied in dynamic game maps, resizing image grids, or matrix adjustments in math.
**Example:** ARM.Redim|$$ARR|5|3 – Resizes $$ARR to 5 rows, 3 columns.
ARM.Validate
**Purpose and Applications:** Validates a 2D array handle for usability. Critical for error handling in games, image processing, or data systems.
**Example:** ARM.Validate|$$ARR – Checks if $$ARR is valid.
ARM.Clear
**Purpose and Applications:** Clears all contents of a 2D array, preserving structure. Used to reset game boards, image grids, or matrices for reuse.
**Example:** ARM.Clear|$$ARR – Empties $$ARR but keeps its structure.
ARM.GetDims
**Purpose and Applications:** Retrieves dimensions of a 2D array. Useful for sizing game boards, image resolutions, or matrix dimensions.
**Example:** ARM.GetDims|$$ARR|$$ROW|$$COL – Gets $$ARR’s rows in $$ROW, columns in $$COL.
ARM.Set
**Purpose and Applications:** Sets a value at a (row, column) in a 2D array. Used for placing game pieces, setting pixel colors, or updating matrices.
**Example:** ARM.Set|$$ARR|2|3|99 – Sets 99 at [2,3] in $$ARR.
ARM.Get
**Purpose and Applications:** Retrieves a value from a (row, column) in a 2D array. Essential for reading game states, pixel data, or matrix values.
**Example:** ARM.Get|$$ARR|1|2|$$VAL – Gets value at [1,2] into $$VAL.
ARM.InsertRow
**Purpose and Applications:** Inserts a row in a 2D array, shifting rows down. Used to expand game boards, add image rows, or grow matrices dynamically.
**Example:** ARM.InsertRow|$$ARR|2 – Inserts a row at position 2 in $$ARR.
ARM.DeleteRow
**Purpose and Applications:** Deletes a row in a 2D array, shifting rows up. Applied to trim game boards, remove image rows, or shrink matrices.
**Example:** ARM.DeleteRow|$$ARR|3 – Deletes row 3 from $$ARR.
ARM.Sort
**Purpose and Applications:** Sorts a 2D array by a column. Useful for ordering game scores, sorting pixel data, or arranging matrix rows.
**Example:** ARM.Sort|$$ARR|1|desc – Sorts $$ARR by column 1 descending.
ARM.Transpose
**Purpose and Applications:** Transposes a 2D array, swapping rows and columns. Used in matrix operations, game board rotations, or image flips.
**Example:** ARM.Transpose|$$ARR – Transposes $$ARR.
ARM.Resize
**Purpose and Applications:** Resizes a 2D array to new dimensions. Applied to adjust game maps, resize images, or modify matrices.
**Example:** ARM.Resize|$$ARR|5|4 – Resizes $$ARR to 5x4.
ARM.Fill
**Purpose and Applications:** Fills a 2D array with a value. Used to initialize game boards, set image backgrounds, or fill matrices.
**Example:** ARM.Fill|$$ARR|0 – Fills $$ARR with 0.
ARM.Copy
**Purpose and Applications:** Copies one 2D array to another. Used for backups in games, duplicating images, or matrix replication.
**Example:** ARM.Copy|$$SRC|$$DST – Copies $$SRC to $$DST.
ARM.Find
**Purpose and Applications:** Finds a value’s position in a 2D array. Used to locate game pieces, pixels, or matrix values.
**Example:** ARM.Find|$$ARR|99|$$ROW|$$COL – Finds 99 in $$ARR.
ARM.GetType
**Purpose and Applications:** Retrieves a 2D array’s data type. Useful for type checking in games, images, or math apps.
**Example:** ARM.GetType|$$ARR|$$TYP – Gets $$ARR’s type into $$TYP.
ARM.Count
**Purpose and Applications:** Counts elements in a 2D array. Used for sizing game boards, image grids, or matrices.
**Example:** ARM.Count|$$ARR|$$CNT – Counts elements in $$ARR into $$CNT.
ARM.Reverse
**Purpose and Applications:** Reverses elements in a 2D array. Used for flipping game boards, image effects, or matrix reordering.
**Example:** ARM.Reverse|$$ARR – Reverses $$ARR.
ARM.Swap
**Purpose and Applications:** Swaps two elements in a 2D array. Used for moving game pieces, swapping pixels, or matrix reordering.
**Example:** ARM.Swap|$$ARR|1|1|2|2 – Swaps positions in $$ARR.
ARM.SumRow
**Purpose and Applications:** Sums values in a row of a 2D array. Used for scoring in games, aggregating pixel data, or matrix row totals.
**Example:** ARM.SumRow|$$ARR|2|$$SUM – Sums row 2 of $$ARR into $$SUM.
ARM.Sum
**Purpose and Applications:** Sums all values in a 2D array. Used for total scores in games, image pixel sums, or matrix totals.
**Example:** ARM.Sum|$$ARR|$$TOT – Sums all values in $$ARR into $$TOT.
Difference from ARM.Transpose vs. ARM.Rotate
While ARM.Rotate rotates the array 90 degrees clockwise, changing both the dimensions and the arrangement of elements (e.g., a 2x3 array becomes 3x2 with a specific clockwise rotation), ARM.Transpose simply swaps rows and columns without rotation, maintaining the same element positions relative to the new orientation but flipping the dimensions (e.g., a 2x3 array becomes 3x2 with elements mirrored across the main diagonal). Specifically:
- ARM.Rotate performs a 90-degree clockwise rotation, moving elements to new positions based on the rotation (e.g., [r,c] → [c, rows-r+1]).
- ARM.Transpose performs a matrix transposition, where [r,c] becomes [c,r], essentially flipping the array over its main diagonal without rotation.
For example, starting with a 2x3 array [1, 2, 3; 4, 5, 6]:
- ARM.Rotate results in [4, 1; 5, 2; 6, 3] (3x2, 90-degree clockwise rotation).
- ARM.Transpose results in [1, 4; 2, 5; 3, 6] (3x2, simple row-column swap).
Illustration for ARM.Transpose:
↔️ 2D Array Transposition: A chessboard-like grid with handle $$ARF, originally 2x3 [1.1, 1.2, 1.3; 2.1, 2.2, 2.3], is transposed to 3x2 [1.1, 2.1; 1.2, 2.2; 1.3, 2.3], swapping rows and columns without rotation.
Complete List of ARM Commands
Click on any command below to access its detailed help page:
Remarks
- All ARM commands require array handles to be stored in variables with a maximum length of 5 characters (e.g., $$ARR, $$VAL, $$ROW).
- 2D arrays in MRL are emulated within a one-dimensional structure, which may be slightly slower but is often negligible in practice.
- Proper memory management is critical; use ARM.End or ARM.EndAll to free memory when 2D arrays are no longer needed.
Limitations
- Variables for array handles and parameters must not exceed 5 characters.
- Some commands may have performance implications with very large 2D arrays.