-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlateau.java
142 lines (126 loc) · 3.46 KB
/
Plateau.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.util.ArrayList;
public class Plateau {
private boolean[][] monde; // tableau 2D representant les cases du plateau selon la convention blanc=false et noir=true
private int[][] colors;
private Fourmi[] f; // instance de la classe Fourmi se deplacant sur le plateau
private float decay = 1e-2f;
private float brightnessThreshold = .1f;
public Plateau(int w, int h) {
this.monde = new boolean[h][w];
this.colors = new int[h][w];
this.f = new Fourmi[10];
System.out.println(this.toString());
}
public Plateau(int w, int h, int fSize) {
this.monde = new boolean[h][w];
this.colors = new int[h][w];
this.f = new Fourmi[fSize];
}
public Plateau(int w, int h, int fSize, float decay, float brightnessThreshold) {
this.monde = new boolean[h][w];
this.colors = new int[h][w];
this.decay = decay;
if(this.getDecayRate() != 0) this.brightnessThreshold = brightnessThreshold;
this.f = new Fourmi[fSize];
System.out.println(this.toString());
}
// Accesseurs
public int getTaille(){
return this.monde.length*this.monde[0].length;
}
public int getWidth() {
return this.monde[0].length;
}
public int getHeight() {
return this.monde.length;
}
public boolean[][] getEtat(){
return this.monde;
}
public void setFourmis(Fourmi[] fs) {
this.f = fs;
}
public Fourmi getFourmi(){
return this.f[0];
}
public Fourmi[] getFourmis() {
return this.f;
}
public int getFourmisCount() {
int c=0;
for (Fourmi f : f)
if (f != null)
++c;
return c;
}
public int getMaxStepVelocity() {
int m = 1;
for (Fourmi f : this.f)
if(f != null && m < f.getStepVelocity())
m = f.getStepVelocity();
return m;
}
public int getMaxVelocity() {
int m = 1;
for (Fourmi f : this.f)
if(f != null && m < f.getVelocity())
m = f.getVelocity();
return m;
}
public boolean getCase(Fourmi f) {
return this.monde[f.getLigne()][f.getColonne()];
}
public int[][] getColors() {
return this.colors;
}
public float getDecayRate() {
return this.decay;
}
public float getBrightnessThreshold() {
return this.brightnessThreshold;
}
public void setDecayRate(float decay) { this.decay = decay;}
public void setBrightnessThreshold(float brght) { this.brightnessThreshold = brght;}
public void addFourmi(Fourmi f) {
for(int i = 0; i<this.f.length; i++) {
if(this.f[i] == null) {
this.f[i] = f;
break;
}
}
}
/**
* Mets a jour le plateau apres une iteration
*/
public void bougeFourmi(Fourmi f){
boolean caz = getCase(f);
f.tourner(caz);
for(int v = 0; v < f.getVelocity(); v++) {
switchCase(f);
f.avance();
collide(f);
if(f.isOut(this)) f.getIn(this);
}
}
private void collide(Fourmi f) {
for (Fourmi fourmi : this.f) {
if(f != fourmi && f.collidesWith(fourmi)) f.onCollideWith(fourmi);
}
}
private void switchCase(Fourmi f) {
this.monde[f.getLigne()][f.getColonne()] = !getCase(f); //noire
this.colors[f.getLigne()][f.getColonne()] = f.getColor().getRGB();
}
public String toString() {
int b=0;
for(Fourmi a : this.f) {
if (a != null) b++;
}
return "Plateau: taille="+this.getTaille()+", "
+b+"/"+this.getFourmis().length+", \n"
+"decay="+(this.getDecayRate() == 0 ? "none": this.getDecayRate())+",\n"
+" brightnessThreshold="+(this.getDecayRate() == 0 ? "none": this.getBrightnessThreshold())+"\n"
+" maxStepVelocity="+this.getMaxStepVelocity()+"\n"
+" maxVelocity="+this.getMaxVelocity();
}
}