Example #1
0
  private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);
    if (split.length == 1) {
      technique = new TechniqueDef(null);
    } else if (split.length == 2) {
      String techName = split[1];
      technique = new TechniqueDef(techName);
    } else {
      throw new IOException("Technique statement syntax incorrect");
    }

    for (Statement statement : techStat.getContents()) {
      readTechniqueStatement(statement);
    }

    if (isUseNodes) {
      nodesLoaderDelegate.computeConditions();
      // used for caching later, the shader here is not a file.
      technique.setShaderFile(
          technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
    }

    if (shaderName.containsKey(Shader.ShaderType.Vertex)
        && shaderName.containsKey(Shader.ShaderType.Fragment)) {
      technique.setShaderFile(shaderName, shaderLanguage);
    }

    materialDef.addTechniqueDef(technique);
    technique = null;
    shaderLanguage.clear();
    shaderName.clear();
  }
Example #2
0
 /**
  * Turns the majority of the given percentage of floor cells into water cells, represented by '~'.
  * Water will be clustered into a random number of pools, with more appearing if needed to fill
  * the percentage. Each pool will have randomized volume that should fill or get very close to
  * filling the requested percentage, unless the pools encounter too much tight space. If this
  * DungeonGenerator previously had addWater called, the latest call will take precedence. If
  * islandSpacing is greater than 1, then this will place islands of floor, '.', surrounded by
  * shallow water, ',', at about the specified distance with Euclidean measurement.
  *
  * @param percentage the percentage of floor cells to fill with water
  * @param islandSpacing if greater than 1, islands will be placed randomly this many cells apart.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addWater(int percentage, int islandSpacing) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.WATER)) fx.remove(FillEffect.WATER);
   fx.put(FillEffect.WATER, percentage);
   if (fx.containsKey(FillEffect.ISLANDS)) fx.remove(FillEffect.ISLANDS);
   if (islandSpacing > 1) fx.put(FillEffect.ISLANDS, islandSpacing);
   return this;
 }
Example #3
0
 /**
  * Turns the majority of the given percentage of floor cells into water cells, represented by '~'.
  * Water will be clustered into a random number of pools, with more appearing if needed to fill
  * the percentage. Each pool will have randomized volume that should fill or get very close to
  * filling the requested percentage, unless the pools encounter too much tight space. If this
  * DungeonGenerator previously had addWater called, the latest call will take precedence. No
  * islands will be placed with this variant, but the edge of the water will be shallow,
  * represented by ','.
  *
  * @param percentage the percentage of floor cells to fill with water
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addWater(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.WATER)) fx.remove(FillEffect.WATER);
   fx.put(FillEffect.WATER, percentage);
   return this;
 }
Example #4
0
 /**
  * Turns the given percentage of floor cells not already adjacent to walls into wall cells,
  * represented by '#'. If this DungeonGenerator previously had addBoulders called, the latest call
  * will take precedence.
  *
  * @param percentage the percentage of floor cells not adjacent to walls to fill with boulders.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addBoulders(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.BOULDERS)) fx.remove(FillEffect.BOULDERS);
   fx.put(FillEffect.BOULDERS, percentage);
   return this;
 }
Example #5
0
 /**
  * Turns the given percentage of open area floor cells into trap cells, represented by '^'.
  * Corridors that have no possible way to move around a trap will not receive traps, ever. If this
  * DungeonGenerator previously had addTraps called, the latest call will take precedence.
  *
  * @param percentage the percentage of valid cells to fill with traps; should be no higher than 5
  *     unless the dungeon floor is meant to be a kill screen or minefield.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addTraps(int percentage) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (fx.containsKey(FillEffect.TRAPS)) fx.remove(FillEffect.TRAPS);
   fx.put(FillEffect.TRAPS, percentage);
   return this;
 }
Example #6
0
 public Strategy strategyFor(CircleDimension dimension) {
   if (strategies.containsKey(dimension)) {
     return strategies.get(dimension);
   } else {
     return dimension.defaultStrategy();
   }
 }
Example #7
0
 protected void addCount(ResultType type) throws CouldNotReceiveResultException {
   if (!resultCounts.containsKey(type)) {
     resultCounts.put(type, 1);
   } else {
     resultCounts.put(type, resultCounts.get(type) + 1);
   }
 }
Example #8
0
 /**
  * Turns the given percentage of viable doorways into doors, represented by '+' for doors that
  * allow travel along the x-axis and '/' for doors that allow travel along the y-axis. If
  * doubleDoors is true, 2-cell-wide openings will be considered viable doorways and will fill one
  * cell with a wall, the other a door. If this DungeonGenerator previously had addDoors called,
  * the latest call will take precedence.
  *
  * @param percentage the percentage of valid openings to corridors to fill with doors; should be
  *     between 10 and 20 if you want doors to appear more than a few times, but not fill every
  *     possible opening.
  * @param doubleDoors true if you want two-cell-wide openings to receive a door and a wall; false
  *     if only one-cell-wide openings should receive doors. Usually, this should be true.
  * @return this DungeonGenerator; can be chained
  */
 public DungeonGenerator addDoors(int percentage, boolean doubleDoors) {
   if (percentage < 0) percentage = 0;
   if (percentage > 100) percentage = 100;
   if (doubleDoors) percentage *= -1;
   if (fx.containsKey(FillEffect.DOORS)) fx.remove(FillEffect.DOORS);
   fx.put(FillEffect.DOORS, percentage);
   return this;
 }
