Example #1
0
  /**
   * Public method to determine if the word has been solved
   *
   * @return boolean true if solved
   */
  public boolean isSolved() {

    /** Always use a local result */
    boolean result = false;

    /** No. of true occurrences */
    int countTrue = 0;

    /** Iterate over all letters, be sure there is an Assertion for each */
    List<CipherLetter> list = this.getLetters();
    int count = list.size();

    for (CipherLetter letter : list) {
      Stack<Assumption> stack = letter.getAffirmations().getStatements();
      for (int i = 0; i < stack.size(); i++) {
        Assumption assumption = stack.pop();
        if (!assumption.isRetractable()) {
          countTrue++;
        }
      }
    }

    /** If the no. of true occurrences equals the no. of letters it's solved */
    if (count == countTrue) {
      result = true;
    }

    return result;
  }
Example #2
0
 /**
  * Populates the HTML templates by replacing variables in the template string with the given value
  * string.
  *
  * @param template The template html to be populated
  * @param values Array of a variable, even number of key-value pairs: { "key1", "val1", "key2",
  *     "val2", ... }
  * @return The populated template
  */
 public static String populateTemplate(String template, String... values) {
   Assumption.assertTrue("The number of values passed in must be even", values.length % 2 == 0);
   String populatedTemplate = template;
   for (int i = 0; i < values.length; i += 2) {
     populatedTemplate = populatedTemplate.replace(values[i], values[i + 1]);
   }
   return populatedTemplate;
 }
 @Override
 public double executeFloat(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasFloat && receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
     return integerFixnumValue;
   } else {
     return next.executeFloat(receiver);
   }
 }
 @Override
 public boolean executeBoolean(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasBoolean && receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
     return booleanValue;
   } else {
     return next.executeBoolean(receiver);
   }
 }
 @Override
 public void leave(Node astNode, VirtualFrame frame, Object result) {
   try {
     inactiveAssumption.check();
   } catch (InvalidAssumptionException e) {
     final ActiveLeaveDebugProbe activeNode = createActive();
     replace(activeNode);
     activeNode.leave(astNode, frame, result);
   }
 }
 @Override
 public long executeLongFixnum(RubyBasicObject receiver) throws UnexpectedResultException {
   if (hasLongFixnum
       && receiver.getRubyClass() == expectedClass
       && unmodifiedAssumption.isValid()) {
     return longFixnumValue;
   } else {
     return next.executeLongFixnum(receiver);
   }
 }
  @Override
  public Object execute(RubyBasicObject receiver) {
    // TODO(CS): not sure trying next on invalid assumption is right...

    if (receiver.getRubyClass() == expectedClass && unmodifiedAssumption.isValid()) {
      return value;
    } else {
      return next.execute(receiver);
    }
  }
Example #8
0
 /**
  * Transforms the already calculated term into a new implication of the already calculated term
  * and the given assertion.
  */
 @Override
 public Assumption assume(Assumption assumption) {
   wp = new Implication(assumption.getTerm(), wp);
   return null;
 }
 /**
  * Substitutes the middle third of the given string with dots and returns the "obscured" string
  *
  * @param inputString
  * @return
  */
 public static String obscure(String inputString) {
   Assumption.assertNotNull(inputString);
   String frontPart = inputString.substring(0, inputString.length() / 3);
   String endPart = inputString.substring(2 * inputString.length() / 3);
   return frontPart + ".." + endPart;
 }