-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblackboard.java
More file actions
117 lines (90 loc) · 2.83 KB
/
blackboard.java
File metadata and controls
117 lines (90 loc) · 2.83 KB
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
import jason.asSyntax.*;
import jason.environment.Environment;
import jason.environment.grid.GridWorldModel;
import jason.environment.grid.GridWorldView;
import jason.environment.grid.Location;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Random;
import java.util.logging.Logger;
public class blackboard extends Environment {
public static final int GSize = 8; // tamaño tablero
public static final int BLUE = 10; // ficha azul
private Logger logger = Logger.getLogger("conecta4.mas2j."+blackboard.class.getName());
private MarsModel model;
private MarsView view;
@Override
public void init(String[] args) {
model = new MarsModel(); //crear un modelo
view = new MarsView(model); //crear la vista con ese modelo
model.setView(view); //asociar
}
@Override
public boolean executeAction(String ag, Structure action) {
logger.info(ag+" doing: "+ action);
try {
if (action.getFunctor().equals("put")) {
int x = (int)((NumberTerm)action.getTerm(0)).solve();
model.put(x);
} else{return false;}
} catch (Exception e) {
e.printStackTrace();
}
updatePercepts();
try {
Thread.sleep(200);
} catch (Exception e) {}
informAgsEnvironmentChanged();
return true;
}
void updatePercepts() {
}
class MarsModel extends GridWorldModel {
Random random = new Random(System.currentTimeMillis());
private MarsModel() {
super(GSize, GSize, 2);
// initial location of agents
try {
//setAgPos(0, 0, 0);
Location r2Loc = new Location(GSize/2, GSize/2);
//setAgPos(1, r2Loc);
} catch (Exception e) {
e.printStackTrace();
}
// initial location of garbage
}
public void put(int x) {
try{
int p=getHeight();
while(p>=0 &&!isFree(x,p)){
p--;
}
if(p <0){
System.out.println("overflow");
}else{
add(BLUE,x,p);
Thread.sleep(700);
}
}catch (Exception e) { }
}
}
class MarsView extends GridWorldView {
public MarsView(MarsModel model) {
super(model, "Conecta4", 600);
defaultFont = new Font("Arial", Font.BOLD, 18); // change default font
setVisible(true);
repaint();
}
public void draw(Graphics g, int x, int y, int object) {
switch (object) {
case blackboard.BLUE: drawFicha(g, x, y, 2); break;
}
}
public void drawFicha(Graphics g, int x, int y, int id) {
if (id == 1) g.setColor(Color.blue);
else g.setColor(Color.red);
g.fillOval(x,y,70,70);
}
}
}