@matfah/

Fuel Depot FR 2011

Java

No description

fork
loading
Files
  • Main.java
  • FuelDepot.java
  • FuelRobot.java
  • FuelTank.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5116377616291155","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLnJlZmxlY3QuKjsKCnB1YmxpYyBjbGFzcyBNYWluIHsKICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAxMDAwOyBpKyspCiAgICAgIHRlc3ROZXh0VGFua1RvRmlsbCgpOwogICAgZm9yKGludCBpID0gMDsgaSA8IDEwMDA7IGkrKykKICAgICAgdGVzdE1vdmVUb0xvY2F0aW9uKCk7CiAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkFsbCB0ZXN0cyBwYXNzZWQhIik7CiAgfQogIAogIHB1YmxpYyBzdGF0aWMgdm9pZCB0ZXN0TmV4dFRhbmtUb0ZpbGwoKSB7CiAgICAKICAgIEZ1ZWxEZXBvdCBkZXBvdCA9IG5ldyBGdWVsRGVwb3QoKTsKICAgIAogICAgQXJyYXlMaXN0PEZ1ZWxUYW5rPiB0YW5rcyA9IG5ldyBBcnJheUxpc3Q8RnVlbFRhbms+KCk7CiAgICBTdHJpbmcgdGFua3NTdHIgPSAiIjsKICAgIAogICAgQXJyYXlMaXN0PEludGVnZXI+IG1pblBvcyA9IG5ldyBBcnJheUxpc3Q8SW50ZWdlcj4oKTsKICAgIAogICAgaW50IGxldmVsID0gKGludCkoTWF0aC5yYW5kb20oKSoyMCk7CiAgICAKICAgIGludCBuZXh0ID0gMDsKICAgIGZvcihpbnQgaSA9IChpbnQpKE1hdGgucmFuZG9tKCkqMjApKzE7IGkgPiAwOyBpLS0pIHsKICAgICAgaW50IHRhbmtMZXZlbCA9IChpbnQpKE1hdGgucmFuZG9tKCkqMTAwKTsKICAgICAgaWYodGFua0xldmVsIDwgbGV2ZWwpIHsKICAgICAgICAKICAgICAgICBpZihtaW5Qb3Muc2l6ZSgpID09IDAgfHwgdGFua3MuZ2V0KG1pblBvcy5nZXQoMCkpLmdldEZ1ZWxMZXZlbCgpID09IHRhbmtMZXZlbCkgewogICAgICAgICAgbWluUG9zLmFkZChuZXh0KTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZih0YW5rcy5nZXQobWluUG9zLmdldCgwKSkuZ2V0RnVlbExldmVsKCkgPiB0YW5rTGV2ZWwpIHsKICAgICAgICAgIG1pblBvcy5jbGVhcigpOwogICAgICAgICAgbWluUG9zLmFkZChuZXh0KTsKICAgICAgICB9CiAgICAgICAgCiAgICAgIAogICAgICB9CiAgICAgIHRhbmtzLmFkZChuZXcgQ3VzdG9tRnVlbFRhbmsodGFua0xldmVsKSk7CiAgICAgIHRhbmtzU3RyICs9IHRhbmtzLmdldCh0YW5rcy5zaXplKCktMSk7CiAgICAgIG5leHQrKzsKICAgIH0KICAgIAogICAgRnVlbFJvYm90IGZpbGxlciA9IG5ldyBDdXN0b21GdWVsUm9ib3QoKGludCkoTWF0aC5yYW5kb20oKSp0YW5rcy5zaXplKCkpLCBNYXRoLnJhbmRvbSgpPDAuNSk7CiAgICBpbnQgb2xkUG9zID0gZmlsbGVyLmdldEN1cnJlbnRJbmRleCgpOwogICAgYm9vbGVhbiBvbGRGYWNpbmcgPSBmaWxsZXIuaXNGYWNpbmdSaWdodCgpOwogICAgCiAgICBpZihtaW5Qb3Muc2l6ZSgpID09IDApCiAgICAgIG1pblBvcy5hZGQob2xkUG9zKTsKCiAgICBGaWVsZCBmaWxsZXJGaWVsZCA9IG51bGw7CiAgICAKICAgIHRyeSB7CiAgICAgIGZpbGxlckZpZWxkID0gRnVlbERlcG90LmNsYXNzLmdldERlY2xhcmVkRmllbGQoImZpbGxlciIpOwogICAgfQogICAgY2F0Y2goRXhjZXB0aW9uIGUpI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7CiAgfQogIAogIHB1YmxpYyBib29sZWFuIGlzRmFjaW5nUmlnaHQoKSB7CiAgICByZXR1cm4gZmFjaW5nUmlnaHQ7CiAgfQogIAogIHB1YmxpYyB2b2lkIGNoYW5nZURpcmVjdGlvbigpIHsKICAgIGZhY2luZ1JpZ2h0ID0gIWZhY2luZ1JpZ2h0OwogIH0KICAKICBwdWJsaWMgdm9pZCBtb3ZlRm9yd2FyZChpbnQgbnVtTG9jcykgewogICAgaWYoZmFjaW5nUmlnaHQpIGxvYyArPSBudW1Mb2NzOwogICAgZWxzZSBsb2MgLT0gbnVtTG9jczsKICAgIAogICAgbG9jcy5hZGQobG9jKTsKICB9Cgp9"},"asBuffer":null},"loaded":true}}
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import java.util.*;
import java.lang.reflect.*;

