State of Profit

You mean more than 400 buses ? :stuck_out_tongue:

I have found out why some of my buses couldn’t find path… I have clicked on rotation on some station so they was not connected to any road :-.

So to avoid mistake :

  • station shouldn’t be build if there is not a road near by
  • when rotation station, it should stop only on a valid rotation

Best bus : 2112.

Only build station where there are roads I don’t agree with (maybe you want to build a station first and pull the road afterwards), but only rotating to a road sounds like a very good idea. Consider it on the todo list :slight_smile:

2100? I need to build a better bus route…

Maintenance costs - 250 per hour per station and 500 per bus? That would mean that if you built 2 stations and have 3 busses going in between them at more or less full loads you’d make 2000 less per hour (making about 1700 instead of 3700). That’d make the game quite slow so maybe I should increase the money made with 25% so you’d make 2700 instead of 3700 (getting closer to the money made I want the finished game to have).

Increasing money generated with 25% and only asking 500 per bus will make it more or less impossible for a bus to loose money though. My worst bus makes 800 per hour, with the 25% increase that’d become 1000. Asking 1000 (or more) per bus is going to make the game really slow unless there are more ways to make money or if you start with much more money.

Kind regards,
Mike

Well, I don’t see the point to build a station in the middle of no where ;D

I’m a few surprise that maintenance cost of the building is lower thant those of buses (all depend of what you want to encourage). What ever you have calculated, it is wrong :wink: ! There is only try and adjustement.

You can also make a variable cost for busses : the older it is, the higher is the maintenance cost. with this, when you start, you have lower maintenance cost.

(Darn a lot of my busses earn less that 500, but I used a “funny” strategy).

News : the east-west axe is open :stuck_out_tongue:
Next objective : make the longest road possible for a bus : south-west -> north-east :smiley:

I think Lindy (the missis) already have the longest roads possible :stuck_out_tongue:

I agree that you most of the time build stations next to city roads, but what if you need to pull one or two road pieces to get the best spot in the city? :wink:

Increasing maintenance costs with older cars was something I thought about on the way to my mom today (Riven had already mentioned something similar), and it seems like a nice idea which isn’t very hard to implement, but it might be a bit harder to visualize so I think it’ll have to wait.

I’d prefer to keep the bus costs higher than the station costs as the bus costs is visible and easy to relate to whether or not a bus line is lucrative. Station costs will be a bit hid away on the economy page.

Economy page… let me finish the maintenance cost (already implemented in the test environment but not tested) and then see what I can do about a summary page for your economy :slight_smile:

As of tomorrow I’ll be driving back to home after the vacation, so don’t expect too many updates or posts until Monday or so.

Mike

Back from vacation and ready to take over the world! Great job with updating and fixing the game Mickelukas!

I wish there was an easy way to spend large amounts of money, it becomes hard to get rid of millions :stuck_out_tongue:

Maybe large buildings you can buy for cities that increases the rate of growth slightly?

The server crashes a lot, I guess it’s reaching its limit?

After a few days off, I just spent 2.500.000 on new bus-stations and buses. :point:

Now the game won’t launch :frowning: “Updating classpath” and then the webpage and eventually the browser hangs

It gets stuck on “Connecting http://stateofprofit.com:39430/” so it seems the server is down :frowning:

The server is up (now) but there are barely any buses leaving.

The server was up for a second before going down again :’(

Found an internet connection in the hotel, I’ll look into it :slight_smile:

Mike

Wow…bug fixing while on vacation, your wife should be pissed :smiley:

She’s lying next to me reading something :slight_smile: I actually went on vacation 3 weeks ago, all the time I spent on the game since I posted it on the forum was during my vacation :slight_smile:

It’s due to the path finding system, for some reason it takes like 20+ seconds to find a path out of 5000 or so nodes, need to figure out why…

Mike

I just had added a shortcut of a road, but all the buses took the detour. (buses created after the detour)

Well, I can restart the server (which will hopefully fix it right away), but I prefer it not to happen again :slight_smile:

Edit: Great, eclipse doesn’t want to debug it anymore and keeps leaving suspend. I’ll restart it and have a look at the code offline. I might post the path finding code here if someone sees any (major) improvements.

Edit: Nope, the path finding code (not even the creation of nodes or something) it’s back to taking 100% of the CPU. Let’s see for how long, I mean, they all leave at the same time when starting up the server so if it’s for a minute or so it’s not too bad.

Mike

The path finding code is way to slow to support all roads built together creating 5-6000 nodes (Especially if a path cannot be found as it needs to go through them all).

Help!

Find path:

public static Path findPath(final Point2DInteger fromPoint, final Point2DInteger toPoint) {
        synchronized (nodes) {
            if (!nodes.contains(fromPoint) || !nodes.contains(toPoint)) {
                return null;
            }
            final OrderedNodeList openList = new OrderedNodeList();
            final OrderedNodeList closedList = new OrderedNodeList();
            final Node endNode = getNode(toPoint);
            CalculatingNode tempNode;
            final CalculatingNode startNode = new CalculatingNode(getNode(fromPoint), null, endNode, 0, 0, 0);
            openList.add(startNode);

            while (!openList.isEmpty()) {
                final CalculatingNode node = openList.removeFirst();
                if (node.getNode().equals(endNode)) {
                    return constructPath(node);
                }

                final LinkedList<Node> neighbors = node.getNode().getNeighbors();
                for (int i = 0; i < neighbors.size(); i++) {
                    final Node neighborNode = neighbors.get(i);
                    final boolean isOpen = openList.contains(neighborNode);
                    final boolean isClosed = closedList.contains(neighborNode);
                    final float costFromStart = node.getCostFromStart() + node.getNode().getCost(neighborNode);

                    if (!isOpen && !isClosed) {
                        tempNode =
                            new CalculatingNode(neighborNode, node, endNode, costFromStart, node.getNode().getDirection(
                                neighborNode), node.getNode().getCost(neighborNode));
                        openList.add(tempNode);
                    } else if (isOpen) {
                        tempNode = (CalculatingNode)openList.get(neighborNode);
                        if (costFromStart < tempNode.getCostFromStart()) {
                            tempNode.setPathParent(node);
                            tempNode.setCostFromStart(costFromStart);
                            tempNode.setCost(node.getNode().getCost(neighborNode));
                            tempNode.setDirection(node.getNode().getDirection(neighborNode));
                        }
                    } else if (isClosed) {
                        tempNode = (CalculatingNode)closedList.get(neighborNode);
                        if (costFromStart < tempNode.getCostFromStart()) {
                            tempNode.setPathParent(node);
                            tempNode.setCostFromStart(costFromStart);
                            closedList.remove(tempNode);
                            openList.add(tempNode);
                        }
                    }
                }
                closedList.add(node);
            }
        }
        // no path found
        return null;
    }

OrderedNodeList:

import java.util.LinkedList;

class OrderedNodeList extends LinkedList<CalculatingNode> {

    private static final long serialVersionUID = 5949236832559417161L;

    @Override
    public boolean add(final CalculatingNode node) {
        for (int i = 0; i < size(); i++) {
            if (node.compareTo(get(i)) <= 0) {
                add(i, node);
                return true;
            }
        }
        addLast(node);
        return true;
    }

    protected Node get(final Node node) {
        for (int i = 0; i < size(); i++) {
            if (node.equals(get(i))) {
                return get(i);
            }
        }
        return null;
    }
}

Any help is appreciated :slight_smile:

Mike

Please replace OrderedNodeList with java.util.TreeMap<CalculatingNode,CalculatingNode>:


public void add(CalculatingNode node)
{
   this.map.put(node, node); // pushes out old node, if any
}

public CalculatingNode get(CalculatingNode node)
{
    return this.map.get(node);
}

You’ll get logarithmic insert/lookup times, as opposed to linear scaling.

Besides, why are you adding duplicate nodes in your collection?

if (node.compareTo(get(i)) <= 0) {
                add(i, node); // if compareTo == 0, do NOT add
                return true;
            }

that will probably result in even worse (exponential) performance degradation.

Where I read up on how to do pathfinding it said that I needed a OrderedNodeList (in the way I implemented it) to have nodes in the correct order when doing get(), otherwise doing get doesn’t guarantee to get the open node with the lowest cost until now

The compareTo doesn’t return 0 if the node is the same, it does the following

public int compareTo(final CalculatingNode node) {
        final float thisValue = getTotalCost();
        final float otherValue = node.getTotalCost();
        final float v = thisValue - otherValue;
        return v > 0 ? 1 : v < 0 ? -1 : 0;
    }

TreeMap is ordered.

if you really want duplicate nodes, I think you should do:


TreeMap<CalculatingNode,LinkedList<CalculatingNode>> ordered;
ordered = new TreeMap<CalculatingNode,LinkedList<CalculatingNode>>();

public void add(CalculatingNode node)
{
   LinkedList<CalculatingNode> matches = this.map.get(node);
   if(matches==null)
      this.map.put(node, matches=new LinkedList<CalculatingNode>());
   matches.addFirst(node);
}
 
public CalculatingNode get(CalculatingNode node)
{
    LinkedList<CalculatingNode> matches = this.map.get(node);
    if(matches==null || matches.isEmpty())
       return null;
   return this.matches.getFirst();
}

public boolean contains(CalculatingNode node)
{
    LinkedList<CalculatingNode> matches = this.map.get(node);
    return (matches!=null && !matches.isEmpty());
}

public CalculatingNode remove(CalculatingNode node)
{
    LinkedList<CalculatingNode> matches = this.map.get(node);
    if(matches==null || matches.isEmpty())
       return null;
   return this.matches.removeFirst();
}

Ah, treemap looks nice! I’ll switch over to it (sorry for not just switching but I want to understand the code in my game :))

Reg duplicates: I’ll need nodes with the same compare in the list as two nodes might have the same cost from the start point but take two different paths to the end node. I don’t want the same node in there twice though, but the checked ones end up in the closed list and if they’re closed the won’t get added (meaning that there shouldn’t be any duplicates).

Yikes, I’m measuring the speed now of the findPath function and it sometimes takes 300 seconds to do a single one(!)

Mike