Skip to content
Snippets Groups Projects
Commit 0b5a3bb2 authored by julienpillis's avatar julienpillis
Browse files

amélioration affichage métro

parent 8cbb7164
No related branches found
No related tags found
1 merge request!14Merge v2
......@@ -181,10 +181,10 @@ func Heuristic(row, col int, end Node) int {
// On introduit de l'aléatoire pour ajouter de la diversité dans la construction des chemins
// On évite d'avoir tout le temps le même chemin pour un même point de départ et d'arrivé
//return abs(row-end.row) + abs(col-end.col) + rand.Intn(3)
return abs(row-end.row) + abs(col-end.col) + rand.Intn(10)
return Abs(row-end.row) + Abs(col-end.col) + rand.Intn(10)
}
func abs(x int) int {
func Abs(x int) int {
if x < 0 {
return -x
}
......
......@@ -6,6 +6,8 @@ import (
"time"
)
var metro_speed int = 5 // Nombre de seconde de l'entrée en gare
type Metro struct {
frequency time.Duration
stopTime time.Duration
......@@ -31,13 +33,14 @@ func (metro *Metro) Start() {
//var step int
for {
//step = <-metro.syncChan
if refTime.Add(metro.frequency).Before(time.Now()) {
if refTime.Add(metro.frequency).Sub(time.Now()) <= time.Duration(metro_speed)*time.Second {
metro.printMetro()
}
if refTime.Add(metro.frequency).Before(time.Now()) {
metro.dropUsers()
metro.pickUpUsers()
metro.removeMetro()
metro.freeSpace = rand.Intn(10)
//fmt.Println(metro.way.id, metro.freeSpace)
//go metro.dropUsers()
refTime = time.Now()
}
//metro.syncChan <- step
......@@ -82,26 +85,106 @@ func (metro *Metro) findAgent(agent AgentID) *Agent {
func (metro *Metro) printMetro() {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "Q" {
metro.way.env.station[x][y] = "M"
if metro.way.horizontal {
waiting_time := time.Duration((metro_speed * 1000) / (metro.way.downRightCoord[1] - metro.way.upLeftCoord[1]))
if metro.way.goToLeft {
for y := metro.way.downRightCoord[1]; y >= metro.way.upLeftCoord[1]; y-- {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
if metro.way.env.station[x][y] == "Q" {
metro.way.env.station[x][y] = "M"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
} else {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
if metro.way.env.station[x][y] == "Q" {
metro.way.env.station[x][y] = "M"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
}
} else {
waiting_time := time.Duration((metro_speed * 1000) / (metro.way.downRightCoord[0] - metro.way.upLeftCoord[0]))
if metro.way.goToLeft {
// de bas en haut
for x := metro.way.downRightCoord[0]; x >= metro.way.upLeftCoord[0]; x-- {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "Q" {
metro.way.env.station[x][y] = "M"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
} else {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "Q" {
metro.way.env.station[x][y] = "M"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
}
}
}
func (metro *Metro) removeMetro() {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "M" {
metro.way.env.station[x][y] = "Q"
if metro.way.horizontal {
waiting_time := time.Duration((metro_speed * 1000) / (metro.way.downRightCoord[1] - metro.way.upLeftCoord[1]))
if metro.way.goToLeft {
for y := metro.way.downRightCoord[1]; y >= metro.way.upLeftCoord[1]; y-- {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
if metro.way.env.station[x][y] == "M" {
metro.way.env.station[x][y] = "Q"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
} else {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
if metro.way.env.station[x][y] == "M" {
metro.way.env.station[x][y] = "Q"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
}
} else {
waiting_time := time.Duration((metro_speed * 1000) / (metro.way.downRightCoord[0] - metro.way.upLeftCoord[0]))
if metro.way.goToLeft {
// de bas en haut
for x := metro.way.downRightCoord[0]; x >= metro.way.upLeftCoord[0]; x-- {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "M" {
metro.way.env.station[x][y] = "Q"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
} else {
for x := metro.way.upLeftCoord[0]; x <= metro.way.downRightCoord[0]; x++ {
for y := metro.way.upLeftCoord[1]; y <= metro.way.downRightCoord[1]; y++ {
if metro.way.env.station[x][y] == "M" {
metro.way.env.station[x][y] = "Q"
}
}
time.Sleep(waiting_time * time.Millisecond)
}
}
}
}
func (metro *Metro) dropAgents() {
func (metro *Metro) dropUsers() {
}
......@@ -4,11 +4,16 @@ package simulation
* Classe et méthodes principales de la structure Way (porte de métro)
*/
import (
alg "metrosim/internal/algorithms"
)
type Way struct {
id WayID
upLeftCoord Coord // inclus
downRightCoord Coord // inclus
goToLeft bool // si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
upLeftCoord Coord // inclus
downRightCoord Coord // inclus
goToLeft bool // si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
horizontal bool
gates []Coord //listes des portes associée à la voie
env *Environment
}
......@@ -23,11 +28,17 @@ func NewWay(wayId WayID, upLeftCoord, downRightCoord Coord, goToLeft bool, gates
}
}
/* Sens de la voie */
horizontal := true
if alg.Abs(upLeftCoord[0]-downRightCoord[0]) > alg.Abs(upLeftCoord[1]-downRightCoord[1]) {
horizontal = false
}
return &Way{
id: wayId,
upLeftCoord: upLeftCoord,
downRightCoord: downRightCoord,
goToLeft: goToLeft,
horizontal: horizontal,
gates: gates,
env: env}
}
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