Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Mar 2002
Online Last Active Today, 12:59 PM

#5170614 Why NDC and how to convert?

Posted by Álvaro on Today, 09:25 AM

Did you try to use Google to find an answer to your first two questions? Here's the first link I found: http://stackoverflow.com/questions/15693231/normalized-device-coordinates

I don't understand how ints could be used instead of floats in DirectX. floats have a huge range and similar relative errors across the range. If you were to use ints, how would you encode the normalized vector (0.707107f, 0.707107f, 0)?

#5170483 Creating an AI for a CCG

Posted by Álvaro on Yesterday, 07:23 PM

Most card games have the added wrinkle that you can't see what cards your opponents have. I would start by writing an AI for a version of the game in which all information is public (everyone plays with their hand open). You can implement Monte Carlo search without the "tree" part, because it's easier and because the tree part is nearly useless for the full game (with hidden information).

One way to handle hidden information that is theoretically sound consists on generating random card distributions that are consistent with what has happened in the game so far (trying to not introduce biases) and using Bayes's formula to compute their likelihood, given a probabilistic model of how players pick moves (you can start with a model that gives all moves equal probability, but your program won't be very good at guessing the opponents' hands). Play the rest of the game normally (as you were doing in the previous paragraph) until you reach a terminal state and update the statistics for your first move, using a weight that is the likelihood of the card distribution.

#5170129 Can somebody explain this code to me, please

Posted by Álvaro on 29 July 2014 - 11:49 AM

I sometimes need to read Perl as part of my job, and I refuse to do it when I am not getting paid. smile.png

You can figure out a lot of things by running the program in the debugger (perl -d), if you have an environment where you can run it.

#5169986 Best Way To Calculate Reflection

Posted by Álvaro on 29 July 2014 - 03:17 AM

Why would you want to delete it? And why not leave the original question? Even if you found the answer on your own, this thread could be useful to other people that might find it in the future...

I have an arbitrary surface normal and the normalized velocity of an object hitting the surface. Is there a way I can calculate the proper reflection vector without using trig operations?

It can be done using the dot product, like this:

reflected_vector = incident_vector - 2 * dot_product(incident_vector, normal) * normal

#5169856 Adding some variation to AI

Posted by Álvaro on 28 July 2014 - 03:08 PM

There is a cheap trick that would solve the problem of all your synchronized enemies and would make them seem much smarter too: Limit how many agents can perform a particular task at a given time (usually to one). For instance, one agent might decide to shoot at the player while running, without taking cover. The other agents might want to do the same, but the slot is now taken, so perhaps they will run for cover instead, and provide suppressive fire once they get there. If you also keep slots for taking cover at particular spots, they will take cover in different spots. Since only one agent can run and shoot at the player at a given time, it will look as if the others are providing suppressive fire to protect the running agent, even though there is actually no coordinated plan. You can enhance the effect by playing clips at the appropriate times (e.g., "Cover me!").

This idea is not my own, but something I read years ago. Unfortunately, I don't remember where I read it.

#5169207 My struggles need some insight!

Posted by Álvaro on 25 July 2014 - 06:14 PM

[Disclaimer: I don't have any experience making anything like an RPG game.]

I would think the Map would know what the level looks like, the Characters would know where they are, and ideally the player would be just another Character, although I can see the case for treating it very differently. The Characters would know where they are (as in they have a member of type Point saying where they are). The Scene would be the object that knows about what Map we are playing on and what Characters exist in the game world.

I don't think there are any circular dependencies in that general way of structuring the code: Map and Character both use Points and the Scene has the Map and the Characters.

More generally, I usually structure my code so modules are users of lower-level modules and are used by higher-level modules. It's not always easy to structure things that way, but I usually find a way.

#5168806 some stuff about robots

Posted by Álvaro on 23 July 2014 - 11:27 PM

When the new reputation system was established, I complained about giving points for idiotic things, like logging in. So here's a perfect example of the undesirable consequences of that: rouncer's profile reports a reputation score of "356 Good". If this individual deserves a "Good" score, who doesn't? What is the score supposed to be used for?

[The thread is worthless, so I don't feel bad using it for something else. Well, a little bad because what I am talking about has nothing to do with AI.]

#5168745 How are the trigonometric functions computed?

Posted by Álvaro on 23 July 2014 - 04:32 PM

Another interesting approach is CORDIC.

#5168324 Is c++ good

Posted by Álvaro on 22 July 2014 - 01:36 AM

C on the other hand has no nice parts, basic input/output drops you straight in the deep end of the pool and thats probably not the best place to put someone who hasn't learned how to swim yet.

Basic input/output is a hard thing to get right in most languages. In C it looks hard. In other languages it might look easier. But then you end up with SQL-injection and cross-site-scripting vulnerabilities all over the place.

I tell beginners to not even try to do robust input/output for a while, because it's just too hard. And this advice is not only for C.

#5167922 C++ smart pointer usage

Posted by Álvaro on 20 July 2014 - 12:14 AM

I didn't look at your code, but it sounds like your objects don't have the right semantics to be copied or moved around.

EDIT: This looks very suspicious:
Object::Object(const Object& orig) {
How is that copy constructor supposed to make a copy of anything?

#5167921 Looking for anyone that can share knowledge

Posted by Álvaro on 20 July 2014 - 12:08 AM

We can collectively mentor you if you post here some specific questions. Is there anything in particular you are having trouble with? Ideally you would post a piece of code, tell us what you were expecting it would do and what it does instead... You'll find that people here are generally very helpful.

#5167529 C++ smart pointer usage

Posted by Álvaro on 18 July 2014 - 12:47 AM

You don't need `new'. Just use emplace_back to create new objects at the end of the vector. You can do that with as many instances as you want.

#5167524 C++ smart pointer usage

Posted by Álvaro on 17 July 2014 - 11:44 PM

I didn't follow the other thread, but I don't see why you need to use unique_ptr at all. It would make sense if Planet were an abstract class and you had several different implementations, but nothing derives from Planet. So you could just use a vector of Planet and that way you don't need pointers at all.

I don't think `move' means what you think it means. If the point is that you are not going to be using the old value of alteredVector anymore, you should probably make your function's prototype be `void Function1(std::vector<std::unique_ptr<Object>> &alteredVector)'.

Your code has a few other stinks, like this one:
std::vector<std::unique_ptr<Planet>> planetAndStarsVector;
If the type is that of a vector of planets, why does the name contain `AndStars'? That's either wrong (likely) or at the very least requires a comment.

#5167387 What's the next step after LZ77?

Posted by Álvaro on 17 July 2014 - 06:51 AM

Compression only works because there is structure in the input. A general compression scheme has to exploit things like the presence of repetition, which is common in many formats. If you look carefully at what the input actually is, you might be able to come up with a much better compression scheme.

So I'll try to ask a different way: Can you show us some examples of what your files contain?

#5167370 What's the next step after LZ77?

Posted by Álvaro on 17 July 2014 - 05:43 AM

What do your files typically contain?