# HG changeset patch # User Azamat S. Kalimoulline # Date 1308481499 -14400 # Node ID a84a3c755d936194af662c113e03d1a2347d2f78 # Parent 2c8b98d4efb84d73c56c1e57196ba8598136aeeb Cards done. Only interpretation of zero card is under question mark. diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Attack.java --- a/src/main/java/ru/alphatech/icfpc/cards/Attack.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Attack.java Sun Jun 19 15:04:59 2011 +0400 @@ -24,27 +24,35 @@ { int i = ((Value)iobj).getValue(); int n = ((Value)nobj).getValue(); - int v = proponent.getSlot(i).getVitality(); - if(i >= 0 && i <= 255 && n <= v) + if(i >= 0 && i <= 255) { - if(jobj instanceof Value) + int v = proponent.getSlot(i).getVitality(); + + if(n <= v) { - int j = ((Value)jobj).getValue(); - - if(j >= 0 && j <= 255) + if(jobj instanceof Value) { - int w = opponent.getSlot(255 - j).getVitality(); + int j = ((Value)jobj).getValue(); - if (w > 0) + if(j >= 0 && j <= 255) { - int wdec = (int) Math.floor(9 * n / 10); - int resw = w - wdec; + int w = opponent.getSlot(255 - j).getVitality(); + + if (w > 0) + { + int wdec = (int) Math.floor(9 * n / 10); + int resw = w - wdec; - opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w); + opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w); + } + + return new I(); } - - return new I(); + else + { + throw new ICFPCException(); + } } else { diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Copy.java --- a/src/main/java/ru/alphatech/icfpc/cards/Copy.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Copy.java Sun Jun 19 15:04:59 2011 +0400 @@ -8,14 +8,15 @@ public class Copy implements ICard { @Override - public IValue returnValue(IValue i, Player proponent, Player opponent) + public IValue returnValue(IValue iobj, Player proponent, Player opponent) { - if (i.getClass().equals(Value.class)) + if (iobj instanceof Value) { - int iVal = ((Value)i).getValue(); - if (iVal >= 0 && iVal < 256) + int i = ((Value)iobj).getValue(); + + if (i >= 0 && i <= 255) { - return opponent.getSlot(((Value)i).getValue()).getValue(); + return opponent.getSlot(i).getValue(); } else { diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Get.java --- a/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 15:04:59 2011 +0400 @@ -13,11 +13,19 @@ if (iobj instanceof Value) { int i = ((Value)iobj).getValue(); - int v = proponent.getSlot(i).getVitality(); - if(i >= 0 && i <= 255 && v > 0) + if(i >= 0 && i <= 255) { - return proponent.getSlot(i).getValue(); + int v = proponent.getSlot(i).getVitality(); + + if(v > 0) + { + return proponent.getSlot(i).getValue(); + } + else + { + throw new ICFPCException(); + } } else { diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Help.java --- a/src/main/java/ru/alphatech/icfpc/cards/Help.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Help.java Sun Jun 19 15:04:59 2011 +0400 @@ -24,27 +24,35 @@ { int i = ((Value)iobj).getValue(); int n = ((Value)nobj).getValue(); - int v = proponent.getSlot(i).getVitality(); - if(i >= 0 && i <= 255 && n <= v) + if(i >= 0 && i <= 255) { - if(jobj instanceof Value) + int v = proponent.getSlot(i).getVitality(); + + if(n <= v) { - int j = ((Value)jobj).getValue(); - - if(j >= 0 && j <= 255) + if(jobj instanceof Value) { - int w = proponent.getSlot(j).getVitality(); + int j = ((Value)jobj).getValue(); - if(w > 0) + if(j >= 0 && j <= 255) { - int winc = (int) Math.floor(11 * n / 10); - int resw = w + winc; + int w = proponent.getSlot(j).getVitality(); - proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw); + if(w > 0) + { + int winc = (int) Math.floor(11 * n / 10); + int resw = w + winc; + + proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw); + } + + return new I(); } - - return new I(); + else + { + throw new ICFPCException(); + } } else { diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Revive.java --- a/src/main/java/ru/alphatech/icfpc/cards/Revive.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Revive.java Sun Jun 19 15:04:59 2011 +0400 @@ -8,17 +8,22 @@ public class Revive implements ICard { @Override - public IValue returnValue(IValue value, Player proponent, Player opponent) + public IValue returnValue(IValue iobj, Player proponent, Player opponent) { - if (value.getClass().equals(Value.class)) + if (iobj instanceof Value) { - int i = ((Value)value).getValue(); - if (i >= 0 && i < 256) + int i = ((Value)iobj).getValue(); + + if (i >= 0 && i <= 255) { - if (proponent.getSlot(i).getVitality() <= 0) + int v = proponent.getSlot(i).getVitality(); + + if (v <= 0) { proponent.getSlot(i).setVitality(1); } + + return new I(); } else { @@ -29,6 +34,5 @@ { throw new ICFPCException(); } - return new I(); } } diff -r 2c8b98d4efb8 -r a84a3c755d93 src/main/java/ru/alphatech/icfpc/cards/Zombie.java --- a/src/main/java/ru/alphatech/icfpc/cards/Zombie.java Sun Jun 19 14:30:33 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Zombie.java Sun Jun 19 15:04:59 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; @@ -7,23 +8,42 @@ public class Zombie implements ICard { @Override - public IValue returnValue(final IValue iVal, Player proponent, Player opponent) + public IValue returnValue(final IValue iobj, Player proponent, Player opponent) { return new ICard() { @Override public IValue returnValue(final IValue x, Player proponent, Player opponent) { - if (iVal.getClass().equals(Value.class)) + if (iobj instanceof Value) { - int i = ((Value)iVal).getValue(); - if (i >= 0 && i < 256) + int i = ((Value)iobj).getValue(); + + if (i >= 0 && i <= 255) { - opponent.getSlot(i).putValue(x); - opponent.getSlot(i).setVitality(-1); + int v = opponent.getSlot(255 - i).getVitality(); + + if(v <= 0) + { + opponent.getSlot(255 - i).putValue(x); + opponent.getSlot(255 - i).setVitality(-1); + + return new I(); + } + else + { + throw new ICFPCException(); + } + } + else + { + throw new ICFPCException(); } } - return new I(); + else + { + throw new ICFPCException(); + } } }; }