-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAgent.java
More file actions
73 lines (69 loc) · 2.06 KB
/
Copy pathAgent.java
File metadata and controls
73 lines (69 loc) · 2.06 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
import java.util.Arrays;
import com.supermarket.*;
// Use this as a template to develop your agent
public class Agent extends SupermarketComponentImpl {
public Agent() {
super();
shouldRunExecutionLoop = true;
log.info("In Agent constructor.");
}
boolean firsttime = true;
@Override
protected void executionLoop() {
// this is called every 100ms
/* put your code in here, you can use the following functions to control your agent:
nop();
startGame();
resetGame();
goNorth();
goSouth();
goEast();
goWest();
toggleShoppingCart();
interactWithObject();
cancelInteraction();
*/
SupermarketObservation obs = getLastObservation();
if (firsttime) {
System.out.println(obs.players.length + " players");
System.out.println(obs.carts.length + " carts");
System.out.println(obs.shelves.length + " shelves");
System.out.println(obs.counters.length + " counters");
System.out.println(obs.registers.length + " registers");
System.out.println(obs.cartReturns.length + " cartReturns");
// print out the shopping list
System.out.println("Shoppping list: " + Arrays.toString(obs.players[0].shopping_list));
firsttime = false;
}
// get cart
SupermarketObservation.CartReturn cartreturn = obs.cartReturns[0];
double x = cartreturn.position[0];
double y = cartreturn.position[1];
SupermarketObservation.Player me = obs.players[0];
double myx = me.position[0];
double myy = me.position[1];
System.out.println("Player (x,y) " + myx + " " + myy);
System.out.println("CartReturn (x,y) " + x + " " + y);
goEast();
goEast();
goEast();
while(!cartreturn.canInteract(me)) {
goSouth();
obs = getLastObservation();
cartreturn = obs.cartReturns[0];
me = obs.players[0];
/*
myx = me.position[0];
myy = me.position[1];
System.out.println("Player (x,y) " + myx + " " + myy);
*/
}
// pick up the cart
System.out.println("Picking up cart");
interactWithObject();
// keeps going north, bumping into the counter
while(true) {
goNorth();
}
}
}