changes is good
authorIgor R. Nikitin <0-range@bazon.ru>
Sun, 19 Jun 2011 12:12:55 +0400
changeset 35743564afa994
parent 27 0e21db22ecec
child 36 5b57bc39cc92
changes is good
src/main/java/ru/alphatech/icfpc/cards/Attack.java
src/main/java/ru/alphatech/icfpc/cards/Copy.java
src/main/java/ru/alphatech/icfpc/cards/Dec.java
src/main/java/ru/alphatech/icfpc/cards/Help.java
src/main/java/ru/alphatech/icfpc/cards/Inc.java
src/main/java/ru/alphatech/icfpc/cards/Revive.java
src/main/java/ru/alphatech/icfpc/cards/Zombie.java
     1.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Attack.java	Sun Jun 19 10:50:46 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Attack.java	Sun Jun 19 12:12:55 2011 +0400
     1.3 @@ -1,5 +1,6 @@
     1.4  package ru.alphatech.icfpc.cards;
     1.5  
     1.6 +import ru.alphatech.icfpc.game.ICFPCException;
     1.7  import ru.alphatech.icfpc.game.IValue;
     1.8  import ru.alphatech.icfpc.game.Player;
     1.9  import ru.alphatech.icfpc.game.Value;
    1.10 @@ -24,18 +25,34 @@
    1.11  							int ival = ((Value)i).getValue();
    1.12  							int jval = ((Value)j).getValue();
    1.13  							int nval = ((Value)n).getValue();
    1.14 -							proponent.getSlot(ival).setVitality(proponent.getSlot(ival).getVitality() - nval);
    1.15 -							opponent.getSlot(255 - jval).setVitality(opponent.getSlot(255 - jval).getVitality() - ((9 * nval)/10));
    1.16 -							return new ICard()
    1.17 +
    1.18 +							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    1.19  							{
    1.20 -								@Override
    1.21 -								public IValue returnValue(IValue value, Player proponent, Player opponent)
    1.22 +								int v = proponent.getSlot(ival).getVitality();
    1.23 +								int w = opponent.getSlot(255 - jval).getVitality();
    1.24 +								if (v - nval < 1)
    1.25  								{
    1.26 -									return value;
    1.27 +									proponent.getSlot(ival).setVitality(v - nval);
    1.28 +									if (w > 0)
    1.29 +									{
    1.30 +										opponent.getSlot(255 - jval).setVitality(w - ((9 * nval)/10));
    1.31 +									}
    1.32  								}
    1.33 -							};
    1.34 +								else
    1.35 +								{
    1.36 +									throw new ICFPCException();
    1.37 +								}
    1.38 +							}
    1.39 +							else
    1.40 +							{
    1.41 +								throw new ICFPCException();
    1.42 +							}
    1.43  						}
    1.44 -						return null;
    1.45 +						else
    1.46 +						{
    1.47 +							throw new ICFPCException();
    1.48 +						}
    1.49 +						return new I();
    1.50  					}
    1.51  				};
    1.52  			}
     2.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Copy.java	Sun Jun 19 10:50:46 2011 +0400
     2.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Copy.java	Sun Jun 19 12:12:55 2011 +0400
     2.3 @@ -1,5 +1,6 @@
     2.4  package ru.alphatech.icfpc.cards;
     2.5  
     2.6 +import ru.alphatech.icfpc.game.ICFPCException;
     2.7  import ru.alphatech.icfpc.game.IValue;
     2.8  import ru.alphatech.icfpc.game.Player;
     2.9  import ru.alphatech.icfpc.game.Value;
    2.10 @@ -11,9 +12,20 @@
    2.11  	{
    2.12  		if (i.getClass().equals(Value.class))
    2.13  		{
    2.14 -			return opponent.getSlot(((Value)i).getValue()).getValue();
    2.15 +			int iVal = ((Value)i).getValue();
    2.16 +			if (iVal >= 0 && iVal < 256)
    2.17 +			{
    2.18 +				return opponent.getSlot(((Value)i).getValue()).getValue();
    2.19 +			}
    2.20 +			else
    2.21 +			{
    2.22 +				throw new ICFPCException();
    2.23 +			}
    2.24 +		}
    2.25 +		else
    2.26 +		{
    2.27 +			throw new ICFPCException();
    2.28  		}
    2.29  
    2.30 -		return null;
    2.31  	}
    2.32  }
     3.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Dec.java	Sun Jun 19 10:50:46 2011 +0400
     3.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Dec.java	Sun Jun 19 12:12:55 2011 +0400
     3.3 @@ -1,5 +1,6 @@
     3.4  package ru.alphatech.icfpc.cards;
     3.5  
     3.6 +import ru.alphatech.icfpc.game.ICFPCException;
     3.7  import ru.alphatech.icfpc.game.IValue;
     3.8  import ru.alphatech.icfpc.game.Player;
     3.9  import ru.alphatech.icfpc.game.Value;
    3.10 @@ -11,18 +12,24 @@
    3.11  	{
    3.12  		if(value.getClass().equals(Value.class))
    3.13  		{
    3.14 -			if (((Value)value).getValue() < 256 && ((Value)value).getValue() > -1)
    3.15 +			int i = ((Value)value).getValue();
    3.16 +
    3.17 +			if (i > 0 && i < 256)
    3.18  			{
    3.19 -				opponent.getSlot(((Value)value).getValue()).setVitality(opponent.getSlot(((Value)value).getValue()).getVitality() - 1);
    3.20 -				return new ICard()
    3.21 +				int v = proponent.getSlot(255 - i).getVitality();
    3.22 +				if (v < 65535 && v > 0)
    3.23  				{
    3.24 -					@Override
    3.25 -					public IValue returnValue(IValue value, Player proponent, Player opponent)
    3.26 -					{
    3.27 -						return value;
    3.28 -					}
    3.29 -				};
    3.30 +					proponent.getSlot(255 - i).setVitality(proponent.getSlot(255 - i).getVitality() - 1);
    3.31 +				}
    3.32  			}
    3.33 +			else
    3.34 +			{
    3.35 +				throw new ICFPCException();
    3.36 +			}
    3.37 +		}
    3.38 +		else
    3.39 +		{
    3.40 +			throw new ICFPCException();
    3.41  		}
    3.42  
    3.43  		return new Value(-100);
     4.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Help.java	Sun Jun 19 10:50:46 2011 +0400
     4.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Help.java	Sun Jun 19 12:12:55 2011 +0400
     4.3 @@ -1,5 +1,6 @@
     4.4  package ru.alphatech.icfpc.cards;
     4.5  
     4.6 +import ru.alphatech.icfpc.game.ICFPCException;
     4.7  import ru.alphatech.icfpc.game.IValue;
     4.8  import ru.alphatech.icfpc.game.Player;
     4.9  import ru.alphatech.icfpc.game.Value;
    4.10 @@ -24,16 +25,37 @@
    4.11  							int ival = ((Value)i).getValue();
    4.12  							int jval = ((Value)j).getValue();
    4.13  							int nval = ((Value)n).getValue();
    4.14 -							proponent.getSlot(ival).setVitality(proponent.getSlot(ival).getVitality() - nval);
    4.15 -							proponent.getSlot(jval).setVitality(proponent.getSlot(jval).getVitality() + ((11 * nval)/10));
    4.16 -							return new ICard()
    4.17 +							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    4.18  							{
    4.19 -								@Override
    4.20 -								public IValue returnValue(IValue value, Player proponent, Player opponent)
    4.21 +								int v = proponent.getSlot(ival).getVitality();
    4.22 +								int w = proponent.getSlot(jval).getVitality();
    4.23 +
    4.24 +								if (v > nval)
    4.25  								{
    4.26 -									return value;
    4.27 +									proponent.getSlot(ival).setVitality(v - nval);
    4.28 +									if (w > 0)
    4.29 +									{
    4.30 +										if (w >= 65535)
    4.31 +										{
    4.32 +											proponent.getSlot(jval).setVitality(65535);
    4.33 +										}
    4.34 +										else
    4.35 +										{
    4.36 +											proponent.getSlot(jval).setVitality(w + ((11 * nval)/10));
    4.37 +										}
    4.38 +									}
    4.39  								}
    4.40 -							};
    4.41 +								else
    4.42 +								{
    4.43 +									throw new ICFPCException();
    4.44 +								}
    4.45 +							}
    4.46 +							else
    4.47 +							{
    4.48 +								throw new ICFPCException();
    4.49 +							}
    4.50 +
    4.51 +							return new I();
    4.52  						}
    4.53  						return null;
    4.54  					}
     5.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Inc.java	Sun Jun 19 10:50:46 2011 +0400
     5.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Inc.java	Sun Jun 19 12:12:55 2011 +0400
     5.3 @@ -1,5 +1,6 @@
     5.4  package ru.alphatech.icfpc.cards;
     5.5  
     5.6 +import ru.alphatech.icfpc.game.ICFPCException;
     5.7  import ru.alphatech.icfpc.game.IValue;
     5.8  import ru.alphatech.icfpc.game.Player;
     5.9  import ru.alphatech.icfpc.game.Value;
    5.10 @@ -11,20 +12,26 @@
    5.11  	{
    5.12  		if(value.getClass().equals(Value.class))
    5.13  		{
    5.14 -			if (((Value)value).getValue() < 256 && ((Value)value).getValue() > -1)
    5.15 +			int i = ((Value)value).getValue();
    5.16 +
    5.17 +			if (i < 256 && i > 0)
    5.18  			{
    5.19 -				proponent.getSlot(((Value)value).getValue()).setVitality(proponent.getSlot(((Value)value).getValue()).getVitality() + 1);
    5.20 -				return new ICard()
    5.21 +				int v = proponent.getSlot(i).getVitality();
    5.22 +				if (v < 65535 && v > 0)
    5.23  				{
    5.24 -					@Override
    5.25 -					public IValue returnValue(IValue value, Player proponent, Player opponent)
    5.26 -					{
    5.27 -						return value;
    5.28 -					}
    5.29 -				};
    5.30 +					proponent.getSlot(i).setVitality(v + 1);
    5.31 +				}
    5.32 +			}
    5.33 +			else
    5.34 +			{
    5.35 +				throw new ICFPCException();
    5.36  			}
    5.37  		}
    5.38 +		else
    5.39 +		{
    5.40 +			throw new ICFPCException();
    5.41 +		}
    5.42  
    5.43 -		return new Value(-100);
    5.44 +		return new I();
    5.45  	}
    5.46  }
     6.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Revive.java	Sun Jun 19 10:50:46 2011 +0400
     6.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Revive.java	Sun Jun 19 12:12:55 2011 +0400
     6.3 @@ -1,5 +1,6 @@
     6.4  package ru.alphatech.icfpc.cards;
     6.5  
     6.6 +import ru.alphatech.icfpc.game.ICFPCException;
     6.7  import ru.alphatech.icfpc.game.IValue;
     6.8  import ru.alphatech.icfpc.game.Player;
     6.9  import ru.alphatech.icfpc.game.Value;
    6.10 @@ -12,20 +13,22 @@
    6.11  		if (value.getClass().equals(Value.class))
    6.12  		{
    6.13  			int i = ((Value)value).getValue();
    6.14 -			if (proponent.getSlot(i).getVitality() <= 0)
    6.15 +			if (i >= 0 && i < 256)
    6.16  			{
    6.17 -				proponent.getSlot(i).setVitality(1);
    6.18 +				if (proponent.getSlot(i).getVitality() <= 0)
    6.19 +				{
    6.20 +					proponent.getSlot(i).setVitality(1);
    6.21 +				}
    6.22  			}
    6.23 -
    6.24 -			return new ICard()
    6.25 +			else
    6.26  			{
    6.27 -				@Override
    6.28 -				public IValue returnValue(IValue value, Player proponent, Player opponent)
    6.29 -				{
    6.30 -					return value;
    6.31 -				}
    6.32 -			};
    6.33 +				throw new ICFPCException();
    6.34 +			}
    6.35  		}
    6.36 -		return null;
    6.37 +		else
    6.38 +		{
    6.39 +			throw new ICFPCException();
    6.40 +		}
    6.41 +		return new I();
    6.42  	}
    6.43  }
     7.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Zombie.java	Sun Jun 19 10:50:46 2011 +0400
     7.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Zombie.java	Sun Jun 19 12:12:55 2011 +0400
     7.3 @@ -17,17 +17,13 @@
     7.4  				if (iVal.getClass().equals(Value.class))
     7.5  				{
     7.6  					int i = ((Value)iVal).getValue();
     7.7 -					opponent.getSlot(i).putValue(x);
     7.8 -					opponent.getSlot(i).setVitality(-1);
     7.9 +					if (i >= 0 && i < 256)
    7.10 +					{
    7.11 +						opponent.getSlot(i).putValue(x);
    7.12 +						opponent.getSlot(i).setVitality(-1);
    7.13 +					}
    7.14  				}
    7.15 -				return new ICard()
    7.16 -				{
    7.17 -					@Override
    7.18 -					public IValue returnValue(IValue value, Player proponent, Player opponent)
    7.19 -					{
    7.20 -						return null;
    7.21 -					}
    7.22 -				};
    7.23 +				return new I();
    7.24  			}
    7.25  		};
    7.26  	}