Example #9
0
 public synchronized void decreaseStock(Book book, int quantity, int jobSeqNum)
     throws InterruptedException {
   while (!inventory.containsKey(book) || inventory.get(book).intValue() < quantity) {
     wait();
   }
   inventory.put(book, inventory.get(book) - quantity);
   printWork(false, jobSeqNum, book, inventory.get(book) + quantity, inventory.get(book));
 }
Example #10
0
  @Override
  public TerminalSize getPreferredSize(List<Component> components) {
    EnumMap<Location, Component> layout = makeLookupMap(components);
    int preferredHeight =
        (layout.containsKey(Location.TOP)
                ? layout.get(Location.TOP).getPreferredSize().getRows()
                : 0)
            + Math.max(
                layout.containsKey(Location.LEFT)
                    ? layout.get(Location.LEFT).getPreferredSize().getRows()
                    : 0,
                Math.max(
                    layout.containsKey(Location.CENTER)
                        ? layout.get(Location.CENTER).getPreferredSize().getRows()
                        : 0,
                    layout.containsKey(Location.RIGHT)
                        ? layout.get(Location.RIGHT).getPreferredSize().getRows()
                        : 0))
            + (layout.containsKey(Location.BOTTOM)
                ? layout.get(Location.BOTTOM).getPreferredSize().getRows()
                : 0);

    int preferredWidth =
        Math.max(
            (layout.containsKey(Location.LEFT)
                    ? layout.get(Location.LEFT).getPreferredSize().getColumns()
                    : 0)
                + (layout.containsKey(Location.CENTER)
                    ? layout.get(Location.CENTER).getPreferredSize().getColumns()
                    : 0)
                + (layout.containsKey(Location.RIGHT)
                    ? layout.get(Location.RIGHT).getPreferredSize().getColumns()
                    : 0),
            Math.max(
                layout.containsKey(Location.TOP)
                    ? layout.get(Location.TOP).getPreferredSize().getColumns()
                    : 0,
                layout.containsKey(Location.BOTTOM)
                    ? layout.get(Location.BOTTOM).getPreferredSize().getColumns()
                    : 0));
    return new TerminalSize(preferredWidth, preferredHeight);
  }
 private static void updateEndLine(int expectedLine, EnumMap<IssueAttribute, String> attr) {
   if (attr.containsKey(IssueAttribute.END_LINE)) {
     String endLineStr = attr.get(IssueAttribute.END_LINE);
     if (endLineStr.charAt(0) == '+') {
       int endLine = Integer.parseInt(endLineStr);
       attr.put(IssueAttribute.END_LINE, Integer.toString(expectedLine + endLine));
     } else {
       Fail.fail("endLine attribute should be relative to the line and must be +N with N integer");
     }
   }
 }
  public void testEnumMap() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    String JSON = "{ \"KEY1\" : \"\", \"WHATEVER\" : null }";

    // to get typing, must use type reference
    EnumMap<Key, String> result =
        mapper.readValue(JSON, new TypeReference<EnumMap<Key, String>>() {});

    assertNotNull(result);
    assertEquals(EnumMap.class, result.getClass());
    assertEquals(2, result.size());

    assertEquals("", result.get(Key.KEY1));
    // null should be ok too...
    assertTrue(result.containsKey(Key.WHATEVER));
    assertNull(result.get(Key.WHATEVER));

    // plus we have nothing for this key
    assertFalse(result.containsKey(Key.KEY2));
    assertNull(result.get(Key.KEY2));
  }
 /**
  * Check if all required attributes are present.
  *
  * @param <T> type of the enumeration describing attributes
  * @param e the event
  * @param attributes extracted attributes
  * @param required array of required attributes
  * @throws XMLStreamException if at least one required attribute is not found
  */
 protected <T extends Enum<T>> void checkRequiredAttributes(
     XMLEvent e, EnumMap<T, String> attributes, T... required) throws XMLStreamException {
   if (required != null) {
     for (int i = 0; i < required.length; i++) {
       if (!attributes.containsKey(required[i]))
         throw newParseError(
             e,
             "'%s' attribute is required for <%s> element",
             required[i].name().toLowerCase(),
             e.asStartElement().getName().getLocalPart());
     }
   }
 }
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    EnumMap<PlayerStats, Float> enumMap = new EnumMap<PlayerStats, Float>(PlayerStats.class);
    for (PlayerStats a : PlayerStats.values())
      if (!enumMap.containsKey(a)) enumMap.put(a, Float.NaN);

    String input;
    System.out.println(MENU);
    do {
      input = scanner.next().toLowerCase();
      switch (input) {
        case "print":
          printMap(enumMap);
          break;
        case "menu":
          System.out.println(MENU);
          break;
        case "load":
          System.out.print("Type in the file to load: ");
          EnumMap<PlayerStats, Float> loadedMap = DataLoader.loadPlayerObject(scanner.next());
          if (loadedMap == null) {
            System.out.println("Cannot load this file!");
            break;
          }
          enumMap = loadedMap;
          break;
        case "save":
          System.out.print("Type in the file to save to: ");
          saveData(scanner.next(), enumMap, true);
          break;
        case "iterate":
          iterateAll(scanner, enumMap);
          break;
        case "edit":
          System.out.print("Type in the property: ");
          input = scanner.next();
          PlayerStats playerStats = PlayerStats.valueOf(input);
          if (playerStats == null) System.out.println(input + " is not a property");
          else {
            System.out.print("Type in the value");
            processInput(enumMap, playerStats, scanner.next());
          }
          break;
        case "exit":
          break;
        default:
          System.out.println("You typed in an invalid menu option\n" + MENU);
          break;
      }
    } while (!input.equals("exit"));
  }
Example #15
0
 public void waitFor(E message) {
   synchronized (message) {
     assert !reservedMessages.containsKey(message)
         : "Thread '" + reservedMessages.get(message) + "' already reserved this message";
     reservedMessages.put(message, java.lang.Thread.currentThread());
     while (!sentMessages.contains(message)) {
       try {
         message.wait();
       } catch (InterruptedException ex) {
         throw new InterruptedExceptionRuntimeException(ex);
       }
     }
   }
 }
Example #16
0
  private EnumMap<GHOST, MOVE> _completeGhostMoves(EnumMap<GHOST, MOVE> moves) {
    if (moves == null) {
      moves = new EnumMap<GHOST, MOVE>(GHOST.class);

      for (GHOST ghostType : GHOST.values())
        moves.put(ghostType, fantasmas.get(ghostType).lastMoveMade);
    }

    if (moves.size() < NUM_GHOSTS)
      for (GHOST ghostType : GHOST.values())
        if (!moves.containsKey(ghostType)) moves.put(ghostType, MOVE.NEUTRAL);

    return moves;
  }
 /**
  * @param name The name for the block group.
  * @param blocks The set of blocks that make up the group. Front, Back, Left and Right must be
  *     provided - the rest is ignored.
  */
 public AlignToSurfaceFamily(String name, EnumMap<Side, Block> blocks) {
   _name = name;
   for (Side side : Side.values()) {
     Block block = blocks.get(side);
     if (block != null) {
       _blocks.put(side, block);
       block.withBlockFamily(this);
     }
   }
   if (_blocks.containsKey(Side.TOP)) {
     _archetype = _blocks.get(Side.TOP);
   } else {
     _archetype = _blocks.get(Side.FRONT);
   }
 }
Example #18
0
 // DON'T CHANGE THIS; WE'RE USING IT FOR SERIALIZATION!!!
 @Override
 public String toString() {
   if (stringForm == null) {
     StringBuilder sb = new StringBuilder();
     String prefix = "";
     for (Service service : new Service[] {Service.TSERV_CLIENT, Service.GC_CLIENT}) {
       if (services.containsKey(service)) {
         sb.append(prefix)
             .append(service.name())
             .append(SEPARATOR_CHAR)
             .append(services.get(service));
         prefix = SERVICE_SEPARATOR;
       }
     }
     stringForm = sb.toString();
   }
   return stringForm;
 }
Example #19
0
 private EnumMap<Location, Component> makeLookupMap(List<Component> components) {
   EnumMap<Location, Component> map =
       new EnumMap<BorderLayout.Location, Component>(Location.class);
   List<Component> unassignedComponents = new ArrayList<Component>();
   for (Component component : components) {
     if (component.getLayoutData() instanceof Location) {
       map.put((Location) component.getLayoutData(), component);
     } else {
       unassignedComponents.add(component);
     }
   }
   // Try to assign components to available locations
   for (Component component : unassignedComponents) {
     for (Location location : AUTO_ASSIGN_ORDER) {
       if (!map.containsKey(location)) {
         map.put(location, component);
         break;
       }
     }
   }
   return map;
 }
Example #20
0
 public synchronized void increaseStock(Book book, int quantity, int jobSeqNum) {
   if (inventory.containsKey(book)) inventory.put(book, inventory.get(book) + quantity);
   else inventory.put(book, quantity);
   printWork(true, jobSeqNum, book, inventory.get(book) - quantity, inventory.get(book));
   notifyAll();
 }
Example #21
0
 private int intent(AbstractAction forAction) {
   return !KIDS.containsKey(forAction) ? -1 : KIDS.get(forAction).intent();
 }
  private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);

    String name;
    if (split.length == 1) {
      name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
    } else if (split.length == 2) {
      name = split[1];
    } else {
      throw new IOException("Technique statement syntax incorrect");
    }

    String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
    technique = new TechniqueDef(name, techniqueUniqueName.hashCode());

    for (Statement statement : techStat.getContents()) {
      readTechniqueStatement(statement);
    }

    technique.setShaderPrologue(createShaderPrologue(presetDefines));

    switch (technique.getLightMode()) {
      case Disable:
        technique.setLogic(new DefaultTechniqueDefLogic(technique));
        break;
      case MultiPass:
        technique.setLogic(new MultiPassLightingLogic(technique));
        break;
      case SinglePass:
        technique.setLogic(new SinglePassLightingLogic(technique));
        break;
      case StaticPass:
        technique.setLogic(new StaticPassLightingLogic(technique));
        break;
      case SinglePassAndImageBased:
        technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
        break;
      default:
        throw new UnsupportedOperationException();
    }

    List<TechniqueDef> techniqueDefs = new ArrayList<>();

    if (isUseNodes) {
      nodesLoaderDelegate.computeConditions();

      // used for caching later, the shader here is not a file.

      // KIRILL 9/19/2015
      // Not sure if this is needed anymore, since shader caching
      // is now done by TechniqueDef.
      technique.setShaderFile(
          technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
      techniqueDefs.add(technique);
    } else if (shaderNames.containsKey(Shader.ShaderType.Vertex)
        && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
      if (shaderLanguages.size() > 1) {
        for (int i = 1; i < shaderLanguages.size(); i++) {
          TechniqueDef td = null;
          try {
            td = (TechniqueDef) technique.clone();
          } catch (CloneNotSupportedException e) {
            e.printStackTrace();
          }
          td.setShaderFile(shaderNames, shaderLanguages.get(i));
          techniqueDefs.add(td);
        }
      }
      technique.setShaderFile(shaderNames, shaderLanguages.get(0));
      techniqueDefs.add(technique);

    } else {
      technique = null;
      shaderLanguages.clear();
      shaderNames.clear();
      presetDefines.clear();
      langSize = 0;
      logger.log(Level.WARNING, "Fixed function technique was ignored");
      logger.log(
          Level.WARNING,
          "Fixed function technique ''{0}'' was ignored for material {1}",
          new Object[] {name, key});
      return;
    }

    for (TechniqueDef techniqueDef : techniqueDefs) {
      materialDef.addTechniqueDef(techniqueDef);
    }

    technique = null;
    langSize = 0;
    shaderLanguages.clear();
    shaderNames.clear();
    presetDefines.clear();
  }
  public void load(URL specModelURL, SpecificationModels featureSpecModels)
      throws MaltChainedException {
    BufferedReader br = null;
    Pattern tabPattern = Pattern.compile("\t");
    if (specModelURL == null) {
      throw new FeatureException("The feature specification file cannot be found. ");
    }
    try {
      br = new BufferedReader(new InputStreamReader(specModelURL.openStream()));
    } catch (IOException e) {
      throw new FeatureException(
          "Could not read the feature specification file '" + specModelURL.toString() + "'. ", e);
    }

    if (br != null) {
      int specModelIndex = featureSpecModels.getNextIndex();
      String fileLine;
      String items[];
      StringBuilder featureText = new StringBuilder();
      String splitfeats;
      ArrayList<String> fileLines = new ArrayList<String>();
      ArrayList<String> orderFileLines = new ArrayList<String>();
      while (true) {
        try {
          fileLine = br.readLine();
        } catch (IOException e) {
          throw new FeatureException(
              "Could not read the feature specification file '" + specModelURL.toString() + "'. ",
              e);
        }
        if (fileLine == null) {
          break;
        }
        if (fileLine.length() <= 1 && fileLine.trim().substring(0, 2).trim().equals("--")) {
          continue;
        }
        fileLines.add(fileLine);
      }
      try {
        br.close();
      } catch (IOException e) {
        throw new FeatureException(
            "Could not close the feature specification file '" + specModelURL.toString() + "'. ",
            e);
      }

      for (int j = 0; j < fileLines.size(); j++) {
        orderFileLines.add(fileLines.get(j));
      }

      boolean deprel;
      for (int j = 0; j < orderFileLines.size(); j++) {
        deprel = false;
        featureText.setLength(0);
        splitfeats = "";
        items = tabPattern.split(orderFileLines.get(j));
        if (items.length < 2) {
          throw new FeatureException(
              "The feature specification file '"
                  + specModelURL.toString()
                  + "' must contain at least two columns.");
        }
        if (!(columnNameMap.containsKey(ColumnNames.valueOf(items[0].trim()))
            || columnNameMap.containsValue(items[0].trim()))) {
          throw new FeatureException(
              "Column one in the feature specification file '"
                  + specModelURL.toString()
                  + "' contains an unknown value '"
                  + items[0].trim()
                  + "'. ");
        }
        if (items[0].trim().equalsIgnoreCase("DEP") || items[0].trim().equalsIgnoreCase("DEPREL")) {
          featureText.append("OutputColumn(DEPREL, ");
          deprel = true;
        } else {
          if (columnNameMap.containsKey(ColumnNames.valueOf(items[0].trim()))) {
            featureText
                .append("InputColumn(")
                .append(columnNameMap.get(ColumnNames.valueOf(items[0].trim())))
                .append(", ");
          } else if (columnNameMap.containsValue(items[0].trim())) {
            featureText.append("InputColumn(").append(items[0].trim()).append(", ");
          }
          if (items[0].trim().equalsIgnoreCase("FEATS") && isUseSplitFeats()) {
            splitfeats = "Split(";
          }
        }
        if (!(items[1].trim().equalsIgnoreCase("STACK")
            || items[1].trim().equalsIgnoreCase("INPUT")
            || items[1].trim().equalsIgnoreCase("CONTEXT"))) {
          throw new FeatureException(
              "Column two in the feature specification file '"
                  + specModelURL.toString()
                  + "' should be either 'STACK', 'INPUT' or 'CONTEXT' (Covington), not '"
                  + items[1].trim()
                  + "'. ");
        }
        int offset = 0;
        if (items.length >= 3) {
          try {
            offset = new Integer(Integer.parseInt(items[2]));
          } catch (NumberFormatException e) {
            throw new FeatureException(
                "The feature specification file '"
                    + specModelURL.toString()
                    + "' contains a illegal integer value. ",
                e);
          }
        }
        String functionArg = "";

        if (items[1].trim().equalsIgnoreCase("CONTEXT")) {
          if (offset >= 0) {
            functionArg =
                dataStructuresMap.get(DataStructures.valueOf("LEFTCONTEXT")) + "[" + offset + "]";
          } else {
            functionArg =
                dataStructuresMap.get(DataStructures.valueOf("RIGHTCONTEXT"))
                    + "["
                    + Math.abs(offset + 1)
                    + "]";
          }
        } else if (dataStructuresMap.containsKey(DataStructures.valueOf(items[1].trim()))) {
          if (covington == true) {
            if (dataStructuresMap
                .get(DataStructures.valueOf(items[1].trim()))
                .equalsIgnoreCase("Stack")) {
              functionArg = "Left[" + offset + "]";
            } else {
              functionArg = "Right[" + offset + "]";
            }
          } else {
            functionArg =
                dataStructuresMap.get(DataStructures.valueOf(items[1].trim())) + "[" + offset + "]";
          }
        } else if (dataStructuresMap.containsValue(items[1].trim())) {
          if (covington == true) {
            if (items[1].trim().equalsIgnoreCase("Stack")) {
              functionArg = "Left[" + offset + "]";
            } else {
              functionArg = "Right[" + offset + "]";
            }
          } else {
            functionArg = items[1].trim() + "[" + offset + "]";
          }

        } else {
          throw new FeatureException(
              "Column two in the feature specification file '"
                  + specModelURL.toString()
                  + "' should not contain the value '"
                  + items[1].trim());
        }

        int linearOffset = 0;
        int headOffset = 0;
        int depOffset = 0;
        int sibOffset = 0;
        int suffixLength = 0;
        if (items.length >= 4) {
          linearOffset = new Integer(Integer.parseInt(items[3]));
        }
        if (items.length >= 5) {
          headOffset = new Integer(Integer.parseInt(items[4]));
        }
        if (items.length >= 6) {
          depOffset = new Integer(Integer.parseInt(items[5]));
        }
        if (items.length >= 7) {
          sibOffset = new Integer(Integer.parseInt(items[6]));
        }
        if (items.length >= 8) {
          suffixLength = new Integer(Integer.parseInt(items[7]));
        }
        if (linearOffset < 0) {
          linearOffset = Math.abs(linearOffset);
          for (int i = 0; i < linearOffset; i++) {
            functionArg = "pred(" + functionArg + ")";
          }
        } else if (linearOffset > 0) {
          for (int i = 0; i < linearOffset; i++) {
            functionArg = "succ(" + functionArg + ")";
          }
        }
        if (headOffset >= 0) {
          for (int i = 0; i < headOffset; i++) {
            functionArg = "head(" + functionArg + ")";
          }
        } else {
          throw new FeatureException(
              "The feature specification file '"
                  + specModelURL.toString()
                  + "' should not contain a negative head function value. ");
        }
        if (depOffset < 0) {
          depOffset = Math.abs(depOffset);
          for (int i = 0; i < depOffset; i++) {
            functionArg = "ldep(" + functionArg + ")";
          }
        } else if (depOffset > 0) {
          for (int i = 0; i < depOffset; i++) {
            functionArg = "rdep(" + functionArg + ")";
          }
        }
        if (sibOffset < 0) {
          sibOffset = Math.abs(sibOffset);
          for (int i = 0; i < sibOffset; i++) {
            functionArg = "lsib(" + functionArg + ")";
          }
        } else if (sibOffset > 0) {
          for (int i = 0; i < sibOffset; i++) {
            functionArg = "rsib(" + functionArg + ")";
          }
        }

        if (deprel == true && (pppath == true || pplifted == true || ppcoveredRoot == true)) {
          featureSpecModels.add(specModelIndex, mergePseudoProjColumns(functionArg));
        } else {
          if (suffixLength != 0) {
            featureSpecModels.add(
                specModelIndex,
                "Suffix(" + featureText.toString() + functionArg + ")," + suffixLength + ")");
          } else if (splitfeats.equals("Split(")) {
            featureSpecModels.add(
                specModelIndex, splitfeats + featureText.toString() + functionArg + "),\\|)");
          } else {
            featureSpecModels.add(specModelIndex, featureText.toString() + functionArg + ")");
          }
        }
      }
    }
  }
Example #24
0
  @Override
  public void doLayout(TerminalSize area, List<Component> components) {
    EnumMap<Location, Component> layout = makeLookupMap(components);
    int availableHorizontalSpace = area.getColumns();
    int availableVerticalSpace = area.getRows();

    // We'll need this later on
    int topComponentHeight = 0;
    int leftComponentWidth = 0;

    // First allocate the top
    if (layout.containsKey(Location.TOP)) {
      Component topComponent = layout.get(Location.TOP);
      topComponentHeight =
          Math.min(topComponent.getPreferredSize().getRows(), availableVerticalSpace);
      topComponent.setPosition(TerminalPosition.TOP_LEFT_CORNER);
      topComponent.setSize(new TerminalSize(availableHorizontalSpace, topComponentHeight));
      availableVerticalSpace -= topComponentHeight;
    }

    // Next allocate the bottom
    if (layout.containsKey(Location.BOTTOM)) {
      Component bottomComponent = layout.get(Location.BOTTOM);
      int bottomComponentHeight =
          Math.min(bottomComponent.getPreferredSize().getRows(), availableVerticalSpace);
      bottomComponent.setPosition(new TerminalPosition(0, area.getRows() - bottomComponentHeight));
      bottomComponent.setSize(new TerminalSize(availableHorizontalSpace, bottomComponentHeight));
      availableVerticalSpace -= bottomComponentHeight;
    }

    // Now divide the remaining space between LEFT, CENTER and RIGHT
    if (layout.containsKey(Location.LEFT)) {
      Component leftComponent = layout.get(Location.LEFT);
      leftComponentWidth =
          Math.min(leftComponent.getPreferredSize().getColumns(), availableHorizontalSpace);
      leftComponent.setPosition(new TerminalPosition(0, topComponentHeight));
      leftComponent.setSize(new TerminalSize(leftComponentWidth, availableVerticalSpace));
      availableHorizontalSpace -= leftComponentWidth;
    }
    if (layout.containsKey(Location.RIGHT)) {
      Component rightComponent = layout.get(Location.RIGHT);
      int rightComponentWidth =
          Math.min(rightComponent.getPreferredSize().getColumns(), availableHorizontalSpace);
      rightComponent.setPosition(
          new TerminalPosition(area.getColumns() - rightComponentWidth, topComponentHeight));
      rightComponent.setSize(new TerminalSize(rightComponentWidth, availableVerticalSpace));
      availableHorizontalSpace -= rightComponentWidth;
    }
    if (layout.containsKey(Location.CENTER)) {
      Component centerComponent = layout.get(Location.CENTER);
      centerComponent.setPosition(new TerminalPosition(leftComponentWidth, topComponentHeight));
      centerComponent.setSize(new TerminalSize(availableHorizontalSpace, availableVerticalSpace));
    }

    // Set the remaining components to 0x0
    for (Component component : components) {
      if (!layout.values().contains(component)) {
        component.setPosition(TerminalPosition.TOP_LEFT_CORNER);
        component.setSize(TerminalSize.ZERO);
      }
    }
  }
Example #25
0
  private char[][] innerGenerate(char[][] map) {
    OrderedSet<Coord> doorways;
    OrderedSet<Coord> hazards = new OrderedSet<>();
    Coord temp;
    boolean doubleDoors = false;
    int floorCount = DungeonUtility.countCells(map, '.'),
        doorFill = 0,
        waterFill = 0,
        grassFill = 0,
        trapFill = 0,
        boulderFill = 0,
        islandSpacing = 0;
    if (fx.containsKey(FillEffect.DOORS)) {
      doorFill = fx.get(FillEffect.DOORS);
      if (doorFill < 0) {
        doubleDoors = true;
        doorFill *= -1;
      }
    }
    if (fx.containsKey(FillEffect.GRASS)) {
      grassFill = fx.get(FillEffect.GRASS);
    }
    if (fx.containsKey(FillEffect.WATER)) {
      waterFill = fx.get(FillEffect.WATER);
    }
    if (fx.containsKey(FillEffect.BOULDERS)) {
      boulderFill = fx.get(FillEffect.BOULDERS) * floorCount / 100;
    }
    if (fx.containsKey(FillEffect.ISLANDS)) {
      islandSpacing = fx.get(FillEffect.ISLANDS);
    }
    if (fx.containsKey(FillEffect.TRAPS)) {
      trapFill = fx.get(FillEffect.TRAPS);
    }

    doorways = viableDoorways(doubleDoors, map);

    OrderedSet<Coord> obstacles = new OrderedSet<>(doorways.size() * doorFill / 100);
    if (doorFill > 0) {
      int total = doorways.size() * doorFill / 100;

      BigLoop:
      for (int i = 0; i < total; i++) {
        Coord entry = rng.getRandomElement(doorways);
        if (map[entry.x][entry.y] == '<' || map[entry.x][entry.y] == '>') continue;
        if (map[entry.x - 1][entry.y] != '#' && map[entry.x + 1][entry.y] != '#') {
          map[entry.x][entry.y] = '+';
        } else {
          map[entry.x][entry.y] = '/';
        }
        obstacles.add(entry);
        Coord[] adj =
            new Coord[] {
              Coord.get(entry.x + 1, entry.y),
              Coord.get(entry.x - 1, entry.y),
              Coord.get(entry.x, entry.y + 1),
              Coord.get(entry.x, entry.y - 1)
            };
        for (Coord near : adj) {
          if (doorways.contains(near)) {
            map[near.x][near.y] = '#';
            obstacles.add(near);
            doorways.remove(near);
            i++;
            doorways.remove(entry);
            continue BigLoop;
          }
        }
        doorways.remove(entry);
      }
    }
    if (boulderFill > 0.0) {
      /*
      short[] floor = pack(map, '.');
      short[] viable = retract(floor, 1, width, height, true);
      ArrayList<Coord> boulders = randomPortion(viable, boulderFill, rng);
      for (Coord boulder : boulders) {
          map[boulder.x][boulder.y] = '#';
      }
      */
      Coord[] boulders = new GreasedRegion(map, '.').retract8way(1).randomPortion(rng, boulderFill);
      Coord t;
      for (int i = 0; i < boulders.length; i++) {
        t = boulders[i];
        map[t.x][t.y] = '#';
      }
    }

    if (trapFill > 0) {
      for (int x = 1; x < map.length - 1; x++) {
        for (int y = 1; y < map[x].length - 1; y++) {
          temp = Coord.get(x, y);
          if (map[x][y] == '.' && !obstacles.contains(temp)) {
            int ctr = 0;
            if (map[x + 1][y] != '#') ++ctr;
            if (map[x - 1][y] != '#') ++ctr;
            if (map[x][y + 1] != '#') ++ctr;
            if (map[x][y - 1] != '#') ++ctr;
            if (map[x + 1][y + 1] != '#') ++ctr;
            if (map[x - 1][y + 1] != '#') ++ctr;
            if (map[x + 1][y - 1] != '#') ++ctr;
            if (map[x - 1][y - 1] != '#') ++ctr;
            if (ctr >= 5) hazards.add(Coord.get(x, y));
          }
        }
      }
    }
    short[] floors = pack(map, '.'), working;
    floorCount = count(floors);
    float waterRate = waterFill / 100.0f, grassRate = grassFill / 100.0f;
    if (waterRate + grassRate > 1.0f) {
      waterRate /= (waterFill + grassFill) / 100.0f;
      grassRate /= (waterFill + grassFill) / 100.0f;
    }
    int targetWater = Math.round(floorCount * waterRate),
        targetGrass = Math.round(floorCount * grassRate),
        sizeWaterPools = targetWater / rng.between(3, 6),
        sizeGrassPools = targetGrass / rng.between(2, 5);

    Coord[] scatter;
    int remainingWater = targetWater, remainingGrass = targetGrass;
    if (targetWater > 0) {
      scatter = fractionPacked(floors, 7);
      scatter = rng.shuffle(scatter, new Coord[scatter.length]);
      ArrayList<Coord> allWater = new ArrayList<>(targetWater);
      for (int i = 0; i < scatter.length; i++) {
        if (remainingWater > 5) // remainingWater >= targetWater * 0.02 &&
        {
          if (!queryPacked(floors, scatter[i].x, scatter[i].y)) continue;
          working =
              spill(
                  floors,
                  packOne(scatter[i]),
                  rng.between(4, Math.min(remainingWater, sizeWaterPools)),
                  rng);

          floors = differencePacked(floors, working);
          Coord[] pts = allPacked(working);
          remainingWater -= pts.length;
          Collections.addAll(allWater, pts);
        } else break;
      }

      for (Coord pt : allWater) {
        hazards.remove(pt);
        // obstacles.add(pt);
        if (map[pt.x][pt.y] != '<' && map[pt.x][pt.y] != '>') map[pt.x][pt.y] = '~';
      }
      for (Coord pt : allWater) {
        if (map[pt.x][pt.y] != '<'
            && map[pt.x][pt.y] != '>'
            && (map[pt.x - 1][pt.y] == '.'
                || map[pt.x + 1][pt.y] == '.'
                || map[pt.x][pt.y - 1] == '.'
                || map[pt.x][pt.y + 1] == '.')) map[pt.x][pt.y] = ',';
      }
    }
    if (targetGrass > 0) {
      scatter = fractionPacked(floors, 7);
      scatter = rng.shuffle(scatter, new Coord[scatter.length]);
      Coord p;
      for (int i = 0; i < scatter.length; i++) {
        if (remainingGrass > 5) // remainingGrass >= targetGrass * 0.02 &&
        {
          working =
              spill(
                  floors,
                  packOne(scatter[i]),
                  rng.between(4, Math.min(remainingGrass, sizeGrassPools)),
                  rng);
          if (working.length == 0) continue;
          floors = differencePacked(floors, working);
          Coord[] pts = allPacked(working);
          remainingGrass -= pts.length;
          for (int c = 0; c < pts.length; c++) {
            p = pts[c];
            map[p.x][p.y] = '"';
          }
        } else break;
      }
    }

    if (islandSpacing > 1 && targetWater > 0) {
      ArrayList<Coord> islands =
          PoissonDisk.sampleMap(
              map, 1f * islandSpacing, rng, '#', '.', '"', '+', '/', '^', '<', '>');
      for (Coord c : islands) {
        map[c.x][c.y] = '.';
        if (map[c.x - 1][c.y] != '#' && map[c.x - 1][c.y] != '<' && map[c.x - 1][c.y] != '>')
          map[c.x - 1][c.y] = ',';
        if (map[c.x + 1][c.y] != '#' && map[c.x + 1][c.y] != '<' && map[c.x + 1][c.y] != '>')
          map[c.x + 1][c.y] = ',';
        if (map[c.x][c.y - 1] != '#' && map[c.x][c.y - 1] != '<' && map[c.x][c.y - 1] != '>')
          map[c.x][c.y - 1] = ',';
        if (map[c.x][c.y + 1] != '#' && map[c.x][c.y + 1] != '<' && map[c.x][c.y + 1] != '>')
          map[c.x][c.y + 1] = ',';
      }
    }

    if (trapFill > 0) {
      int total = hazards.size() * trapFill / 100;

      for (int i = 0; i < total; i++) {
        Coord entry = rng.getRandomElement(hazards);
        if (map[entry.x][entry.y] == '<' || map[entry.x][entry.y] == '<') continue;
        map[entry.x][entry.y] = '^';
        hazards.remove(entry);
      }
    }

    dungeon = map;
    return map;
  }
Example #26
0
 private boolean hasSublayer(Direction direction) {
   return sublayers.containsKey(direction);
 }
Example #27
0
 public boolean contain(final AccessList access) {
   return accesses.containsKey(access);
 }
Example #28
0
 boolean has(Field field) {
   return entries.containsKey(field);
 }
Example #29
0
 public <T> T getValue(TYPES type) {
   if (values.containsKey(type)) return (T) values.get(type);
   return null;
 }