My son and I are trying to write a trading game, similar in format to Drug Wars, but without the drugs and set in feudal Japan. The idea is to move from place to place buying and selling goods, building up capital, investing in larger transports, etc.
The problem is we also want to have costs involved. The idea is to base it on a 3x3 grid (maybe larger when we understand the concept), with a cost of x to move to an adjacent square, and 2x to move to a square 2 spaces away. Using Tic-Tac-Toe as an example, if the player is in the middle square, all others are only 1 space away; if they're in a corner square, there are 3 others just one space away, and 5 that are 2 spaces away. For the life of us we can't see how to set up the calculations.
Does anyone have any advice, please? We realise it'd involve tagging each port and using a distance matrix of some sort, but don't see how to code it into Sugarcube.
Any advice gratefully received!
For what you're doing, I'd suggest specific paths rather than allowing the player to hop around the map at random.
This sets up a limited movement map. Note that the like from city4 to city 5 is a one way link, providing an expensive backdoor out of city4 without going through city2.
To get the paths available from a city, use:
<<set $paths to $cities[$here].paths>>
$paths will then be an array, where each element is on object holding the name of the destination city (.to) and the cost of travelling there (.cost). These would be and . You could add an additional attributes to each link such as a name ("High pass", "Coast road", "Way of the Damned") or a chance of encountering bandits or other misadventure etc...
The $cities object is set up so you can add additional attributes to each city, such as market information, descriptions or coordinates on an image map.
The idea was originally to have any-to-any, but seeing it written down, I realise now that that wouldn't make much sense, so your suggestion of specific paths is the way to go.
Thanks very much for the info - I'll try it over the weekend. You've actually also answered what would probably have been a couple of subsequent questions as well, so much appreciated.
It's become clear to us that this game would need be driven by a whole load of arrays: I've just spent my lunch break working on one for the different haulage methods, capacities, affect on movement and market cost - I'm just grateful now my son didn't want to attempt a football manager sim
1. Give your passages coordinates in a matrix system. I guess it would be easiest to set the passage names to these coordinates. Example (using a tic-tac-toe-board):
First value equals x, second value y position.
2. Movements from one passage to another could now be expressed using Eucledean vectors. So if you moved from the middle top field (0｜1) to the bottom left field (2｜0) you would calculate destionation field minus starting field e.g. (2｜0) - (0｜1) = (2 ｜-1)
3. In order to calculate the necessary steps you need to calculate the length of the vector which is the square root of the sum of the two squared values, in our example the square root of 4+1=5, which is, 2.23. The int value of that should do, so you are moving two steps.
Could that solve your issue?