Skip to content

Instantly share code, notes, and snippets.

Created November 27, 2014 03:56
Show Gist options
  • Save anonymous/2deead22fd4a30fbdfdb to your computer and use it in GitHub Desktop.
Save anonymous/2deead22fd4a30fbdfdb to your computer and use it in GitHub Desktop.
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;
} //================
}
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())
{
while (this.seesCD())
{this.moveOn();} //to next empty slot
this.moveOn(); //to the slot after the first empty slot
while(this.seesSlot()&&seesCD())
this.moveOn();
valueToReturn=this.seesSlot();
while(!point.equals(getPosition()))
{this.backUp();}
}
return valueToReturn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment