Source

ICFP 2011 ICRS / src / Icfp2011.Icrs / LtgSlot.cs

Full commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Icfp2011.Icrs
{
    public class LtgSlot
    {
        // 0 or -1 => slot is dead
        private int vitality;

        private LtgValue value;

        public LtgSlot(int vitality, LtgValue value)
        {
            this.vitality = vitality;
            this.value = value;
        }

        public bool IsAlive
        {
            get { return this.vitality > 0; }
        }

        public bool IsZombie
        {
            get { return this.vitality == -1; }
        }

        public int Vitality
        {
            get { return this.vitality; }
            set { this.vitality = value; }
        }

        public LtgValue Value
        {
            get { return this.value; }
        }

        public bool ApplyLeft(LtgSlot[] propSlots, LtgSlot[] oppSlots, LtgValue card)
        {
            var depth = 0;
            PerformAutomaticApplication(propSlots);
            this.value = card.Evaluate(ref depth, propSlots, oppSlots, this.value);
            if (this.value == null)
            {
                this.value = LtgCards.ICombinator;
                return false;
            }
            return true;
        }

        public bool ApplyRight(LtgSlot[] propSlots, LtgSlot[] oppSlots, LtgValue card)
        {
            var depth = 0;
            PerformAutomaticApplication(propSlots);
            this.value = this.value.Evaluate(ref depth, propSlots, oppSlots, card);
            if (this.value == null)
            {
                this.value = LtgCards.ICombinator;
                return false;
            }
            return true;
        }

        private void PerformAutomaticApplication(LtgSlot[] propSlots)
        {
            // TODO
        }

        public LtgSlot Clone()
        {
            return new LtgSlot(
                this.vitality,
                this.value
                );
        }
    }
}