Example #1
0
 public Value Reduce(Slot[] me, Slot[] opponent, ref int applicationsDone, bool zombieMode)
 {
     if (ArgsNeeded > 0)
     {
         applicationsDone++;
         return this;
     }
     var fun = f;
     var args = new List<Value> { arg };
     while (fun is Application)
     {
         var app = (Application)fun;
         args.Insert(0, app.arg);
         fun = app.f;
     }
     if (!(fun is Function)) throw new GameError("cant apply not a function " + fun);
     var res = ((Function)fun).Reduce(me, opponent, args.ToArray(), ref applicationsDone, zombieMode);
     if (!(res is Num) && res.ArgsNeeded == 0) throw new Exception("Bug!");
     return res;
 }
Example #2
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var proponentSlot = args[0].AsSlot();
     var opponentSlot = 255 - args[1].AsSlot();
     var n = args[2].AsNum();
     if (me[proponentSlot].vitality < n) throw new GameError("not enough vitality " + me[proponentSlot].vitality + " for " + this);
     me[proponentSlot].vitality -= n;
     if (opponent[opponentSlot].vitality > 0)
     {
         if (!zombieMode)
         {
             opponent[opponentSlot].vitality -= n*9/10;
             if (opponent[opponentSlot].vitality < 0) opponent[opponentSlot].vitality = 0;
         }
         else
         {
             opponent[opponentSlot].vitality += n * 9 / 10;
             if (opponent[opponentSlot].vitality > 65535) opponent[opponentSlot].vitality = 65535;
         }
     }
     return Funcs.I;
 }
Example #3
0
 private static string SlotsToString(Slot[] slots)
 {
     var sb = new StringBuilder();
     for (int i = 0; i <= 255; i++)
     {
         if (slots[i].vitality != 10000 || slots[i].value != Funcs.I)
             sb.AppendFormat("{0}={{{1},{2}}}\r\n", i, slots[i].vitality, slots[i].value);
     }
     string s = sb.ToString();
     return s.TrimEnd();
 }
Example #4
0
 private static void RessurectZombies(Slot[] me, Slot[] opponent)
 {
     for (int mySlot = 0; mySlot <= 255; mySlot++)
     {
         var currentMySlot = me[mySlot];
         if (!currentMySlot.IsZombie) continue;
         try
         {
             var zobieFunc = currentMySlot.value;
             if (zobieFunc.ArgsNeeded <= 0) throw new GameError("incorrect application of zombie func: " + zobieFunc);
             var applicationsDone = 0;
             new Application(zobieFunc, Funcs.I).Reduce(me, opponent, ref applicationsDone, true);
         }
         catch (GameError e)
         {
             Log(e.Message);
         }
         currentMySlot.vitality = 0;
         currentMySlot.value = Funcs.I;
     }
 }
Example #5
0
 private static void Apply(Slot[] me, Slot[] opponent, Value left, Value right, int resultSlot)
 {
     RessurectZombies(me, opponent);
     try
     {
         if (me[resultSlot].vitality <= 0) throw new GameError("result slot is dead:" + resultSlot);
         if (left.ArgsNeeded <= 0) throw new GameError("incorrect application: " + left + " " + right);
         var applicationsDone = 0;
         var res = new Application(left, right).Reduce(me, opponent, ref applicationsDone, false);
         me[resultSlot].value = res;
     }
     catch (GameError e)
     {
         Log(e.Message);
         me[resultSlot].value = Funcs.I;
     }
 }
Example #6
0
 public static void RegisterMove(Slot[] me, Slot[] opponent, Move move)
 {
     if (move.slot < 0 || move.slot > 255) return;
     if (move.card_to_slot)
         Apply(me, opponent, move.card, me[move.slot].value, move.slot);
     else
         Apply(me, opponent, me[move.slot].value, move.card, move.slot);
 }
Example #7
0
 public World()
 {
     opponent = new Slot[256];
     me = new Slot[256];
     for (int i = 0; i <= 255; i++)
     {
         opponent[i] = new Slot{value = Funcs.I, vitality = 10000};
         me[i] = new Slot{value = Funcs.I, vitality = 10000};
     }
     turnNumber = 0;
 }
Example #8
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var opponentSlot = 255 - args[0].AsSlot();
     var x = args[1];
     if (opponent[opponentSlot].vitality > 0) throw new GameError("Slot is not dead! " + this);
     opponent[opponentSlot].value = x;
     opponent[opponentSlot].vitality = -1;
     return Funcs.I;
 }
Example #9
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var arg = args.First();
     if (arg is Num) return new Num(Math.Min(((Num)arg).num + 1, 65535));
     throw new GameError("Call succ with not a num: " + arg);
 }
Example #10
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var f = args[0];
     var g = args[1];
     var x = args[2];
     var left = new Application(f, x).Reduce(me, opponent, ref applicationsDone, zombieMode);
     var right = new Application(g, x).Reduce(me, opponent, ref applicationsDone, zombieMode);
     var res = new Application(left, right).Reduce(me, opponent, ref applicationsDone, zombieMode);
     return res;
 }
Example #11
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var proponentSlot = args[0].AsSlot();
     if (me[proponentSlot].vitality <= 0)
         me[proponentSlot].vitality = 1;
     return Funcs.I;
 }
Example #12
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     return Funcs.I;
 }
Example #13
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     var slot = args.First().AsSlot();
     var vitality = me[slot].vitality;
     if (!zombieMode)
     {
         if (vitality > 0 && vitality < 65535)
             me[slot].vitality = vitality + 1;
     }
     else
     {
         if (vitality > 0)
             me[slot].vitality = vitality - 1;
     }
     return Funcs.I;
 }
Example #14
0
 public override Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     return me[args.First().AsSlot()].value;
 }
Example #15
0
 public Value Reduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode)
 {
     if (args.Length != ArgsNeeded) throw new Exception("Bug in code!");
     if (applicationsDone >= 1000) throw new GameError("Too many applications " + applicationsDone);
     applicationsDone++;
     //r.Append(" " + ToString());
     var res = DoReduce(me, opponent, args, ref applicationsDone, zombieMode);
     return res;
 }
Example #16
0
 public abstract Value DoReduce(Slot[] me, Slot[] opponent, Value[] args, ref int applicationsDone, bool zombieMode);