DEV Community

owly
owly

Posted on

LivinGrimoire Experiment: Showcasing Key Abilities

LivinGrimoire Experiment: Showcasing Key Abilities

The Incantation 0 LivinGrimoire experiment is designed to demonstrate two specific abilities of the LivinGrimoire software design pattern. These abilities are vital for enhancing the functionality and efficiency of the system.

Ability 1: Postponing the Run of an Algorithm

One key ability is to postpone the execution of an algorithm while another algorithm is actively running. This is tested with a skill that has two specific abilities:

1) Reciting the Ainz Incantation

The Ainz Incantation is a long algorithm that takes several cycles to complete, with one cycle per spell cast.

case "incantation 0":
    setSimpleAlg("fly", "bless of magic caster", "infinity wall", "magic ward holy", "life essence");
Enter fullscreen mode Exit fullscreen mode

While this algorithm is running, a second algorithm is set on standby to run after the first one finishes:

Brain b1 = new Brain()
b1.hardwareChobit.addSkill(new DiSysOut());
b1.logicChobit.addSkill(new DiTime());
b1.doIt("incantation 0", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("what is the time", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
Enter fullscreen mode Exit fullscreen mode

Output:

fly
bless of magic caster
infinity wall
magic ward holy
life essence
12:32
Enter fullscreen mode Exit fullscreen mode

Ability 2: Prioritizing an Algorithm

The second key ability showcases LivinGrimoire's ability to prioritize an algorithm. An algorithm with a higher priority will pause an actively running algorithm with a lower priority. The lower-priority algorithm will resume only once the higher-priority algorithm finishes running.

Test: Changing Algorithm Priority

By changing the algorithm's priority:

case "what is the time":
    setVerbatimAlg(3, pl.getCurrentTimeStamp());
    return;
Enter fullscreen mode Exit fullscreen mode

In this example, the priority of the short algorithm (telling the time) is set to 3, which is lower than the default priority (4) of the long algorithm. This gives the shorter algorithm priority to run over the long algorithm.

Brain b1 = new Brain()
b1.hardwareChobit.addSkill(new DiSysOut());
b1.logicChobit.addSkill(new DiTime());
b1.doIt("incantation 0", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("what is the time", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
b1.doIt("", "", "");
Enter fullscreen mode Exit fullscreen mode

Output:

fly
bless of magic caster
infinity wall
14:34
magic ward holy
life essence
Enter fullscreen mode Exit fullscreen mode

The algorithm with the lower numeric value (higher priority) runs without waiting for the higher-priority active algorithm to finish, similar to how in nature, fight or flight algorithms have higher priority.

Top comments (0)