// The web service operation corresponding to the sum ontology action will be called add @OperationName(name = "add") public Sum toSum(float firstElement, float secondElement) { Sum sum = new Sum(); sum.setFirstElement(firstElement); sum.setSecondElement(secondElement); return sum; }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub CallbackTest callTest = new CallbackTest(); Sum total = new Sum(); total.setMaxNumber(50); total.setOnMaxNumberCb(callTest); for (int i = 1; i <= 11; i++) { total.addNumber(i); } System.out.println("Total is" + total.getTotal()); }
@Override public void makeChoices(Game game, Event event, java.util.Map<Parameter, Set> parameters) { int numberOfCards = 1; if (parameters.containsKey(Parameter.NUMBER)) numberOfCards = Sum.get(parameters.get(Parameter.NUMBER)); if (numberOfCards < 0) numberOfCards = 0; java.util.Set<Card> cardsInHand = null; boolean specificChoices = parameters.containsKey(Parameter.CHOICE); if (specificChoices) cardsInHand = parameters.get(Parameter.CHOICE).getAll(Card.class); for (Player player : parameters.get(Parameter.PLAYER).getAll(Player.class)) { if (!specificChoices) cardsInHand = new Set(player.getHand(game.actualState).objects).getAll(Card.class); java.util.Collection<Card> choices = player.sanitizeAndChoose( game.actualState, numberOfCards, cardsInHand, PlayerInterface.ChoiceType.OBJECTS, PlayerInterface.ChooseReason.DISCARD); if (choices.size() != numberOfCards) event.allChoicesMade = false; event.putChoices(player, choices); } }
@Override public boolean attempt(Game game, Event event, java.util.Map<Parameter, Set> parameters) { int successes = 0; Set cause = parameters.get(Parameter.CAUSE); int required = 1; if (parameters.containsKey(Parameter.NUMBER)) required = Sum.get(parameters.get(Parameter.NUMBER)); for (Player player : parameters.get(Parameter.PLAYER).getAll(Player.class)) { java.util.Set<Card> cards = null; if (parameters.containsKey(Parameter.CHOICE)) cards = parameters.get(Parameter.CHOICE).getAll(Card.class); else cards = new Set(player.getHand(game.actualState).objects).getAll(Card.class); successes = 0; for (Card thisCard : cards) { java.util.Map<Parameter, Set> newParameters = new java.util.HashMap<Parameter, Set>(); newParameters.put(Parameter.CAUSE, cause); newParameters.put(Parameter.CARD, new Set(thisCard)); if (createEvent( game, thisCard.getOwner(game.actualState) + " discards " + thisCard + ".", DISCARD_ONE_CARD, newParameters) .attempt(event)) successes++; if (successes == required) break; } if (successes != required) return false; } return true; }
@Override public void meet(Sum node) throws RuntimeException { builder.append("SUM("); optypes.push(ValueType.DOUBLE); node.getArg().visit(this); optypes.pop(); builder.append(")"); }
public static void main(String[] arg) { String[] args = {"12"}; if (args.length > 0) { if (Integer.parseInt(args[0]) < 0) { System.err.println(args[0] + "must be >= 0."); } else { // create the object to be shared Sum sumObject = new Sum(); int upper = Integer.parseInt(args[0]); Thread thrd = new Thread(new Summation(upper, sumObject)); thrd.start(); try { thrd.join(); System.out.println("The sum of " + upper + " is " + sumObject.getSum()); } catch (InterruptedException ie) { } } } else { System.err.println("Ussage: summation <intger value>"); } }
public PredatorsRapport(GameState state) { super(state); // Choose target creature you control. You gain life equal to that // creature's power plus its toughness. SetGenerator target = targetedBy(this.addTarget(CREATURES_YOU_CONTROL, "target creature you control")); this.addEffect( gainLife( You.instance(), Sum.instance(Union.instance(PowerOf.instance(target), ToughnessOf.instance(target))), "Choose target creature you control. You gain life equal to that creature's power plus its toughness.")); }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Sum total = new Sum(); OnMaxNumberCb callback = new OnMaxNumberCb() { @Override public void onMaxNumber(int number, int exceed) { // TODO Auto-generated method stub // 구현하시오 // } }; total.setMaxNumber(50); total.setOnMaxNumberCb(callback); for (int i = 1; i <= 11; i++) { total.addNumber(i); } System.out.println("Total is" + total.getTotal()); }
public static void setup() { x = new Variable("x"); y = new Variable("y"); z = new Variable("z"); multiLetter = new Variable("multi"); multiCase = new Variable("HeLlO"); one = new Number(1); zero = new Number(0); two = new Number(02.0); four = new Number(4); twox = new Product(two, x); alongname = new Variable("alongname"); twoplusxtimesxplusy = new Product(new Sum(two, x), new Sum(x, y)); twotimesxtimesxtimesy = new Product(new Product(two, x), new Product(x, y)); nestedproductandsumtwoxy = new Product(new Sum(two, new Product(x, y)), new Product(new Sum(two, y), x)); xy = new Product(x, y); xplusy = new Sum(x, y); xplustwo = new Sum(x, two); xplusypluszplusone = new Sum(x, new Sum(y, new Sum(z, one))); xplusone = x.add(one); xtimesx = x.multiply(x); xtimesy = x.multiply(y); threepointtwotimesxtimesy = x.multiply(y).multiply(new Number(3.2)); twotimesxtimesx = x.multiply(x).multiply(new Number(2)); xtimesxplusx = new SimpleExpression(xtimesx, x); twoy = new Product(two, y); fourxy = new Product(new Product(x, y), four); twoxysquared = new Product(new Product(two, x), new Product(y, y)); mapxtimesx.put("x", 2); mapxtimesy.put("x", 1); mapxtimesy.put("y", 1); mapthreepointtwotimesxtimesy.put("x", 1); mapthreepointtwotimesxtimesy.put("y", 1); maptwotimesxtimesx.put("x", 2); xplusytimesxy = Expression.parse("(x+y)*(x*y)"); xytimesxplusy = Expression.parse("(x*y)*(x+y)"); xplusyplusxy = Expression.parse("(x+y)+(x*y)"); xyplusxplusy = Expression.parse("(x*y)+(x+y)"); dxy = xy.differentiate(x); dxplusy = xplusy.differentiate(x); oneplusone = Expression.parse("1+1"); onetimesone = Expression.parse("1*1"); onepointone = new Number(001.100); }
@Override public boolean attempt(Game game, Event event, Map<Parameter, MagicSet> parameters) { int lifeGain = Sum.get(parameters.get(Parameter.NUMBER)); if (lifeGain <= 0) return true; MagicSet players = parameters.get(Parameter.PLAYER); for (Player player : players.getAll(Player.class)) { HashMap<Parameter, MagicSet> newParameters = new HashMap<Parameter, MagicSet>(parameters); newParameters.put(Parameter.PLAYER, new MagicSet(player)); Event gainLifeOnePlayer = createEvent( game, player + " loses " + lifeGain + " life", GAIN_LIFE_ONE_PLAYER, newParameters); if (!gainLifeOnePlayer.attempt(event)) return false; } return true; }
public EnsnaringBridgeAbility0(GameState state) { super( state, "Creatures with power greater than the number of cards in your hand can't attack."); SetGenerator numberOfCardsInYourHand = Count.instance(InZone.instance(HandOf.instance(You.instance()))); SetGenerator hasPowerGreater = HasPower.instance( Between.instance( Sum.instance(Union.instance(numberGenerator(1), numberOfCardsInYourHand)), Empty.instance())); SetGenerator restriction = Intersect.instance(Attacking.instance(), hasPowerGreater); ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.ATTACKING_RESTRICTION); part.parameters.put( ContinuousEffectType.Parameter.RESTRICTION, Identity.instance(restriction)); this.addEffectPart(part); }
@Override public boolean perform(Game game, Event event, Map<Parameter, MagicSet> parameters) { int lifeGain = Sum.get(parameters.get(Parameter.NUMBER)); if (lifeGain <= 0) { event.setResult(Empty.set); return true; } MagicSet result = new MagicSet(); MagicSet players = parameters.get(Parameter.PLAYER); for (Player player : players.getAll(Player.class)) { HashMap<Parameter, MagicSet> newParameters = new HashMap<Parameter, MagicSet>(parameters); newParameters.put(Parameter.PLAYER, new MagicSet(player)); Event gain = createEvent( game, player + " gains " + lifeGain + " life", GAIN_LIFE_ONE_PLAYER, newParameters); gain.perform(event, false); result.addAll(gain.getResult()); } event.setResult(result); return true; }
@Override public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) { Set result = new Set(); Identified producer = parameters.get(Parameter.SOURCE).getOne(Identified.class); java.util.Set<Color> colors = parameters.get(Parameter.MANA).getAll(Color.class); java.util.Set<ManaSymbol.ManaType> types = parameters.get(Parameter.MANA).getAll(ManaSymbol.ManaType.class); ManaPool pool = new ManaPool(); ManaSymbol addition = new ManaSymbol(""); addition.colors.addAll(colors); for (ManaSymbol.ManaType type : types) { if (ManaSymbol.ManaType.COLORLESS == type) { addition.colorless = 1; addition.name += "1"; } else { Color color = type.getColor(); addition.colors.add(color); addition.name += color.getLetter(); } } if (!addition.isZero()) pool.add(addition); pool.addAll(parameters.get(Parameter.MANA).getAll(ManaSymbol.class)); int multiply = 1; if (parameters.containsKey(Parameter.MULTIPLY)) multiply = Sum.get(parameters.get(Parameter.MULTIPLY)); if (multiply != 1) { ManaPool newPool = new ManaPool(); if (multiply > 1) { newPool.addAll(pool); for (ManaSymbol symbol : pool) for (int i = 1; i < multiply; ++i) newPool.add(symbol.create()); } pool = newPool; } int number = 1; if (parameters.containsKey(Parameter.NUMBER)) number = Sum.get(parameters.get(Parameter.NUMBER)); boolean snow = false; if (producer.isGameObject()) snow = ((GameObject) producer).getSuperTypes().contains(SuperType.SNOW); for (Player actualPlayer : parameters.get(Parameter.PLAYER).getAll(Player.class)) { Player physicalPlayer = actualPlayer.getPhysical(); java.util.Set<CostCollection> choices = pool.explode("Add"); // TODO : Ticket 430 ManaPool chosen = null; if (choices.isEmpty()) // empty pool to start with chosen = pool; else if (choices.size() == 1) chosen = choices.iterator().next().manaCost; else { // if all of the choices are mana of a single color, present // it as a color choice boolean allSingleColorSymbols = true; for (CostCollection choiceCollection : choices) { ManaPool choice = choiceCollection.manaCost; if (choice.converted() != 1) { allSingleColorSymbols = false; break; } ManaSymbol symbol = choice.first(); if (symbol.colorless != 0) { allSingleColorSymbols = false; break; } if (symbol.colors.size() != 1) { allSingleColorSymbols = false; break; } } if (allSingleColorSymbols) { java.util.Set<Color> colorChoices = java.util.EnumSet.noneOf(Color.class); for (CostCollection choice : choices) colorChoices.add(choice.manaCost.first().colors.iterator().next()); Color chosenColor = physicalPlayer.chooseColor(colorChoices, producer.ID); ManaSymbol s = pool.first().create(); s.colors = java.util.EnumSet.of(chosenColor); s.colorless = 0; chosen = new ManaPool(java.util.Collections.singleton(s)); } else chosen = physicalPlayer .sanitizeAndChoose( game.actualState, 1, choices, PlayerInterface.ChoiceType.MANA_EXPLOSION, PlayerInterface.ChooseReason.HYBRID_MANA) .iterator() .next() .manaCost; } for (int i = 0; i < number; ++i) { // Use the reference mana to create a new mana to // add to the pool for (ManaSymbol newMana : chosen) { newMana = newMana.create(); newMana.sourceID = producer.ID; newMana.isSnow = snow; physicalPlayer.pool.add(newMana); result.add(newMana); if (game.currentAction != null) game.currentAction.manaProduced.add(newMana); } } } GameObject source = event.getSource(); if (source.isActivatedAbility()) ((ActivatedAbility) source.getPhysical()).addedMana(result.getAll(ManaSymbol.class)); event.setResult(Identity.instance(result)); return true; }
public static void main(String[] args) { Sum sum = new Sum(); sum.method1(); sum.method2(); sum.method3(); }
/** * This method parses an expression that it reads from a given input stream. * * @param parseOneNext if parsing should parse only one item. * @return An expression that is the root of the parse tree produced by the parser. * @throws SyntaxException */ public Expression parse(boolean parseOneNext) throws SyntaxException { Expression c = null; boolean contin = true; while (contin) { contin = false; switch (token) { case LexicalAnalyzer.PLUS: lexer.nextToken(); if (token != LexicalAnalyzer.WORD && token != LexicalAnalyzer.LEFT_PAREN) { // print error message and throw SyntaxException expect(LexicalAnalyzer.Beginning); } // if Expression c2 = parse(false); if (c.getType() == RegularExpressionParser.Sum && c2.getType() == RegularExpressionParser.Sum) ((Sum) c).addSum((Sum) c2); if (c.getType() == RegularExpressionParser.Sum && c2.getType() != RegularExpressionParser.Sum) ((Sum) c).addExp(c2); if (c.getType() != RegularExpressionParser.Sum && c2.getType() == RegularExpressionParser.Sum) { ((Sum) c2).addExp(c); c = c2; } if (c.getType() != RegularExpressionParser.Sum && c2.getType() != RegularExpressionParser.Sum) c = new Sum(c, c2); break; case LexicalAnalyzer.DOT: lexer.nextToken(); if (token != LexicalAnalyzer.WORD && token != LexicalAnalyzer.LEFT_PAREN) { // print error message and throw SyntaxException expect(LexicalAnalyzer.Beginning); } // if Expression c3 = parse(true); c = new Concatination(c, c3); while (token == LexicalAnalyzer.DOT) { lexer.nextToken(); c3 = parse(true); c = new Concatination(c, c3); } if (token != LexicalAnalyzer.EOF) contin = true; break; case LexicalAnalyzer.LEFT_PAREN: lexer.nextToken(); c = parse(false); expect(LexicalAnalyzer.RIGHT_PAREN); lexer.nextToken(); if (token != LexicalAnalyzer.EOF) contin = true; break; case LexicalAnalyzer.STAR: c = new Star(c); lexer.nextToken(); if (token != LexicalAnalyzer.EOF) contin = true; break; case LexicalAnalyzer.WORD: c = new Literal(lexer.getString()); lexer.nextToken(); if (token != LexicalAnalyzer.RIGHT_PAREN && token != LexicalAnalyzer.EOF) { if (token != LexicalAnalyzer.DOT && token != LexicalAnalyzer.STAR && token != LexicalAnalyzer.PLUS) { // print error message and throw SyntaxException expect(LexicalAnalyzer.Operator); } // if contin = true; } break; } if (parseOneNext == true && !(token == LexicalAnalyzer.STAR)) contin = false; } if (Regular.debugAll) System.out.println("Succesful parsing of " + c); return c; }
public Sum add(Sum otherSum) { return this.add(otherSum.getValue()); }