About     Blog     LinkedIn     GitHub    

23 Aug 2015
Remaking Tradewars - Part V
Outposts and Traders

Tradewars -- Trading what?

Half the point of Tradewars is the act of trading! Now that we've established a universe, we need to populate it with two things: ports and traders!

In Tradewars, each port sells three things: Fuel, Ore, and Equipment. The port also gets designated a Class, and the Class identifies which type of trades they make. The description is delineated as [BBS]. The B stands for Buy, and the S stands for Sell. The letters occur in the order of Fuel, Ore, and Equipment.

For instance, [BBS] means it buys fuel, buys ore, and sells equipment.

If you visit a port that sells Equipment, you cannot buy equipment from that port.

Enough about that. Here's a list of the possible Classes:

Class Description Fuel Ore Equipment
1 BBS Buy Buy Sell
2 BSB Buy Sell Buy
3 SBB Sell Buy Buy
4 SSB Sell Sell Buy
5 SBS Sell Buy Sell
6 BSS Buy Sell Sell
7 SSS Sell Sell Sell
8 BBB Buy Buy Buy

Make sense? Great.

Port Theory

Like I said earlier, half the point of the game is to trade. Since some ports only buy certain goods and other ports only sell certain goods, it stands to reason that a savvy trader might find two ports near each other with reasonable prices and travel back and forth between the two of them.

If we have ports too close together, the game gets too easy. If they're too far apart, it takes too long to play.

In other words, we need to be careful about exactly how many outposts we set up.

The second concern is pricing. If Port A sells Fuel for 100 credits, and Port B buys Fuel for 200 credits, then it's profitable to travel to Port A, buy up a bunch of Fuel, then go to Port B and sell it all.

On teh other hand, if Port A sells Fuel for 200 credits, and port B buys Fuel for 100 credits, then it's not worth it at all. You'd lose 100 credits per Fuel!

On yet another hand (apparently we have three hands), you don't want it to always be profitable. That would be too easy. We'll need to add an element of randomness.

Generating Ports

When we generate ports, we have to think of a few numbers.

Port Density and Distribution

Let's say we initialize our universe with 100 sectors. (Clusters don't really matter -- if we choose random sectors, our ports should be randomly distributed.)

With 100 sectors and a port density of about 40%, that gives us 40 sectors. Sounds about right.

Not all ports are created equal. The original Tradewars created Ports in roughly this distribution:

Class Description Chance
1 BBS 20%
2 BSB 20%
3 SBB 20%
4 SSB 10%
5 SBS 10%
6 BSS 10%
7 SSS 5%
8 BBB 5%


The next thing we need to decide is the pricing structure. In Tradewars, Fuel is cheapest and Equipment is the most expensive, with Ore falling somewhere in between.

One strategy is to do something like: RAND(STANDARD) + MIN. You pick a "standard" price and then specify a minimum. Pick a random number between 0 and STANDARD, then add the minimum. This gives you a final number between MIN and STANDARD + MIN.

Here are the values I picked, which may or may not line up to Tradewars standards:

Class MIN STANDARD Lowest Highest
Fuel 50 100 50 150
Ore 150 500 150 650
Equipment 750 2500 750 3250


The final thing we need to consider about a port is its inventory: how many of each item do we have?

Let's go back to our original thought: if Port A sold Fuel for 100 and Port B bought Fuel for 200, then the trader could go back and forth and make a huge profit. This is good in the short term, but it makes the game way too easy if you can just do it forever! The solution: limited inventory.

We can use exactly the same algorithm as above to generate random inventories for a given Port.

For prices, Fuel was the cheapest and Equipment was the most expensive. The basic economic theory of supply and demand tells us that Fuel, being the cheapest, would be the most plentiful, while Equipment, being the most expensive, would be relatively rare.

For our inventory, here are the values I picked, which, again, may or may not line up to Tradewars standards:

Class MIN STANDARD Lowest Highest
Fuel 50 100 50 150
Ore 10 50 10 60
Equipment 0 25 0 25

You'll notice that it's theoretically possible for a Port to not have any Equipment at all! That sucks, but fortunately, it'll only be temporary. All ports have to restock, eventually!

The Algorithm

This one is pretty straightforward:


for 0..NUM_PORTS
    port = new Port
    chance = Random number between 0 and 100
    switch(true) {
        case chance < 20:  port.class = 1; break; // 20% chance of Class 1
        case chance < 40:  port.class = 2; break; // 20% chance of Class 2
        case chance < 60:  port.class = 3; break; // 20% chance of Class 3
        case chance < 70:  port.class = 4; break; // 10% chance of Class 4
        case chance < 80:  port.class = 5; break; // 10% chance of Class 5
        case chance < 90:  port.class = 6; break; // 10% chance of Class 6
        case chance < 95:  port.class = 7; break; // 5% chance of Class 7
        case chance < 100: port.class = 8; break; // 5% chance of Class 8

    port.price.fuel      = Random(100) + 50;
    port.price.ore       = Random(500) + 150; = Random(2500) + 750;

    port.inventory.fuel      = Random(100) + 50;
    port.inventory.ore       = Random(50) + 10; = Random(25) + 0;

    add port to random sector in Universe

That should be it!



About     Blog     LinkedIn     GitHub