Giter Site home page Giter Site logo

Add Basic Trade about villager HOT 2 CLOSED

ThomasThelen avatar ThomasThelen commented on June 5, 2024
Add Basic Trade

from villager.

Comments (2)

ThomasThelen avatar ThomasThelen commented on June 5, 2024

Just a quick note that the double for loop in the Simulation class will have to change. Right now it advances each village through time, independently. ie it runs village A for 10 years, then runs village B for 10 years when it should run village A for 1 year, then run village B for run year, then back to A, etc

from villager.

ThomasThelen avatar ThomasThelen commented on June 5, 2024

After discussing it with Marcus, the trade was originally designed to be in a subclassed village. This is no longer the case, and trade is officially not supported at this moment.

We Currently Have

  1. The ability to connect two villages for trade with add_trade_partner.
  2. A skeleton method for executing trade algorithms, trade

We Don't Have

  1. The ability to add custom functions that dictate trade behavior to the village
  2. The logic that actually executes the trade (the contents of trade())

Adding Custom Functions

I think it makes the most sense to do this with add_trade_partner. This method becomes
add_trade_partner = function(newTradePartner, trade_model, addBack=TRUE). This ties a particular trade model to that village. By pairing the village to the algorithm (village, trade_algo) you can have different dynamics between villages.

The tuple should then be added so some sort of list that belongs in villager, like models.

Running the Trade Models

Once the models are stored, you'll want to run them at each time step. Note that the logic for whether it's a trading day (ie a festival) is in the trade model code.

I believe the trade() method in villager is there for historical reasons. This was the method that subclassed villages subclassed with their trade logic.

There are a couple of ways to do this.

Same way as propagate()

Loop over the trade functions and call them in the trade() method, and call village$trade() in the simulation class. If you put the call before the call to propagate, then the trade is done at the beginning of time step (day, month, year). If it goes after, then it's at the end of the year, month, day, etc.

Call from propagate

You can also put the logic in propagate(). You can also call trade() from propagate and skip the Simulator class

Which One?

There's a nice sense of division of responsibility in the first way. But the second way has a sense of elegance in that just a single call to the village propagates it through time. Your call!

from villager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.