Operations

Operations

> LeekScript Tutorial

All calculations performed in an AI take a certain amount of time for the server to execute. This execution time is estimated by a number: the number of operations used by the calculation.

An AI can't use more than a certain number of operations in one turn (1 million per core your leek has). Fortunately, the number of operations an AI has used during the current turn can be obtained with the getOperations function, and the maximum number of operations with the getMaxOperations function.

A leek's summons are subject to the same limit as their summoner's turn (if a leek has 3 cores and its AI uses 2 million operations on a given turn, its summons will be able to use at most 1 million operations).

Here is an (almost exhaustive) list of the costs of the various actions you can perform in an AI:

Code | Cost -----|------ var a; | 1 var a = value; | 1 array[index] = value; | 3 (push costs 2) map[key] = value; | 4

Access

Code | Cost -----|---- a | 0 function(params) | 1 + cost of the function array[index] | 1 map[key] | 2

Operators

Of course, you need to add the cost of a and b each time.

Code | Cost -----|----- a = b | 1 a ++ | 1 a -- | 1 a + b | 1 a - b | 1 a * b | 2 a / b | 5 a \\ b | 5 a % b | 5 a ** b | 40 a += b | 1 a -= b | 1 a = b | 2 a /= b | 5 a \\= b | 5 a %= b | 5 a *= b | 40

Comparison operators

Code | Cost -----|----- a == b | 1 a != b | 1 a > b | 1 a = b | 1 a > b | 1 a >>> b | 1 a >= b | 1 a <<= b | 1

OOP

Code | Cost -----|----- class object { ... } | 0 new object(params) | 1 + number of fields in the class + cost of the constructor object.method(params) | 2 + cost of the method object.property | 1 (only when outside the declaration of this object)

Keywords

Code | Cost -----|----- if(a) | 1 (plus the cost of a) a ? b : c | 1 (plus the cost of a, b and c) while(0) | 0 do {} while(0); | 1