Last updated: February 10th, 2023
Evolve 5.0
VOLVE    5.0

KFORTH Interpreter Dialog

This dialog allows you to experiment with KFORTH programs. You can also develop new genetic programs, and verify that they compile.

File Buttons

NOTE: If you modify something in the Kforth Source pane you will be prompted to save if you try to exit.

Debugger Buttons

The KFORTH Interpreter allows the special organism instructions like OMOVE, LOOK, EAT, etc... Inside of the interpreter these instructions are just no-op's. But at least you can examine real genetic programs and single step through them (even though they won't actually do anything).


KFORTH MACHINE

This section of the dialog shows the current state of the kforth machine. All 10 registers R0 ... R9 are shown. CB is the current code block being executed. PC is the current program counter. Both CB and PC are 0 based numbers. Code block 0, refers to the code block with the label "main:". PC is relative to the current code block being executed.

The data stack shows the elements currently on the data stack. The top most item represents the "top" of the stack.

The call stack shows the saved locations for cb and pc. This stack allows KFORTH to return from a subroutine call.


KFORTH INTERPRETER

This dialog allows you to execute generic KFORTH program (that is, KFORTH programs that do not use CELL instructions). However "dummy" versions of the CELL instructions are provided, so that genetic programs may be explored using this dialog without getting compiler errors. You can even step thru the code, but since all the CELL instructions "fail" you won't learn much.


KFORTH Instruction Dialog

If you click on [Instructions] this pop-up dialog will appear:

This dialog lets you browse the list of available instructions.


Function Key Summary


The mutations tab.

Detailed information about these mutations available here.

Here is how the [MUTATE!] button and other fields are used to implement mini-evolution.

MUTATE_BUTTON(TIMES, POPULATION, TRIALS)
{
    STEP_LIMIT = 10,000 ; fixed constant, prevents infinite loops
    PROGRAM p1          ; program we start and end with
    PROGRAM p           ; program used during trials
    PROGRAM best        ; best program so far
    integer best_score  ; best score so far
    integer best_steps  ; best number of steps
    integer avg_score   ; average score across # of TRIALs
    integer avg_nsteps  ; average steps taken over  # of TRIALs
    bool    first_time  ; on first member of population

    p1 = <KFORTH Disassembly>

    for(i=0; i < TIMES; i++) {

        first_time = true
        for(j=0; j < POPULATION; j++) {

            p = Mutate(p1)

            avg_score = 0
            avg_nsteps = 0;
            for(k=0; k < TRIALS; k++) {
                rr = Run(p, STEP_LIMIT)
                avg_score += rr.score
                avg_nsteps += rr.steps
            }
            avg_score = avg_score / TRIALS
            avg_nsteps = avg_nsteps / TRIALS

            if first_time
                    or avg_score > best.score
                    or (avg_score == best_score and avg_nsteps < best_nsteps)
            {
                best = p
                best_score = avg_score
                best_nsteps = avg_nsteps
                first_time = false
            }
        }

        p1 = best
    }

    <KFORTH Disassembly> = p1
}
Pseudo-Code

The Run() function runs the program for up to 10,000 steps and returns whatever is on the top of the data stack. An empty data stack is treated as 0. Returns two things: the score and the number of steps required.

Scoring is based on the 16-bit KFORTH integer returned from the program. The larger the value, the better the score.

The Mutate() function returns a copy of the provided program, except it has been mutated. The algortihm is described here.


The protections tab.

Protections are explained here.

Lookup Symbol: This field allows you to lookup a symbol in the source code pane and place its code block number into the Protected Code Blocks field.

This is handy when you are developing a new program. It is annoying to constantly count code block numbers to just set the protections.