public class Main {
  public static void main(String[] args) {
    
    for(int i = 0; i < 1000; i++)
      testNextTankToFill();
    for(int i = 0; i < 1000; i++)
      testMoveToLocation();
    System.out.println("All tests passed!");
  }
  
  public static void testNextTankToFill() {
    
    FuelDepot depot = new FuelDepot();
    
    ArrayList<FuelTank> tanks = new ArrayList<FuelTank>();
    String tanksStr = "";
    
    ArrayList<Integer> minPos = new ArrayList<Integer>();
    
    int level = (int)(Math.random()*20);
    
    int next = 0;
    for(int i = (int)(Math.random()*20)+1; i > 0; i--) {
      int tankLevel = (int)(Math.random()*100);
      if(tankLevel < level) {
        
        if(minPos.size() == 0 || tanks.get(minPos.get(0)).getFuelLevel() == tankLevel) {
          minPos.add(next);
        }
        else if(tanks.get(minPos.get(0)).getFuelLevel() > tankLevel) {
          minPos.clear();
          minPos.add(next);
        }
        
      
      }
      tanks.add(new CustomFuelTank(tankLevel));
      tanksStr += tanks.get(tanks.size()-1);
      next++;
    }
    
    FuelRobot filler = new CustomFuelRobot((int)(Math.random()*tanks.size()), Math.random()<0.5);
    int oldPos = filler.getCurrentIndex();
    boolean oldFacing = filler.isFacingRight();
    
    if(minPos.size() == 0)
      minPos.add(oldPos);

    Field fillerField = null;
    
    try {
      fillerField = FuelDepot.class.getDeclaredField("filler");
    }
    catch(Exception e) {
      System.out.println("Error accessing filler instance variable");
      System.exit(0);
    }
    
    fillerField.setAccessible(true);
    
    try {
      fillerField.set(depot, filler);
    }
    catch(Exception e) {
      System.out.println("Error setting filler instance variable");
      System.exit(0);
    }
    
    Field tanksField = null;
    
    try {
      tanksField = FuelDepot.class.getDeclaredField("tanks");
    }
    catch(Exception e) {
      System.out.println("Error accessing tanks instance variable");
      System.exit(0);
    }
    
    tanksField.setAccessible(true);
    
    try {
      tanksField.set(depot, tanks);
    }
    catch(Exception e) {
      System.out.println("Error setting tanks instance variable");
      System.exit(0);
    }
    
    int pos = 0;
    try {
      pos = depot.nextTankToFill(level);
    }
    catch(Exception e) {
      System.out.println("Error calling nextTankToFill() method");
      System.exit(0);
    }
    
    if(!minPos.contains(pos)) {
      
      System.out.println("nextTankToFill() is not returning the right value");
      System.exit(0);
    }
    
    ArrayList<FuelTank> updatedTank = null;
    try {
      updatedTank = (ArrayList<FuelTank>)tanksField.get(depot);
    }
    catch(Exception e) {
      System.out.println("Error accessing tanks instance variable");
      System.exit(0);
    }
    
    String resultTanks = "";
    
    for(FuelTank tank: updatedTank)
      resultTanks += tank;
      
    if(!resultTanks.equals(tanksStr)) {
      System.out.println("nextTankToFill() should not change the tanks instance variable!");
      System.exit(0);
    }
    
    if(filler.getCurrentIndex() != oldPos || filler.isFacingRight() != oldFacing) {
      System.out.println("nextTankToFill() should not change the filler instance variable!");
      System.exit(0);
    }
    
  }
  
