Watching a video yesterday (Http://www.tudou.com/programs/view/4QmfLMMBZBg) is about a strong network built by the slime bacteria looking for food.
The following figure
Through the observation of the behavior of sticky bacteria. I would like to use a distributed swarm algorithm to simulate the behavior of slime to achieve the optimal path of search.
At present, simple behavior simulation is realized. There are two main areas
1, the expansion of slime bacteria behavior.
First, a survivability value is defined to simulate. In the position of slime bacteria, vitality is the strongest. With the expansion of the slime bacteria, the expansion of the edge of the vitality will decline. The slime fungus will continue to expand.
2. Access to food
It is assumed here that the expansion of the slime can only absorb food, but not the food can be converted into energy. Like the human body, only the stomach can digest food and convert food into energy for absorption by the human body.
It is assumed that the core of slime can transform food into energy, and other parts can only absorb and transmit energy.
So the transmission of energy is transmitted from the low vitality to the place where the vitality is high, and only in the initial position of the slime bacterium.
Program Simulation
1, the various parts of slime bacteria can only be obtained from the surrounding parts of the information. Can only communicate with the surrounding parts of the exchange of information, as well as the delivery of food.
Now it's simple to use arrays to demonstrate. Did not do interface demo.
First of all, describe the meaning of the following array "vitality, food content, food transport quantity Statistics"
Where the initial position of slime bacteria in the "10,0,0" place, food protection in the picture of the "0,5000,0"
The source code is as follows
Package Main
Import (
"FMT"
"Sync"
"Time"
)
Func Main () {
for {
Select {}
}
}
var max_x int = 10
var max_y int = 10
var Allpart []parts
Type Parts []*part
var lock *sync. Rwmutex
Func Print () {
TICK: = time. Tick (1 * time. Second)
for {
Select {
Case <-tick:
Fmt. Println ("-------------------------------------------------")
Lock. Lock ()
For y: = 0; Y < max_y; y++ {
For x: = 0; x < max_x; X + + {
Fmt. Printf ("%d,%d,%d\t", Allpart[y][x].en, Allpart[y][x].food, Allpart[y][x].countfood)
}
Fmt. Println ()
}
Lock. Unlock ()
}
}
}
Func init () {
Lock = &sync. rwmutex{}
Allpart = Make ([]parts, Max_y, max_y)
For y: = 0; Y < max_y; y++ {
Allpart[y] = Parts (make ([]*part, max_x, max_x))
}
For y: = 0; Y < max_y; y++ {
For x: = 0; x < max_x; X + + {
ALLPART[Y][X] = Newpart (x, y)
}
}
Allpart[8][3].en = 10
Allpart[8][3].ismother = True
Allpart[3][8].food = 5000
Allpart[3][8].isfood = True
For y: = 0; Y < max_y; y++ {
For x: = 0; x < max_x; X + + {
Go Allpart[y][x].run ()
}
}
Go Print ()
}
Type part struct {
x int
Y int
En int
Food int
Countfood int
ismother BOOL
Isfood BOOL
}
Func Newpart (x, y int) *part {
P: = part{x, y, 0, 0, 0, false, false}
Return &p
}
Func geten (x, y int) int {
If x < 0 | | Y < 0 {
Return-1
}
If x >= max_x | | Y >= max_y {
Return-1
}
Return Allpart[y][x].en
}
Func (P *part) run () {
TICK: = time. Tick (1 * time. Second)
For!p.ismother {
Select {
Case <-tick:
Func () {
Lock. Rlock ()
Defer lock. Runlock ()
Max_node: = 0
Maxcount: = 0
Other: = Make (</