Example #1
0
 public Player(string name)
 {
     gems = new Gem();
     reserve = new List<Card>();
     field = new List<Card>();
     this.name = name;
 }
Example #2
0
        public static Move getMove(Board state, IEnumerable<Card> toBuy, IEnumerable<int> weights)
        {
            if (toBuy.Count() < 1) throw new Exception("BuySeeker.getMove called with no cards");
            if (toBuy.Count() != weights.Count()) throw new Exception("Buyseeker called with the wrong number of weights");
            Move target = new Move.BUY(toBuy.First());
            if (target.isLegal(state)) return target;   //Buy if possible
            target = new Move.RESERVE(toBuy.First());
            if (state.notCurrentPlayer.canBuy(state, toBuy.First()) && target.isLegal(state)) return target; //Reserve if opponent can buy

            var zipped = toBuy.Zip(weights, (c, w) => new { cd = c, wt = w });
            int[] needed = new int[5] { 0, 0, 0, 0, 0 };
            foreach (var a in zipped)
            {
                Gem toAdd = neededGems(state, a.cd);
                for (int i = 0; i < 5; i++) needed[i] += toAdd[i] * a.wt;
            }
            Gem targetGems = new Gem(needed);
            Heuristic fn = Heuristic.colors(targetGems);
            return Greedy.getGreedyMove(state, fn);
        }
Example #3
0
        public static void testGems()
        {
            Gem test = new Gem(1, 1, 1, 1, 1, 0);
            Gem testGold = new Gem(0, 0, 0, 0, 0, 1);
            Gem test2 = new Gem(1, 0, 0, 0, 0, 0);
            Debug.Assert(test > test2);
            Debug.Assert(test >= test2);
            Debug.Assert(testGold >= test2);
            Debug.Assert(!(testGold > test2));
            Debug.Assert(!(test2 >= test));
            Debug.Assert(!(test2 > test));

            Debug.Assert(test.takeaway(test2) == new Gem(0, 1, 1, 1, 1, 0));

            foreach (Gem g in Gem.ThreeNetThree)
            {
                int i = 0;
                foreach (Gem k in Gem.ThreeNetThree)
                {
                    if (g == k) i++;
                    Debug.Assert(i < 2, "AllThree contained duplicates!");
                }
            }
        }
Example #4
0
 /// <summary>
 /// Returns the result of spending g gems, gold included.
 /// </summary>
 public Gem takeaway(Gem gem)
 {
     Gem g = gem.positive;
     Gem ret = this;
     for (int i = 0; i < 5; i++)
     {
         if (ret[i] < g[i])
         {
             ret.gold -= g[i] - ret[i];
             ret[i] = 0;
         }
         else
         {
             ret[i] -= Math.Max(0, g[i]);
         }
     }
     if (ret.gold < 0)
     {
         throw new InvalidOperationException("Got negative gold gems somehow.");
     }
     return ret;
 }
Example #5
0
 public Gem requiredToBuy(Gem target)
 {
     return (target - this).positive;
 }
Example #6
0
 public static void Reset()
 {
     selected = Gem.zero;
     colors['w'] = 0;
     colors['u'] = 1;
     colors['b'] = 2;
     colors['r'] = 3;
     colors['g'] = 4;
 }
Example #7
0
 /// <summary>
 /// Standard vector subtraction.
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 public static Gem operator -(Gem a, Gem b)
 {
     Gem ret = new Gem();
     int i;
     for (i = 0; i < 6; i++)
     {
         ret[i] = a[i] - b[i];
     }
     return ret;
 }
Example #8
0
 public static Heuristic colors(Gem c)
 {
     Func<Board, double> fn = b =>
      {
          Gem deltaGems = (b.notCurrentPlayer.Gems - b.PrevBoard.currentPlayer.Gems);
          return (c - (c - deltaGems).positive).magnitude;
      };
     return new Heuristic(fn, "colors: " + c);
 }
Example #9
0
 public TAKE3(Gem x)
 {
     moveType = Type.TAKE3;
     colors = x;
 }
Example #10
0
 public TAKE2(Gem g)
 {
     color = g;
     for (int i=0; i < 5; i++)
     {
         if (g[i] > 0)
         {
             index = i;
             break;
         }
     }
     moveType = Type.TAKE2;
 }
Example #11
0
 public TAKE2(int i)
 {
     color = new Gem();
     color[i] = 2;
     index = i;
     moveType = Type.TAKE2;
 }
Example #12
0
 internal void takeGems(Gem x)
 {
     Gem.board -= x;
     gems += x;
 }
Example #13
0
 internal void Buy(Card c)
 {
     Gem newGems = gems.takeaway((c.cost - discount));
     Gem.board += (gems - newGems);
     gems = newGems;
     field.Add(c);
     c.deck.removeCard(c);
     reserve.Remove(c);
     Card noble;
     if (canGetNoble(out noble))
     {
         noble.deck.removeCard(noble);
         field.Add(noble);
     }
 }