  public static void testMoveToLocation() {
    FuelDepot depot = new FuelDepot();
    
    ArrayList<FuelTank> tanks = new ArrayList<FuelTank>();
    String tanksStr = "";
    
    int next = 0;
    for(int i = (int)(Math.random()*20)+1; i > 0; i--) {
      int tankLevel = (int)(Math.random()*100);
      tanks.add(new CustomFuelTank(tankLevel));
      tanksStr += tanks.get(tanks.size()-1);
      next++;
    }
    
    FuelRobot filler = new CustomFuelRobot((int)(Math.random()*tanks.size()), Math.random()<0.5);
    Field fillerField = null;
    
    try {
      fillerField = FuelDepot.class.getDeclaredField("filler");
    }
    catch(Exception e) {
      System.out.println("Error accessing filler instance variable");
      System.exit(0);
    }
    
    fillerField.setAccessible(true);
    
    try {
      fillerField.set(depot, filler);
    }
    catch(Exception e) {
      System.out.println("Error setting filler instance variable");
      System.exit(0);
    }
    
    Field tanksField = null;
    
    try {
      tanksField = FuelDepot.class.getDeclaredField("tanks");
    }
    catch(Exception e) {
      System.out.println("Error accessing tanks instance variable");
      System.exit(0);
    }
    
    tanksField.setAccessible(true);
    
    try {
      tanksField.set(depot, tanks);
    }
    catch(Exception e) {
      System.out.println("Error setting tanks instance variable");
      System.exit(0);
    }
    
    int newLoc = (int)(Math.random() * tanks.size());
    
    try {
      depot.moveToLocation(newLoc);
    }
    catch(Exception e) {
      System.out.println("Error calling moveToLocation()");
      System.exit(0);
    }
    
    if(filler.getCurrentIndex() != newLoc) {
      System.out.println("moveToLocation() does not move the robot to the correct position");
      System.exit(0);
    }
    
    ArrayList<Integer> locs = ((CustomFuelRobot)filler).locs;
    
    for(int x : locs) {
      if(x < 0 || x >= tanks.size()) {
        System.out.println("moveToLocation() moves the robot out of bounds");
        System.exit(0);
      }
    }
    
    ArrayList<FuelTank> updatedTank = null;
    try {
      updatedTank = (ArrayList<FuelTank>)tanksField.get(depot);
    }
    catch(Exception e) {
      System.out.println("Error accessing tanks instance variable");
      System.exit(0);
    }
    
    String resultTanks = "";
    
    for(FuelTank tank: updatedTank)
      resultTanks += tank;
      
    if(!resultTanks.equals(tanksStr)) {
      System.out.println("moveToLocation() should not change the tanks instance variable!");
      System.exit(0);
    }
  }
}

class CustomFuelTank implements FuelTank {
  
  int level;
  
  public CustomFuelTank(int lev) {
    level = lev;
  }
  
  public int getFuelLevel() {
    return level;
  }
}

class CustomFuelRobot implements FuelRobot {

  private int loc;
  private boolean facingRight;
  
  ArrayList<Integer> locs = new ArrayList<Integer>();
  
  public CustomFuelRobot(int loc, boolean facingRight) {
    this.loc = loc;
    this.facingRight = facingRight;
  }

  public int getCurrentIndex() {
    return loc;
  }
  
  public boolean isFacingRight() {
    return facingRight;
  }
  
  public void changeDirection() {
    facingRight = !facingRight;
  }
  
  public void moveForward(int numLocs) {
    if(facingRight) loc += numLocs;
    else loc -= numLocs;
    
    locs.add(loc);
  }

}