# HG changeset patch # User Igor R. Nikitin <0-range@bazon.ru> # Date 1308471175 -14400 # Node ID 743564afa994b3103b55788fb3911818f5f00fe0 # Parent 0e21db22ecec8ab447e67d7b6e7c0ec9638dc519 changes is good diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Attack.java --- a/src/main/java/ru/alphatech/icfpc/cards/Attack.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Attack.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -24,18 +25,34 @@ int ival = ((Value)i).getValue(); int jval = ((Value)j).getValue(); int nval = ((Value)n).getValue(); - proponent.getSlot(ival).setVitality(proponent.getSlot(ival).getVitality() - nval); - opponent.getSlot(255 - jval).setVitality(opponent.getSlot(255 - jval).getVitality() - ((9 * nval)/10)); - return new ICard() + + if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256) { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) + int v = proponent.getSlot(ival).getVitality(); + int w = opponent.getSlot(255 - jval).getVitality(); + if (v - nval < 1) { - return value; + proponent.getSlot(ival).setVitality(v - nval); + if (w > 0) + { + opponent.getSlot(255 - jval).setVitality(w - ((9 * nval)/10)); + } } - }; + else + { + throw new ICFPCException(); + } + } + else + { + throw new ICFPCException(); + } } - return null; + else + { + throw new ICFPCException(); + } + return new I(); } }; } diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Copy.java --- a/src/main/java/ru/alphatech/icfpc/cards/Copy.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Copy.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -11,9 +12,20 @@ { if (i.getClass().equals(Value.class)) { - return opponent.getSlot(((Value)i).getValue()).getValue(); + int iVal = ((Value)i).getValue(); + if (iVal >= 0 && iVal < 256) + { + return opponent.getSlot(((Value)i).getValue()).getValue(); + } + else + { + throw new ICFPCException(); + } + } + else + { + throw new ICFPCException(); } - return null; } } diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Dec.java --- a/src/main/java/ru/alphatech/icfpc/cards/Dec.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Dec.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -11,18 +12,24 @@ { if(value.getClass().equals(Value.class)) { - if (((Value)value).getValue() < 256 && ((Value)value).getValue() > -1) + int i = ((Value)value).getValue(); + + if (i > 0 && i < 256) { - opponent.getSlot(((Value)value).getValue()).setVitality(opponent.getSlot(((Value)value).getValue()).getVitality() - 1); - return new ICard() + int v = proponent.getSlot(255 - i).getVitality(); + if (v < 65535 && v > 0) { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) - { - return value; - } - }; + proponent.getSlot(255 - i).setVitality(proponent.getSlot(255 - i).getVitality() - 1); + } } + else + { + throw new ICFPCException(); + } + } + else + { + throw new ICFPCException(); } return new Value(-100); diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Help.java --- a/src/main/java/ru/alphatech/icfpc/cards/Help.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Help.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -24,16 +25,37 @@ int ival = ((Value)i).getValue(); int jval = ((Value)j).getValue(); int nval = ((Value)n).getValue(); - proponent.getSlot(ival).setVitality(proponent.getSlot(ival).getVitality() - nval); - proponent.getSlot(jval).setVitality(proponent.getSlot(jval).getVitality() + ((11 * nval)/10)); - return new ICard() + if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256) { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) + int v = proponent.getSlot(ival).getVitality(); + int w = proponent.getSlot(jval).getVitality(); + + if (v > nval) { - return value; + proponent.getSlot(ival).setVitality(v - nval); + if (w > 0) + { + if (w >= 65535) + { + proponent.getSlot(jval).setVitality(65535); + } + else + { + proponent.getSlot(jval).setVitality(w + ((11 * nval)/10)); + } + } } - }; + else + { + throw new ICFPCException(); + } + } + else + { + throw new ICFPCException(); + } + + return new I(); } return null; } diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Inc.java --- a/src/main/java/ru/alphatech/icfpc/cards/Inc.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Inc.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -11,20 +12,26 @@ { if(value.getClass().equals(Value.class)) { - if (((Value)value).getValue() < 256 && ((Value)value).getValue() > -1) + int i = ((Value)value).getValue(); + + if (i < 256 && i > 0) { - proponent.getSlot(((Value)value).getValue()).setVitality(proponent.getSlot(((Value)value).getValue()).getVitality() + 1); - return new ICard() + int v = proponent.getSlot(i).getVitality(); + if (v < 65535 && v > 0) { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) - { - return value; - } - }; + proponent.getSlot(i).setVitality(v + 1); + } + } + else + { + throw new ICFPCException(); } } + else + { + throw new ICFPCException(); + } - return new Value(-100); + return new I(); } } diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Revive.java --- a/src/main/java/ru/alphatech/icfpc/cards/Revive.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Revive.java Sun Jun 19 12:12:55 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -12,20 +13,22 @@ if (value.getClass().equals(Value.class)) { int i = ((Value)value).getValue(); - if (proponent.getSlot(i).getVitality() <= 0) + if (i >= 0 && i < 256) { - proponent.getSlot(i).setVitality(1); + if (proponent.getSlot(i).getVitality() <= 0) + { + proponent.getSlot(i).setVitality(1); + } } - - return new ICard() + else { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) - { - return value; - } - }; + throw new ICFPCException(); + } } - return null; + else + { + throw new ICFPCException(); + } + return new I(); } } diff -r 0e21db22ecec -r 743564afa994 src/main/java/ru/alphatech/icfpc/cards/Zombie.java --- a/src/main/java/ru/alphatech/icfpc/cards/Zombie.java Sun Jun 19 10:50:46 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Zombie.java Sun Jun 19 12:12:55 2011 +0400 @@ -17,17 +17,13 @@ if (iVal.getClass().equals(Value.class)) { int i = ((Value)iVal).getValue(); - opponent.getSlot(i).putValue(x); - opponent.getSlot(i).setVitality(-1); + if (i >= 0 && i < 256) + { + opponent.getSlot(i).putValue(x); + opponent.getSlot(i).setVitality(-1); + } } - return new ICard() - { - @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) - { - return null; - } - }; + return new I(); } }; }