@Command( name = "promote", permission = "mytown.cmd.assistant.promote", parentName = "mytown.cmd", syntax = "/town promote <resident> <rank>", completionKeys = {"residentCompletion", "rankCompletion"}) public static CommandResponse promoteCommand(ICommandSender sender, List<String> args) { if (args.size() < 2) return CommandResponse.SEND_SYNTAX; Resident resSender = MyTownUniverse.instance.getOrMakeResident(sender); Resident resTarget = getResidentFromName(args.get(0)); Town town = getTownFromResident(resSender); if (!resTarget.townsContainer.contains(town)) throw new MyTownCommandException( "mytown.cmd.err.resident.notsametown", args.get(0), town.getName()); Rank mayorRank = town.ranksContainer.getMayorRank(); if (args.get(1).equalsIgnoreCase(mayorRank.getName())) throw new MyTownCommandException("mytown.cmd.err.promote.notMayor"); Rank rank = getRankFromTown(town, args.get(1)); if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) { resSender.sendMessage( getLocal() .getLocalization( "mytown.cmd.promote.success.sender", resTarget.getPlayerName(), rank.getName())); resTarget.sendMessage( getLocal() .getLocalization( "mytown.cmd.promote.success.target", rank.getName(), town.getName())); } return CommandResponse.DONE; }
public Player(Vector<Card> cards) { for (int i = 0; i < 4; i++) { Vector<Rank> ranks = new Vector<Rank>(); this.cards.add(ranks); } for (Card card : cards) { suits.add(card.getSuit()); distinctRank.add(card.getRank()); } List<Rank> myList = new ArrayList(distinctRank); myList.sort(new RankComparator()); for (Rank rank : myList) { int count = 0; for (Card card : cards) { if (card.getRank().ordinal() == rank.ordinal()) count++; } if (count < 5 && count > 0) { if (this.cards.size() > 0) this.cards.get(count - 1).add(rank); } } mode = findPlayerMode(); }
/** Test range. */ public void testRange() { for (int i = 130; i >= 80; i--) { Rank rank = new Rank(i); // System.err.println(rank); assertTrue("" + rank + "/" + i + "/" + rank.getRank(), Rank.convert(rank.toString()) == i); } }
@Command( name = "remove", permission = "mytown.cmd.assistant.ranks.remove", parentName = "mytown.cmd.everyone.ranks", syntax = "/town ranks remove <rank>", completionKeys = {"rankCompletion"}) public static CommandResponse ranksRemoveCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); Rank rank = getRankFromTown(town, args.get(0)); if (rank.getType().unique) { throw new MyTownCommandException("mytown.cmd.err.ranks.cantDelete"); } for (Rank residentRank : town.residentsMap.values()) { if (residentRank == rank) { throw new MyTownCommandException("mytown.cmd.err.ranks.assigned"); } } getDatasource().deleteRank(rank); res.sendMessage( getLocal() .getLocalization("mytown.notification.town.ranks.rem", args.get(0), town.getName())); return CommandResponse.DONE; }
/** @see HorizontalPlacement#buildRankSeparators(RankList) */ void buildRankSeparators(RankList ranks) { CompoundDirectedGraph g = (CompoundDirectedGraph) graph; Rank rank; for (int row = 0; row < g.ranks.size(); row++) { rank = g.ranks.getRank(row); Node n = null, prev = null; for (int j = 0; j < rank.size(); j++) { n = rank.getNode(j); if (prev == null) { Node left = addSeparatorsLeft(n, null); if (left != null) { Edge e = new Edge(graphLeft, getPrime(left), 0, 0); prime.edges.add(e); e.delta = graph.getPadding(n).left + graph.getMargin().left; } } else { Subgraph s = GraphUtilities.getCommonAncestor(prev, n); Node left = addSeparatorsRight(prev, s); Node right = addSeparatorsLeft(n, s); createEdge(left, right); } prev = n; } if (n != null) addSeparatorsRight(n, null); } }
// Create the flyweight objects static { for (Suit suit : Suit.values()) { CARDS[suit.ordinal()] = new Card[Rank.values().length]; for (Rank rank : Rank.values()) { CARDS[suit.ordinal()][rank.ordinal()] = new Card(rank, suit); } } }
public static Rank toRank(String rankString) { for (Rank r : values()) { if (r.getRankString().equals(rankString)) { return r; } } throw new IllegalArgumentException("Illegal rank: " + rankString); }
public static Rank fromChar(char c) { for (Rank s : Rank.values()) { if (s.toChar() == c) { return s; } } throw new IllegalArgumentException(c + " is not a rank."); }
private ArrayList<Card> pickNRandomDifferentCards(int nCards) { if (nCards > 5) { throw new IllegalArgumentException("Don't yet know how to generate more than 5 random cards"); } TreeSet<Rank> ranks = new TreeSet<Rank>(); ArrayList<Card> cards = new ArrayList<Card>(); while (ranks.size() != nCards) { Rank randomRank = Rank.getRandomRank(); if (ranks.contains(randomRank)) { continue; } ranks.add(randomRank); if (ranks.size() == 5) { Iterator<Rank> iRank = ranks.iterator(); boolean straight = true; Rank previousRank = iRank.next(); while (iRank.hasNext()) { Rank nextRank = iRank.next(); // annoying edge case of 2-3-4-5-A if (previousRank.addToRank(1) != nextRank) { if (!(previousRank == Rank.FIVE && nextRank == Rank.ACE)) { straight = false; break; } } previousRank = nextRank; } // make sure we don't accidentally crate a straight if (straight) { ranks.remove(randomRank); continue; } } } TreeSet<Suit> suits = new TreeSet<Suit>(); for (Rank randomRank : ranks) { Suit randomSuit = Suit.getRandomSuit(); // make sure that there are more than one suit while (suits.size() == 1 && suits.contains(randomSuit)) { randomSuit = Suit.getRandomSuit(); } suits.add(randomSuit); Card card = Card.from(randomRank, randomSuit); cards.add(card); } return cards; }
/** Test ratings. */ public void testRatings() { for (int i = 130; i >= 80; i--) { Rank rank = new Rank(i); double d = rank.getRating(); assertTrue(d >= 0.0); assertTrue(d <= 1000); // System.err.println(rank); assertTrue("" + rank + "/" + i + "/" + rank.getRank(), Rank.convert(rank.toString()) == i); } }
public void testInstance() { for (Card card : Card.values()) assertEquals(card, Card.instance(card.rank(), card.suit())); for (Rank rank : Rank.values()) for (Suit suit : Suit.values()) assertNotNull(Card.instance(rank, suit)); System.out.println("************************************"); for (Rank rank : Rank.values()) if (rank.ordinal() <= 2) for (Suit suit : Suit.values()) System.out.println(rank + " " + suit + " " + Card.instance(rank, suit)); System.out.println("************************************"); }
@EventHandler public void onInfectedCommand(InfectedCommandEvent event) { if (event.getArgs().length >= 1) { if (event.getArgs()[0].equalsIgnoreCase("Rank") || event.getArgs()[0].equalsIgnoreCase("Ranks") && event.getP() != null) { event.setCancelled(true); Player p = event.getP(); if (RanksManager.canRankUp(p)) RanksManager.setPlayersRank(p, RanksManager.getNextRank(p)); Rank rank = RanksManager.getPlayersRank(p); Rank nextRank = RanksManager.getNextRank(p); p.sendMessage(Msgs.Format_Header.getString("<title>", "Ranks")); if (rank.isMaxRank()) p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + " MAX RANK"); p.sendMessage( "" + ChatColor.GREEN + ChatColor.BOLD + "Your Current Rank: " + ChatColor.GRAY + rank.getPrefix()); p.sendMessage( ChatColor.GRAY + "Your Score: " + ChatColor.RED + InfPlayerManager.getInfPlayer(p).getScore()); if (!rank.isMaxRank()) p.sendMessage( ChatColor.GRAY + "Score to next rank: " + ChatColor.RED + (nextRank.getScoreNeeded() - InfPlayerManager.getInfPlayer(p).getScore())); if (!rank.isMaxRank()) p.sendMessage( "" + ChatColor.GREEN + ChatColor.BOLD + "Next Rank: " + nextRank.getPrefix() + ChatColor.RED + " - " + ChatColor.GRAY + " Unlocks at " + ChatColor.RED + nextRank.getScoreNeeded()); if (rank.isMaxRank()) p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + " MAX RANK"); p.sendMessage(Msgs.Format_Line.getString()); } } }
private IHand generateRandomStraight() { Rank randomRank = Rank.getRandomRank(Rank.TEN); ImmutableSortedSet.Builder<Card> builder = ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer()); builder.add(Card.from(randomRank, Suit.getRandomSuit())); builder.add(Card.from(randomRank.addToRank(1), Suit.getRandomSuit())); builder.add(Card.from(randomRank.addToRank(2), Suit.getRandomSuit())); builder.add(Card.from(randomRank.addToRank(3), Suit.SPADES)); builder.add(Card.from(randomRank.addToRank(4), Suit.HEARTS)); return new SortedHand(builder.build()); }
@Test public void testByRankComparator() { ArrayList<Card> aList; ArrayList<Card> sortedList = new ArrayList<Card>(); // create a list of 46 cards sorted by rank then suit followed by the low and high jokers for (Rank lRank : Rank.values()) { for (Suit lSuit : Suit.values()) { sortedList.add(new Card(lRank, lSuit)); } } sortedList.add(aLJo); sortedList.add(aHJo); // create a shuffled list and sort it, then compare it to sortedList aList = TestComparators.shuffledList(); Collections.sort(aList, new Card.ByRankComparator()); assertTrue(TestComparators.compareLists(sortedList, aList)); aList = TestComparators.shuffledList(); Collections.sort(aList, new Card.ByRankComparator()); assertTrue(TestComparators.compareLists(sortedList, aList)); aList = TestComparators.shuffledList(); Collections.sort(aList, new Card.ByRankComparator()); assertTrue(TestComparators.compareLists(sortedList, aList)); }
public static Rank getRankFromAbbrev(char c) { // using char instead of String to avoid using switch with strings (unavailable on early java) // one could use a lookup map inside the enum instead. // opting for fewer advanced java concepts instead if (Character.isDigit(c)) { int irank = Character.digit(c, 10); // convert to int if (irank == 0) return Rank.TEN; // or raise error? if (irank == 1) return Rank.ACE; return Rank.values()[irank - 2]; } switch (c) { case 'T': return Rank.TEN; case 'J': return Rank.JACK; case 'Q': return Rank.QUEEN; case 'K': return Rank.KING; case 'A': return Rank.ACE; default: throw new IllegalArgumentException("No such rank!"); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((rank == null) ? 0 : rank.hashCode()); result = prime * result + ((suit == null) ? 0 : suit.hashCode()); return result; }
/** * Update keywords according to values of special fields * * @param nc indicates the undo named compound. May be null */ public static void syncKeywordsFromSpecialFields(BibtexEntry be, NamedCompound nc) { SpecialFieldsUtils.exportFieldToKeywords(Priority.getInstance(), be, nc); SpecialFieldsUtils.exportFieldToKeywords(Rank.getInstance(), be, nc); SpecialFieldsUtils.exportFieldToKeywords(Relevance.getInstance(), be, nc); SpecialFieldsUtils.exportFieldToKeywords(Quality.getInstance(), be, nc); SpecialFieldsUtils.exportFieldToKeywords(ReadStatus.getInstance(), be, nc); SpecialFieldsUtils.exportFieldToKeywords(Printed.getInstance(), be, nc); }
@Command( name = "reset", permission = "mytown.cmd.assistant.ranks.reset", parentName = "mytown.cmd.everyone.ranks", syntax = "/town ranks reset") public static CommandResponse ranksResetCommand(ICommandSender sender, List<String> args) { Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); for (Rank defaultRank : Rank.defaultRanks) { Rank rank = town.ranksContainer.get(defaultRank.getName()); rank.permissionsContainer.clear(); rank.permissionsContainer.addAll(defaultRank.permissionsContainer); rank.setType(defaultRank.getType()); getDatasource().saveRank(rank); } for (int i = 0; i < town.ranksContainer.size(); i++) { Rank rank = town.ranksContainer.get(i); if (!Rank.defaultRanks.contains(rank.getName())) { getDatasource().deleteRank(rank); i--; } } res.sendMessage(getLocal().getLocalization("mytown.notification.ranks.reset")); return CommandResponse.DONE; }
public StandardDeck() { cards = new ArrayList<>(); for (Suit suit : Suit.values()) { for (Rank rank : Rank.values()) { cards.add(new Card(rank, suit)); } } discardPile = new ArrayList<>(); }
/** * Get a list of factories that match the given parameter. * * <p>It is a combination of listGetElement and listFilter passing all the results of the first * call to the second. * * <p>This method improves performance because there is no need to map to java list the elements * returned by the first call. * * @param type a {@link ElementFactoryListType} * @param minrank Minimum rank * @param caps a {@link Caps} * @param direction a {@link PadDirection} to filter on * @param subsetonly whether to filter on caps subsets or not. * @return a {@link List} of {@link ElementFactory} elements that match the given requisits. */ public static List<ElementFactory> listGetElementFilter( ElementFactoryListType type, Rank minrank, Caps caps, PadDirection direction, boolean subsetonly) { GList glist = gst.gst_element_factory_list_get_elements(type.getValue(), minrank.getValue()); return lister(glist, caps, direction, subsetonly); }
public void gather() { for (Suit suit : Suit.values()) { for (Rank rank : Rank.values()) { Card card = new Card(rank, suit); card.flipCard(); this.add(card); } } }
/** Populates the tab completion map. */ public static void populateCompletionMap() { List<String> populator = new ArrayList<String>(); for (Town town : getUniverse().towns) { populator.add(town.getName()); } CommandCompletion.addCompletions("townCompletionAndAll", populator); CommandCompletion.addCompletion("townCompletionAndAll", "@a"); CommandCompletion.addCompletions("townCompletion", populator); populator = new ArrayList<String>(); for (Resident res : getUniverse().residents) { populator.add(res.getPlayerName()); } CommandCompletion.addCompletions("residentCompletion", populator); populator = new ArrayList<String>(); for (FlagType flag : FlagType.values()) { populator.add(flag.name.toLowerCase()); } CommandCompletion.addCompletions("flagCompletion", populator); populator = new ArrayList<String>(); for (FlagType flag : FlagType.values()) { if (flag.isWhitelistable) populator.add(flag.name.toLowerCase()); } CommandCompletion.addCompletions("flagCompletionWhitelist", populator); populator = new ArrayList<String>(); for (Plot plot : MyTownUniverse.instance.plots) { populator.add(plot.toString()); } CommandCompletion.addCompletions("plotCompletion", populator); populator = new ArrayList<String>(); for (Rank rank : Rank.defaultRanks) { populator.add(rank.getName()); } CommandCompletion.addCompletions("rankCompletion", populator); }
private IHand generateRandomFullHouse(StandardDeckFactory deckFactory) { SortedHand randomHand = new SortedHand(); Rank randomTrips = Rank.getRandomRank(); Rank randomPair = null; while ((randomPair = Rank.getRandomRank()) == randomTrips) {} IDeck deck = deckFactory.build(); ImmutableSortedSet.Builder<Card> builder = ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer()); builder.add(deck.pickRandom(randomTrips)); builder.add(deck.pickRandom(randomTrips)); builder.add(deck.pickRandom(randomTrips)); builder.add(deck.pickRandom(randomPair)); builder.add(deck.pickRandom(randomPair)); return new SortedHand(builder.build()); }
public Deck() { this.deck = new ArrayList(); for (int i = 0; i <= 12; i++) { for (int j = 0; j <= 3; j++) { Rank rank = Rank.values()[i]; Suits suits = Suits.values()[j]; Card card = new Card(rank, suits); this.deck.add(card); } } }
/** * updates field values according to keywords * * @param ce indicates the undo named compound. May be null */ public static void syncSpecialFieldsFromKeywords(BibtexEntry be, NamedCompound ce) { if (be.getField("keywords") == null) { return; } ArrayList<String> keywordList = Util.getSeparatedKeywords(be.getField("keywords")); SpecialFieldsUtils.importKeywordsForField(keywordList, Priority.getInstance(), be, ce); SpecialFieldsUtils.importKeywordsForField(keywordList, Rank.getInstance(), be, ce); SpecialFieldsUtils.importKeywordsForField(keywordList, Quality.getInstance(), be, ce); SpecialFieldsUtils.importKeywordsForField(keywordList, Relevance.getInstance(), be, ce); SpecialFieldsUtils.importKeywordsForField(keywordList, ReadStatus.getInstance(), be, ce); SpecialFieldsUtils.importKeywordsForField(keywordList, Printed.getInstance(), be, ce); }
@SuppressWarnings("unchecked") protected List<Card> createDeck() { ArrayList<Card> cards = new ArrayList<Card>(); for (List<Enum<?>> cardContainer : cartesianProduct(copyOf(Suit.values()), copyOf(Rank.values()))) { Suit suit = (Suit) cardContainer.get(0); Rank rank = (Rank) cardContainer.get(1); cards.add(new Card(rank, suit)); } return cards; }
@Command( name = "list", permission = "mytown.cmd.assistant.ranks.perm.list", parentName = "mytown.cmd.assistant.ranks.perm", syntax = "/town ranks perm list [rank]") public static CommandResponse ranksPermListCommand(ICommandSender sender, List<String> args) { Rank rank; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (args.isEmpty()) { rank = getRankFromResident(res); } else { rank = getRankFromTown(town, args.get(0)); } res.sendMessage( getLocal() .getLocalization( "mytown.notification.town.ranks.perm.list", rank.getName(), town.getName(), rank.permissionsContainer.toString())); return CommandResponse.DONE; }
/** * Get a list of factories that match the given type. Only elements with a rank greater or equal * to minrank will be returned. The list of factories is returned by decreasing rank. * * @param type a {@link ElementFactoryListType} * @param minrank Minimum rank * @return a List of ElementFactory elements. */ public static List<ElementFactory> listGetElement(ElementFactoryListType type, Rank minrank) { GList glist = gst.gst_element_factory_list_get_elements(type.getValue(), minrank.getValue()); List<ElementFactory> list = new ArrayList<ElementFactory>(); GList next = glist; while (next != null) { if (next.data != null) { ElementFactory fact = new ElementFactory(initializer(next.data, true, true)); list.add(fact); } next = next.next(); } gst.gst_plugin_list_free(glist); return list; }
/** * @param fieldName the fieldName * @return an instance of that field. The returned object is a singleton. null is returned if * fieldName does not indicate a special field */ public static SpecialField getSpecialFieldInstanceFromFieldName(String fieldName) { if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_PRIORITY)) { return Priority.getInstance(); } else if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_QUALITY)) { return Quality.getInstance(); } else if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_RANKING)) { return Rank.getInstance(); } else if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_RELEVANCE)) { return Relevance.getInstance(); } else if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_READ)) { return ReadStatus.getInstance(); } else if (fieldName.equals(SpecialFieldsUtils.FIELDNAME_PRINTED)) { return Printed.getInstance(); } else { return null; } }
@Command( name = "set", permission = "mytown.cmd.assistant.ranks.set", parentName = "mytown.cmd.everyone.ranks", syntax = "/town ranks set <rank> <type>", completionKeys = {"rankCompletion"}) public static CommandResponse ranksSetCommand(ICommandSender sender, List<String> args) { if (args.size() < 2) { return CommandResponse.SEND_SYNTAX; } Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); Rank rank = getRankFromTown(town, args.get(0)); Rank.Type type = getRankTypeFromString(args.get(1)); if (type.unique) { Rank fromRank = town.ranksContainer.get(type); if (fromRank == rank) { throw new MyTownCommandException("mytown.cmd.err.ranks.set.already", type.toString()); } fromRank.setType(Rank.Type.REGULAR); rank.setType(type); getDatasource().saveRank(rank); getDatasource().saveRank(fromRank); } else { if (rank.getType().unique) { throw new MyTownCommandException("mytown.cmd.err.ranks.set.unique", rank.getName()); } rank.setType(type); getDatasource().saveRank(rank); } res.sendMessage( getLocal() .getLocalization( "mytown.notification.ranks.set.successful", rank.getName(), type.toString())); return CommandResponse.DONE; }