Skip to content

@v12-engine/engine/testing ​

Core ​

What a game meets first.

NameKindWhat
checkDeterminismfunctionMakes a world twice with make (the same seed, the same commands given in it, as a replay would) and runs them side by side, comparing their fingerprints every tick and their states (and the order each player's entities are filed in) every every ticks; with from, a third is saved at that tick and a fourth loaded from the save, and the two run on side by side. Says, for each, the first tick and thing it differs at, or that it does not. A test of a game's own systems: one that reads Math.random, the clock, or the order of something unordered is found here const report = await checkDeterminism(() = makeMyGame(1), ticks: 1800, from: 300, rules ) expect(report).toEqual( twice: null, fromSave: null )
orderfunctionGives units an order, as their owner would: taken up at the next tick. queue adds it after what they are doing
runfunctionSteps the world for up to seconds, stopping early once until holds. Returns the time that went by in it
simulatefunctionPlays games of a simulation, one from each seed, and gives what each ended in, in the order of the seeds. Given as it is, they are played in this thread. Given as the address of a file (a module whose default, or simulation, is one: a Simulation), each worker thread imports it and plays its share: in Node, from the built packages (a worker loads JavaScript, not the TypeScript of this repository)
SimulationinterfaceA game to play many times (simulate): the rules, the map, who the computer plays and how, and what to count
testWorldfunctionA small world of a game for a test (the game, createGame, or its module, Rules): flat ground, a neutral player and two enemies (TEST_PLAYERS), the same every time (seed 7). Each of them is the test's to say otherwise

Advanced ​

Interfaces ​

NameWhat
Apart betaWhere two runs of a game came apart: the first tick they were looked at and differed, and what differed first
BrainResults betaHow a brain did over some games (winRates): by seat, so a brain that played both sides of a game counts twice
ComputerMeasures betaHow a computer player played one game, beside who won (SimulatedGame.computers): the numbers that say whether a brain plays well, not only whether it won (AiStats, the brain's own counts, by the minute where it says so)
ComputerWatch betaA computer player followed over a run (watchComputer): the rules it broke, what it decided and sent, and, where asked, what an observer saw at each of its thinks
DecisionRecorder betaThe decisions of every computer of a world, as they are made (recordDecisions): plain data, for a side file beside a replay of commands, read back by whoever wonders why the computer did what the replay shows
DecisionsApart betaWhere a game saved and loaded first decided otherwise than the game it was saved from (checkComputerSave): the decision each made at that place in their logs. null where they decided alike to the end
DeterminismOptions betaHow a game is checked for coming out the same (checkDeterminism)
DeterminismReport betaWhat the check found: for each run, where it came apart from the first, or null for the same to the last tick
Difference betaWhere two states differ (firstDifference)
FairPlay betaWhether a computer player played fair over a run (fairPlay): every command it sent named what its own snapshot had, and how many the game refused
RecordedDecision betaOne thing a computer player decided, with whose: a line of a replay's side file (recordDecisions)
SimulatedGame betaHow one game ended
SimulateOptions betaHow simulate plays its games
WatchOptions betaHow a computer player is watched (watchComputer): which invariants and how long things may go on (AiCheckOptions), and what to be shown at each think

Functions ​

NameWhat
brainOf betaThe brain that plays a player, where one is seated (world.computers.seat): none where nobody is, or where what is seated is not a brain (defineComputer)
checkComputerSave betaThe seventh invariant of a computer player: a game saved at tick from and loaded makes the same decisions from then on as the game it was saved from, under the same commands. Makes the world with make (its computers seated, as a game seats them), runs it to from, saves it as a file would keep it and loads that with game, then runs both to ticks and compares what every computer decided. What lost rng, tasks or memory in a restore shows as expect(await checkComputerSave(() = duel(), from: 600, ticks: 2400, rules: melee )).toBeNull()
expectDecision betaSays that a goal runs, as of a report (thinkOnce, Brain.report): it is picked and holds what it claimed. Throws where it does not, with its row in words (Brain.explain): what each consideration answered and what kept it out. Gives the goal's row. With picked: false, says it does not run expectDecision(thinkOnce(world, ENEMY), 'ai.defend')
fairPlay betaFollows the brain at a player from now on for fair play: that it never sends a command about an entity its snapshot did not have (a fog leak: its seat's session would drop the command, so a game shows nothing; this says it), and counts what the game refused
firstDifference betaWhere two states first differ: the path to it (entities[id 11].pos.x) and what each holds there. Nothing when they are the same. Lists of things with an id are named by it, the rest by their place
fixtureGame betaThe fixture game (see the top of this file): every role of the kit, with round numbers. Gold and lumber, 1000 of each to start with; a hall and five workers at each start; heroes on (heroesPack); no fog explored at the start. A new one each time, for a test to change
fixtureMap betaA map of the fixture game, 64 cells a side: two players, starting at opposite corners (12, 12 and 52, 52), a gold mine and a row of trees by each start, and a camp of three creeps in the middle
flatTerrain betaFlat ground, size cells a side: 48 when left out
playGame betaPlays one game of a simulation from a seed, in this thread *
recordDecisions betaKeeps the decisions of every brain seated at a world, from now on, those seated later included (looked for at each tick, by a system of its own that keeps nothing in a save)
thinkOnce betaHas the brain at a player think now, all of it (a think its budget slices over ticks is run to its end), over a new picture of the game, and gives its report: what a test reads after setting a scene. Its commands land at the next tick, as a think's do. A think the seat would have had is not skipped: this one is beside them
watchComputer betaFollows the brain at a player from now on: after every think, the invariants of ai/checks.ts (a unit in one squad and one hold, gold spent once, finite numbers, commands about what it sees, no order sent again to a unit still at it, builders, tasks, holds and wants that end), with what it decided and sent. A broken rule is kept, not thrown, unless onViolation throws: assert at the end says them all
winRates betaThe win rate of each brain over games of simulate, by brain id (ComputerMeasures.brain): what a balance run of two brains reads. A seat that named no brain is left out const games = await simulate( ...duel, brains: 1: meleeBrain, 2: myBrain , seeds ) winRates(games) // 'core.melee': rate: 0.4, … , 'mygame.brain': rate: 0.55, …
worldFingerprint betaA quick hash of what a game that came apart differs in first: the tick, the random state, each player's resources, upgrades and supply, and each entity's id, type, owner, place, facing, health, mana, whether it lives, its orders (how many, and the first's kind and target), its buffs (which, and the time left) and its attack's cooldown and swing. Read off the world as it is, with no save: 0.4 ms at 1000 units a side, where worldHash takes 66. What a replay of commands keeps every few seconds and checks as it plays (recordCommands), and what checkDeterminism compares every tick, for the tick a game came apart at; what it leaves out (components, areas, the fog) the whole state, compared every so often, has
worldHash betaThe simulation's state as a hash: two worlds with the same hash are, to all that is saved of them, the same. Fourteen hex digits (cyrb53, of the save as JSON, but the hash of the rules, which another build of the same code writes otherwise): enough to tell drift, not to stand against someone forging a state
worldState betaThe simulation's state as plain data: its save, which holds all of it, but what each team's screens remember of the map, which is the watchers' (teamMemory)

Values ​

NameWhat
TEST_PLAYERS betaThe players of a test world, when a test says none: a neutral one, and two who are enemies

Types ​

NameWhat
Counted betaWhat a value counted at the end of a game may be: plain data, which comes back from a worker as it went