Home

Awesome

Dukedom

Port of (link) to Ruby for fun and understanding

Rough Loop

  1. Print Banner
  2. Init a Ledger
  3. Choose a Reporter
  4. Create Game w/ Ledger, Reporter
  5. Game.start
  6. Report
  7. Make a Food Manager (Chef)
  8. Update Ledger / End check
  9. Make a Real Estate Manager
  10. Update Ledger / End check
  11. War with king? (I think)
  12. Make a Farm Manager
  13. Update Ledger
  14. War check again?
  15. Process Disease Stuff
  16. Increment Year
  17. Retirement check
  18. Goto 6
  19. Why did we break?

Land Minister

Buy Land

Sell Land

War Minister: King over land

TODO:

Agriculture Minister

War with another Duke OR King

TODO

x Fields

Crop planting, locusts, rotation from python game, converted to ruby/pseudo


def allocate(list, amount)
  list.each_with_object([]) do |item, collection|
    x = [amount, item].min
    collection << item - x
    amount -= max(amount - x, 0)
  end
end

grain = 10000
crop_yield = 0

puts('Land to be planted = ')
farmed = gets
seeding = farmed * 2 # it takes two hl of grain to plant 1 ha of land
grain -= seeding

sown = allocate(land, farmed)                           # land, high-to-low, how much farmed
fallow = land.zip(sown).collect {|a| a.first - a.last } # land, high-to-low, amount less farmed

# Crop gains - yield starts with a random number
crop_yield = distributions.random(2) + 9 

if (year % 7) == 0
  # Field grain is eaten by seven year locusts. They eat half of all your crop
  # in the years that they appear.
  puts 'Seven year locusts.'
  crop_yield = round(crop_yield * 0.65) # Hmm, not really half...
end

weighted = sown[0..4].each_with_index { |field, i| field * 1.0 - (0.2 * i) }.sum
crop_yield = if farmed == 0
               0
             else
               round(crop_yield * (weighted / farmed) * 100) / 100
             end
puts("Yield = #{crop_yield} HL/HA.")
# save to ledger

# sown land reduces quality for next year 
sown.unshift(0)            # 100 gets depleted; each section gets demoted
sown[5] = sown[5..6].sum   # 0% land gets sum of 20 + 0%
sown.pop                   # don't need extra element

# fallow land improves for next year
nutrition = []
nutrition << fallow[0..2].sum # promote unused 100/80/60 to 100
nutrition += fallow[3..5]     # 80 = 40, 60 = 20, 40 = 0% 
nutrition += [0, 0]           # 20 = 0, 0% = 0

# add depletion + nutrition
land.each_with_index do |field, i|
  field = sown[i] + nutrition[i]
end

new_land = sown.zip(nutrition).collect{|a| a.sum }


# Alternate

farmed_land = gets
ledger.seeding = farmed_land * 2 

ledger.fields.plant(farmed_land) # plant & rotate
ledger.crop_yield_rate = ledger.fields.harvest(locusts?)
ledger.crop_yield = ledger.crop_yield_rate * farmed_land