Oops Mel, I quickly translated my little program, and since it was in
Italian and "Yes" sounds "Sì" here, I missed that line.
You are right about the file rules.txt. The lines 98-99 are wrong. The
correct syntax is:
There is no need to fopen after fcreate, fcreate returns the file handle
of the already opened file. The prog was written in Clipper many years
ago, and maybe there is a difference in the way fopen and fcreate do
work. For sure, that syntax worked in Clipper.
Since you are interested, here is a little explanation of the behavior
of the prog:
the matrix holds the weights of the properties for every animal. When
the prog has collected the 5 answers, it calculates the row that
totalizes the higher score, simply adding the weights for every "yes"
The interesting part is how the program corrects the weights when he
gives the wrong answer:
- it increases the weight of the properties of the right animal where it
got a "yes"
- it decreases the weight of the properties of all the others animals
where it got a "yes".
That's all. This very simple mechanism is incredibly efficient.
In another program, I was able to simulate a creature (let's say an ant)
that starts from a point in the upper row of a "field" (a grid of cells)
and tries to reach its "home" in the bottom row.
The ant moves from one cell to the adjacent at every loop.
To be honest, the ant is more like a pigeon, because it is able to know
the direction it should take to reach home. It knows its coordinates
(x,y) on the grid, and the coords of home (x1,y1), so it can simply
subtract the x,y values to know if it's approaching or stepping away.
But the creature resembles to an ant for the other thing it can do: it
leaves a chemical track on every visited cell.
The ant has two simple rules to follow: approach home and not enter a
cell already visited. Both rules are not mandatory: only discouraged.
But the chemical track is reinforced, should the ant enter a visited
cell, and the smell can become so strong that the ant can overcome the
primary directive to not step away from home!
The ant can calculate which cell is the nearest to home at every loop,
and move accordingly.
The problem that the pigeonesque ant must solve is what to do when it
encounters an obstacle.
If the obstacle is a simple horizontal wall, it is not difficult to
write a program that makes it to follow the wall until it ends and
restart approaching. In fact, the 3 cells below the ant are forbidden,
the 3 cells above discouraged because more far away from home, so the
only choice is to go horizontally.
But when the wall is like a "U" and the ant ends up inside the "U" it's
hard to make it to follow the wall, because it must step away from home
in order to overcome the obstacle. Without the chemical track the ant
would enter an infinite loop going left to right and right to left.
With the ES, the ant adjusts the score of the next move and "realizes"
that it must climb the wall, even if that is against the main directive,
if it wants not to be intoxicated by its own chemical substance.
I'll post the source here if someone is interested.
I was very proud to solve the problem with exactly the same algorythm
seen in neurnetw.prg, used in a ingenious way!