fix reserves for not looped routes
This commit is contained in:
@@ -308,6 +308,7 @@ public class Route implements Comparable<Route> {
|
|||||||
public LoopIterator loopIterator(int from){
|
public LoopIterator loopIterator(int from){
|
||||||
return new LoopIterator() {
|
return new LoopIterator() {
|
||||||
private final int size = entries.size() - (isLoop() ? 1 : 0);
|
private final int size = entries.size() - (isLoop() ? 1 : 0);
|
||||||
|
private final int maxIndex = isLoop() ? size - 1 : size - from;
|
||||||
private int i = -1;
|
private int i = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -324,7 +325,7 @@ public class Route implements Comparable<Route> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return i < size-1;
|
return i < maxIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -421,11 +421,14 @@ public class RouteFiller {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getLastIndex(final int fromIndex, final Offer buyOffer, final Order[] sells){
|
private static int getLastIndex(final int fromIndex, final Offer buyOffer, final Order[] sells, boolean isLoop){
|
||||||
long need = buyOffer.getCount();
|
long need = buyOffer.getCount();
|
||||||
for (int i = 0; i < sells.length; i++) {
|
for (int i = 0; i < sells.length; i++) {
|
||||||
int index = i + fromIndex;
|
int index = i + fromIndex;
|
||||||
if (index >= sells.length) index -= sells.length;
|
if (index >= sells.length){
|
||||||
|
if (isLoop) index -= sells.length;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
Order sell = sells[index];
|
Order sell = sells[index];
|
||||||
if (sell == null) continue;
|
if (sell == null) continue;
|
||||||
if (sell.getCount() >= need) {
|
if (sell.getCount() >= need) {
|
||||||
@@ -465,7 +468,7 @@ public class RouteFiller {
|
|||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.sell = orders[index];
|
this.sell = orders[index];
|
||||||
int lastIndex = getLastIndex(index, buyOffer, orders);
|
int lastIndex = getLastIndex(index, buyOffer, orders, route.isLoop());
|
||||||
if (lastIndex != -1) {
|
if (lastIndex != -1) {
|
||||||
endIndex = route.find(buyOffer.getVendor(), lastIndex+1);
|
endIndex = route.find(buyOffer.getVendor(), lastIndex+1);
|
||||||
if (endIndex != -1) {
|
if (endIndex != -1) {
|
||||||
@@ -481,7 +484,7 @@ public class RouteFiller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSeller(){
|
private boolean isSeller(){
|
||||||
return sell != null && endIndex != -1;
|
return sell != null && endIndex != -1 && (endIndex >= index || route.isLoop());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getProfit(){
|
private double getProfit(){
|
||||||
|
|||||||
Reference in New Issue
Block a user