Skip to content
Snippets Groups Projects
Commit 52bcc2ee authored by Jana Eltayeb El Rafei's avatar Jana Eltayeb El Rafei
Browse files

test_main

parent 2885676a
No related branches found
No related tags found
1 merge request!8Controleur
......@@ -6,7 +6,7 @@ import (
)
func main() {
s := simulation.NewSimulation(20, -1, 600*time.Second)
s := simulation.NewSimulation(1, -1, 600*time.Second)
//go simulation.StartAPI(s)
s.Run()
}
......@@ -291,7 +291,7 @@ func writeAgent(matrix *[20][20]string, agt *Agent) {
for i := borneInfRow; i < borneSupRow; i++ {
for j := borneInfCol; j < borneSupCol; j++ {
matrix[i][j] = string(agt.id)[0:1]
matrix[i][j] = "A"//string(agt.id)[0:1]
}
}
......
......@@ -110,7 +110,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
}
*/
ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{1, 17}, Coord{0, 0}, 2, 1)
ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{19, 12}, Coord{0, 8}, 2, 1)
// ajout de l'agent à la simulation
simu.agents = append(simu.agents, *ag)
......@@ -179,7 +179,7 @@ func (simu *Simulation) Print() {
}
fmt.Println()
fmt.Println()
fmt.Println("============================================================")
//fmt.Println("============================================================")
//time.Sleep(time.Second / 4) // 60 fps !
time.Sleep(5000 * time.Millisecond) // 1 fps !
//fmt.Print("\033[H\033[2J") // effacement du terminal
......
......@@ -9,9 +9,10 @@ import (
type UsagerLambda struct{
req Request
}
/*
func (ul *UsagerLambda) Percept(ag *Agent) {
// récupérer le channel de l'agent lambda
chan_agt := ag.env.GetAgentChan(ag.id)
select {
case req := <-chan_agt : //verifier si l'agent est communiqué par un autre agent, par exemple un controleur lui a demandé de s'arreter
......@@ -19,8 +20,16 @@ func (ul *UsagerLambda) Percept(ag *Agent) {
case <- time.After(time.Second):
ag.stuck = ag.isStuck()
}
//
ag.stuck = ag.isStuck()
if ag.stuck {
return
}
//
}
func (ul *UsagerLambda) Deliberate(ag *Agent) {
if ag.position == ag.destination && (ag.isOn[ag.position] == "W" || ag.isOn[ag.position] == "S") {
fmt.Println(ag.id, "disapear")
......@@ -61,4 +70,38 @@ func (ul *UsagerLambda) findNearestExit(env *Environment) Coord{
}
return Coord{0,0}
}
*/
\ No newline at end of file
*/
func (ul *UsagerLambda) Percept(ag *Agent) {
ag.stuck = ag.isStuck()
if ag.stuck {
return
}
}
func (ul *UsagerLambda) Deliberate(ag *Agent) {
if ag.position == ag.destination && (ag.isOn[ag.position] == "W" || ag.isOn[ag.position] == "S") {
fmt.Println(ag.id, "disapear")
ag.decision = Disapear
} else if ag.stuck {
ag.decision = Wait
} else {
ag.decision = Move
}
}
func (ul *UsagerLambda) Act(ag *Agent) {
if ag.decision == Move {
ag.MoveAgent()
} else if ag.decision == Wait {
n := rand.Intn(2) // temps d'attente aléatoire
time.Sleep(time.Duration(n) * time.Second)
} else if ag.decision == Disapear {
RemoveAgent(&ag.env.station, ag)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment