• Create Account

# Álvaro

Member Since 07 Mar 2002
Offline Last Active Today, 12:24 AM

### #53139853D Dubins over-estimate the path cost by an extremely small fraction

Posted by on 05 October 2016 - 05:05 AM

Try using doubles and a more correct approximation to pi (like std::atan(1.0)*4.0). If that doesn't work, then your problem is not lack of precision.

With my non-understanding [and your non-explaining] of what you are doing, that's the only advice I can give you.

### #5313629Generating all possible combinations of route in a graph?

Posted by on 02 October 2016 - 03:49 PM

The result is stored as a single matrix indicating the total cost for the path between any two nodes. Reconstructing the paths from this information is very easy.

Yes, storing ONLY the optimal distances between all paths is relatively small.  But often it is also nearly useless by itself.

Reconstructing the paths is not always "very easy" as you blithely commented.  For scenarios such as a small game level's map it can be easy, but for other scenarios it can require significant processing; for moderate searches it can become something that is no longer approachable realtime in a game, or outside of games becoming something that is an hours-long process.

You just need to move to the neighbor that minimizes the sum of cost from here to neighbor and cost from neighbor to destination. What's a realistic scenario where that is difficult implement or expensive to run?

### #5313502How to calcolate moving vector of object by its rotation degress in 2d

Posted by on 01 October 2016 - 12:24 PM

The vector is (cos(angle), sin(angle)). This vector is so useful that you generally don't need to deal with the angle at all. The representation of a direction as a unit-length vector is much better for many reasons, even if you find angles more natural.

### #5313276When should I use int32_t rather than int

Posted by on 29 September 2016 - 11:43 AM

Also correct:
for ( auto i = 0; i < someVec.size(); ++)

Unfortunately, that's not correct. That `auto' will have the same effect as `int', since that's the type of `0'.

### #5312885target selection strategies

Posted by on 27 September 2016 - 12:23 PM

The problem is that real humans and indeed real decisions don't work that way.

This is true. I have mostly dealt with situations where rational behavior is preferred, and imitating humans is irrelevant.

But I do have some experience in making utility systems that need to conform to rules. There are two ways of mixing them:
* Rules cannot be broken (e.g., you need to obey regulations in a trading system).
* Following rules is encouraged. I believe this is what applies to games.

So you can have a utility system where one of the terms in evaluating an action is whether this action is in accordance with a set of rules. The weight of this term can be adjusted so rules will be ignored at the right time. That way you may be able to get the best of both worlds: The utility mechanism will take care of emergency situations, and the designer still can describe how things should happen under normal circumstances.

For instance, a rule might say that the correct action to perform now is make tea, because a guest has requested it. But someone just started shooting. Ignoring the rules, the utility of taking cover is much higher than the utility of making tea, so even with the bonus for following rules making tea won't be selected.

### #53128162D circle and OBB moments of inertia

Posted by on 27 September 2016 - 06:51 AM

Integral of density is mass, integral of position times density divided by mass is center of mass, integral of density times the square of the distance to the center of mass is moment of inertia. [EDIT: I had forgotten about the square, sorry.]

I guess I just went to a good high school.

### #5312810target selection strategies

Posted by on 27 September 2016 - 06:38 AM

Incidentally this is probably the most significant problem that I have with utility systems - designers often have a mental model of the ranking or precedence that they want the actions to have, but trying to force the mathematics to produce that result consistently can be very difficult.

While this is indeed a problem, I think it's a problem with designers, not utility systems. The way designers often think about behavior (rankings of actions, if-then rules...) is brittle by nature and results in many absurd situations. Designers just need to get more sophisticated in their thinking and learn to describe their preferences as utility functions.

It is very important to give them tools to understand why an agent is behaving the way it's behaving, like a display of available actions, the contribution of each term in the utility function to the final assessment, etc.

### #5312355C++ Angle bracket function

Posted by on 24 September 2016 - 06:57 PM

Sorry for not replying for a while! I managed to get it all sorted out thanks to your help!

It would be nice if you could give us a brief description of what worked for you. That way this thread would be more helpful to people that find it in the future when they have a similar problem to yours.

### #5312352target selection strategies

Posted by on 24 September 2016 - 06:05 PM

The most robust strategy is to consider all targets and all interactions, and pick the best combination. Utility systems are great for this. It helps to mix in "non-targeted" actions as well (running away, healing, etc.) so you can always have something semi-reasonable to do regardless of situation.

This.

### #5312127Provide a quick code-review of c++ code?

Posted by on 23 September 2016 - 09:43 AM

I was reading Alberth's comments so I looked at the code starting at line 487:
```	int yPos = 0;

switch (barData.uEdge)
{
case ABE_LEFT:
case ABE_RIGHT:
{
yPos = btnDim.top - lbH - 10;
}
break;
case ABE_TOP:
{
yPos = btnDim.bottom + 10;
}
break;
//case ABE_BOTTOM:
default:
{
yPos = btnDim.top - lbH - 10;
}
break;
}
```

`	int yPos = (barData.uEdge == ABE_TOP) ? btnDim.bottom + 10 : btnDim.top - lbH - 10;`

### #5311534C++ Angle bracket function

Posted by on 19 September 2016 - 09:49 PM

Or just do addComponent(BaseComponent* baseComponent). No need to use templates.

I sometimes feel invisible.

### #5311459C++ Angle bracket function

Posted by on 19 September 2016 - 11:20 AM

```void addComponent(std::unique_ptr<BaseComponent> component) {
components.push_back(component);
}```
Probably something like that, perhaps with a different type of pointer, depending on how exactly you handle ownership.

### #5311188Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 17 September 2016 - 05:27 AM

Here's what to do in situations like this one: Make a copy of your code and boil it down to the smallest possible program that still shows the problem. Remove absolutely everything you can that doesn't have to do with the particular crash. Put all the code in a single file.

Now either of two things will happen:
(1) You discover the problem in the process of creating the small version of the program.
(2) You have a short program that you can post here, so we can all reproduce the problem and help you much better. If it turns out the short program is obviously correct and it's still breaking, you can include this code in a bug report.

Now, in the last 20 years of programming I have found a compiler bug exactly once. So the prior probability that you found one is very small, and the fact that your code has some issues (like not checking return values) leads me to lower my estimate in light of what I know about the situation.

### #5310841Find the domain of this function.

Posted by on 14 September 2016 - 03:33 PM

That's a second-degree inequality in v^2:

(v^2)^2 - 2gy * v^2 - g^2x^2 >= 0

The solutions are values of v for which

v^2 >= g * (y + sqrt(y^2 + x^2))
or
v^2 <= g * (y - sqrt(y^2 + x^2))

But (y - sqrt(y^2 + x^2)) is always negative, so the second condition never really happens.

Taking a square root on the first inequality, you get what I think is the final answer:

abs(v) >= sqrt(g * (y + sqrt(y^2 + x^2)))

### #5310621Why can't I print out my std::string vector?

Posted by on 13 September 2016 - 12:49 PM

A singleton is rarely a good solution. In a well-designed program you typically don't have that many dependencies, so perhaps you need to rethink your design. Sending the references everywhere at least makes the dependencies explicit. Otherwise you'll try to reuse some piece of code for a new project and you'll realize that the whole project has become one monolithic mess and you can't do it.

If you end up using global state of some sort, what is the advantage of using a singleton over using a global variable?

PARTNERS