src/main/java/ru/alphatech/icfpc/cards/Attack.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Tue, 21 Jun 2011 11:55:31 +0400
changeset 140 9ddaa68cccae
parent 102 cc814352ab43
permissions -rw-r--r--
Cards bugs revealed.
     1 package ru.alphatech.icfpc.cards;
     2 
     3 import ru.alphatech.icfpc.game.ICFPCException;
     4 import ru.alphatech.icfpc.game.IValue;
     5 import ru.alphatech.icfpc.game.Player;
     6 import ru.alphatech.icfpc.game.Run;
     7 import ru.alphatech.icfpc.game.Value;
     8 
     9 public class Attack extends AbstractCard
    10 {
    11 	@Override
    12 	public String getName() {
    13 		return "attack";
    14 	}
    15 
    16 	@Override
    17 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    18 	{
    19 		return new AbstractCard()
    20 		{
    21 			@Override
    22 			public String getName() {
    23 				return "attack(" + iobj + ")";
    24 			}
    25 			
    26 			@Override
    27 			public IValue returnValue(final IValue jobj, Player proponent, Player opponent)
    28 			{
    29 				incAndTest();
    30 				
    31 				return new AbstractCard()
    32 				{
    33 					@Override
    34 					public String getName() {
    35 						return "attack(" + iobj + ")(" + jobj + ")";
    36 					}
    37 					@Override
    38 					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    39 					{
    40 						incAndTest();
    41 						
    42 						if(iobj instanceof Value && nobj instanceof Value)
    43 						{
    44 							int i = ((Value)iobj).getValue();
    45 							int n = ((Value)nobj).getValue();
    46 							
    47 							if(i >= 0 && i <= 255)
    48 							{
    49 								int v = proponent.getSlot(i).getVitality();
    50 
    51 								if(n <= v)
    52 								{
    53 									proponent.getSlot(i).setVitality(v - n);
    54 
    55 									if(jobj instanceof Value)
    56 									{
    57 										int j = ((Value)jobj).getValue();
    58 										
    59 										if(j >= 0 && j <= 255)
    60 										{
    61 											int w = opponent.getSlot(255 - j).getVitality();
    62 											
    63 											if(Run.getAutoMode())
    64 											{
    65 												if(w > 0)
    66 												{
    67 													int wdec = (int) Math.floor(9 * n / 10);
    68 													int resw = w + wdec;
    69 
    70 													opponent.getSlot(255 - j).setVitality(resw > 65535 ? 65535 : w);
    71 												}
    72 											}
    73 											else
    74 											{
    75 												if (w > 0)
    76 												{
    77 													int wdec = (int) Math.floor(9 * n / 10);
    78 													int resw = w - wdec;
    79 
    80 													opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w);
    81 												}
    82 											}											
    83 
    84 											return new I();
    85 										}
    86 										else
    87 										{
    88 											throw new ICFPCException();
    89 										}
    90 									}
    91 									else
    92 									{
    93 										throw new ICFPCException();
    94 									}
    95 								}
    96 								else
    97 								{
    98 									throw new ICFPCException();
    99 								}
   100 							}
   101 							else
   102 							{
   103 								throw new ICFPCException();
   104 							}
   105 						}
   106 						else
   107 						{
   108 							throw new ICFPCException();
   109 						}
   110 					}
   111 				};
   112 			}
   113 		};
   114 	}
   115 
   116 }