Skip to content

Instantly share code, notes, and snippets.

@evanc
Forked from anonymous/gist:2deead22fd4a30fbdfdb
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save evanc/8dc8ddaecbca6f63c552 to your computer and use it in GitHub Desktop.

Select an option

Save evanc/8dc8ddaecbca6f63c552 to your computer and use it in GitHub Desktop.
public class smartVic extends Vic {
public void backUpTo(String someSpot) {
while (!someSpot.equals(getPosition())) {
backUp();
}
}
public boolean hasSomeEmptySlot() {
String point;
point = getPosition();
while (seesSlot() && seesCD()) {
this.moveOn();
}
boolean valueToReturn;
valueToReturn = seesSlot();
while (!point.equals(getPosition())) {
this.backUp();
}
return valueToReturn;
}
public String lastEmptySlot() {
String place = this.getPosition();
String lastEmpty = place; // in case no later slot is empty
while (this.seesSlot()) {
if (!this.seesCD()) {
lastEmpty = place;
}
this.moveOn();
}
this.backUpTo(place);
return lastEmpty;
}
public boolean hasTwoEmpty() {
String point = getPosition();
boolean valueToReturn;
valueToReturn = false;
if (this.hasSomeEmptySlot()){
//to next empty slot
while (this.seesCD()) {
this.moveOn();
}
//to the slot after the first empty slot
this.moveOn();
while(this.seesSlot() && seesCD()) {
this.moveOn();
}
valueToReturn = this.seesSlot();
while(!point.equals(getPosition())) {
this.backUp();
}
}
return valueToReturn;
}
}
public class Looper extends smartVic {
public String secondToLastEmpty() {
String spot = this.getPosition();
String secondToLastEmpty = spot;
if (this.hasTwoEmpty()) {
this.lastEmptySlot();
this.backUp();
secondToLastEmpty=spot;
}
return secondToLastEmpty;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment