/**
   * Called when we first enter the game room and subsequently if {@link AtlantiObject#TILES} is
   * set.
   */
  public void tilesChanged(DSet<AtlantiTile> tset) {
    // clear out our old tiles list
    _tiles.clear();

    // copy the tiles from the set into our local list
    CollectionUtil.addAll(_tiles, tset.iterator());

    // sort the list
    Collections.sort(_tiles);

    // recompute our desired dimensions and then have our parent
    // adjust to our changed size
    computeDimensions();
  }
  /** Test code. */
  public static void main(String[] args) {
    JFrame frame = new JFrame("Board test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AtlantiBoardView board = new AtlantiBoardView(null);

    TestDSet set = new TestDSet();
    set.addTile(new AtlantiTile(CITY_TWO, true, WEST, 0, 0));
    set.addTile(new AtlantiTile(CITY_TWO, false, WEST, -1, 1));
    set.addTile(new AtlantiTile(CITY_ONE, false, SOUTH, -1, -1));
    AtlantiTile zero = new AtlantiTile(CURVED_ROAD, false, WEST, 0, 2);
    set.addTile(zero);
    AtlantiTile one = new AtlantiTile(TWO_CITY_TWO, false, NORTH, 0, 1);
    set.addTile(one);
    set.addTile(new AtlantiTile(CITY_THREE, false, WEST, 1, 1));
    set.addTile(new AtlantiTile(CITY_THREE_ROAD, false, EAST, 1, 2));
    set.addTile(new AtlantiTile(CITY_THREE, false, NORTH, -1, 0));
    AtlantiTile two = new AtlantiTile(CITY_ONE, false, EAST, -2, 0);
    set.addTile(two);
    board.tilesChanged(set);

    AtlantiTile placing = new AtlantiTile(CITY_TWO, false, NORTH, 0, 0);
    board.setTileToBePlaced(placing);

    // set a feature group to test propagation
    List<AtlantiTile> tiles = new ArrayList<AtlantiTile>();
    CollectionUtil.addAll(tiles, set.iterator());
    Collections.sort(tiles);

    zero.setPiecen(new Piecen(Piecen.GREEN, 0, 0, 2), tiles);
    one.setPiecen(new Piecen(Piecen.BLUE, 0, 0, 0), tiles);
    two.setPiecen(new Piecen(Piecen.RED, 0, 0, 1), tiles);

    Log.info("Incomplete road: " + TileUtil.computeFeatureScore(tiles, zero, 2));

    Log.info("Completed city: " + TileUtil.computeFeatureScore(tiles, two, 1));

    Log.info("Incomplete city: " + TileUtil.computeFeatureScore(tiles, one, 2));

    frame.getContentPane().add(board, BorderLayout.CENTER);
    frame.pack();
    SwingUtil.centerWindow(frame);
    frame.setVisible(true);
  }
Beispiel #3
0
  /** Loads a random set of new & hot and staff pick items for the filler. */
  protected List<EmailListing> randomItems(MsoyItemType itemType) throws ServiceException {
    int count = ITEM_COUNT;

    // load up items from new & hot and staff picks (x2), no dupes
    Set<ListingCard> resultSet = Sets.newHashSet();
    resultSet.addAll(
        _catalogLogic.loadCatalog(null, itemType, CatalogQuery.SORT_BY_NEW_AND_HOT, count));
    resultSet.addAll(
        _itemLogic.resolveFavorites(_faveRepo.loadRecentFavorites(0, count * 2, itemType)));

    // get a random subset into a list
    List<ListingCard> result;
    if (resultSet.size() > count) {
      result = CollectionUtil.selectRandomSubset(resultSet, count);
    } else {
      result = Lists.newArrayList(resultSet);
    }

    // transform to velocity wrapper
    return Lists.transform(result, _toListing);
  }
Beispiel #4
0
 /** Returns a random subset of a list, or the list itself if there are not enough items. */
 protected static <T> List<T> randomSubset(int size, List<T> list) {
   if (list.size() < size) {
     return list;
   }
   return CollectionUtil.selectRandomSubset(list, size);
 }