src/main/java/ru/alphatech/icfpc/cards/Help.java
changeset 67 e2df2fbc6e8e
parent 64 8ce8964b584f
child 68 a84a3c755d93
     1.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Help.java	Sun Jun 19 14:34:54 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Help.java	Sun Jun 19 14:35:19 2011 +0400
     1.3 @@ -8,41 +8,47 @@
     1.4  public class Help implements ICard
     1.5  {
     1.6  	@Override
     1.7 -	public IValue returnValue(final IValue i, Player proponent, Player opponent)
     1.8 +	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
     1.9  	{
    1.10  		return new ICard()
    1.11  		{
    1.12  			@Override
    1.13 -			public IValue returnValue(final IValue j, Player proponent, Player opponent)
    1.14 +			public IValue returnValue(final IValue jobj, Player proponent, Player opponent)
    1.15  			{
    1.16  				return new ICard()
    1.17  				{
    1.18  					@Override
    1.19 -					public IValue returnValue(final IValue n, Player proponent, Player opponent)
    1.20 +					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    1.21  					{
    1.22 -						if (i.getClass().equals(Value.class) && j.getClass().equals(Value.class) && n.getClass().equals(Value.class))
    1.23 +						if(iobj instanceof Value && nobj instanceof Value)
    1.24  						{
    1.25 -							int ival = ((Value)i).getValue();
    1.26 -							int jval = ((Value)j).getValue();
    1.27 -							int nval = ((Value)n).getValue();
    1.28 -							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    1.29 +							int i = ((Value)iobj).getValue();
    1.30 +							int n = ((Value)nobj).getValue();
    1.31 +							int v = proponent.getSlot(i).getVitality();
    1.32 +							
    1.33 +							if(i >= 0 && i <= 255 && n <= v)
    1.34  							{
    1.35 -								int v = proponent.getSlot(ival).getVitality();
    1.36 -								int w = proponent.getSlot(jval).getVitality();
    1.37 -
    1.38 -								if (v > nval)
    1.39 +								if(jobj instanceof Value)
    1.40  								{
    1.41 -									proponent.getSlot(ival).setVitality(v - nval);
    1.42 -									if (w > 0)
    1.43 +									int j = ((Value)jobj).getValue();
    1.44 +									
    1.45 +									if(j >= 0 && j <= 255)
    1.46  									{
    1.47 -										if (w >= 65535)
    1.48 +										int w = proponent.getSlot(j).getVitality();
    1.49 +										
    1.50 +										if(w > 0)
    1.51  										{
    1.52 -											proponent.getSlot(jval).setVitality(65535);
    1.53 +											int winc = (int) Math.floor(11 * n / 10);
    1.54 +											int resw = w + winc;
    1.55 +											
    1.56 +											proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    1.57  										}
    1.58 -										else
    1.59 -										{
    1.60 -											proponent.getSlot(jval).setVitality(w + ((11 * nval)/10));
    1.61 -										}
    1.62 +										
    1.63 +										return new I();
    1.64 +									}
    1.65 +									else
    1.66 +									{
    1.67 +										throw new ICFPCException();
    1.68  									}
    1.69  								}
    1.70  								else
    1.71 @@ -54,10 +60,11 @@
    1.72  							{
    1.73  								throw new ICFPCException();
    1.74  							}
    1.75 -
    1.76 -							return new I();
    1.77  						}
    1.78 -						return null;
    1.79 +						else
    1.80 +						{
    1.81 +							throw new ICFPCException();
    1.82 +						}
    1.83  					}
    1.84  				};
    1.85  			}