     2 * Math.floor(unique.length / 5)    
 }
 
+makeCard 'Farmland', c.Estate, {
+  cost: 6
+  vp: 2
+
+  upgradeFilter: (state, oldCard, newCard) ->
+    [coins1, potions1] = oldCard.getCost(state)
+    [coins2, potions2] = newCard.getCost(state)
+    return (potions1 >= potions2) and (coins1 + 2 == coins2)
+
+  buyEffect: (state) ->
+    choices = upgradeChoices(state, state.current.hand, this.upgradeFilter)
+    choice = state.current.ai.choose('upgrade', state, choices)
+    if choice isnt null
+      [oldCard, newCard] = choice
+      state.current.doTrash(oldCard)
+      state.gainCard(state.current, newCard)    
+}
+
+
 makeCard 'Gardens', c.Estate, {
   cost: 4
   getVP: (state) -> Math.floor(state.current.getDeck().length / 10)


makeCard 'Adventurer', action, {
  cost: 6

  playEffect: (state) ->
    treasuresDrawn = 0
    while treasuresDrawn < 2
      # Take cards one at a time, and either put them in hand or set them
      # aside depending on their type.
      drawn = state.current.getCardsFromDeck(1)
      if drawn.length == 0
        break
      card = drawn[0]
      if card.isTreasure
        treasuresDrawn += 1
        state.current.hand.push(card)
        state.log("...drawing a #{card}.")
      else
        state.current.setAside.push(card)
    state.current.discard = state.current.discard.concat(state.current.setAside)
    state.current.setAside = []
}

makeCard 'Alchemist', action, {

      transferCard(c['Horse Traders'], player.hand, player.duration)
}

# So far Hunting Party is the only card that digs for something 
# dependent on the game state.
makeCard 'Hunting Party', action, {
  cost: 5
  cards: +1
  actions: +1
  playEffect: (state) ->
    state.revealHand(state.current)    
    drawn = state.current.dig(state,
      (state, card) -> card not in state.current.hand
    )
    if drawn.length > 0
      card = drawn[0]
      state.log("...#{state.current.ai} draws #{card}.")
      state.current.hand.push(card)
}

makeCard 'Ironworks', action, {
