Please dont Ban me....

Started by
20 comments, last by sirGustav 17 years, 1 month ago
Quote:Original post by ToohrVyk
Quote:Original post by doctorsixstring
I doubt the Python code is any faster, but I think it is significantly easier to read and understand (no offense to pascalosti or ToohrVyk ).


I certaintly won't disagree with that! C++ is often a very bad idea for small-to-medium problems such as this one, and sometimes a bad idea for larger problems as well.

While we're at it:

*** Source Snippet Removed ***


Out of curiosity, what language is that? I don't recognise it at all. It looks like a functional language, at a guess...
[TheUnbeliever]
Advertisement
Quote:Original post by TheUnbeliever
Out of curiosity, what language is that? I don't recognise it at all. It looks like a functional language, at a guess...


Objective Caml.

Now all we need is a Java, C#, and Scheme version! Matter of fact...

Beginner in Game Development?  Read here. And read here.

 

I'm having trouble running the C++ code

It does not recognize
#include <pair> (or pair.h)
I can comment it out and it works fine until
I try
"works.setup_map()" function
then i get 25 errors

If I'm not mistaken

std::pair is defined in the header "utility." so #include <utility> should do the trick
Still get the same 25 errors,
here are some of the errors... (which are beyond me)


Error 2 error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Container', expected a real type


Error 3 error C2825: '_Container': must be a class or namespace when followed by '::'


Error 6 error C2602: 'std::priority_queue<_Ty,_Container,_Pr>::value_type' is not a member of a base class of 'std::priority_queue<_Ty,_Container,_Pr>'
std::priority_queue<pos,std::vector,comp> candidates;

What it's saying is that this std::vector is unspeciallised (as opposed to speciallised eg. std:vector<int>) The priority queue wants a vector of something.

Maybe ToohrVyk can fill you in. He did mention it was untested and full of errors.
Ok just checked docos because it compiled fine on VS05 turns out VS allows template template paramaters for the second template param but the standard doesnt :)

change
std::priority_queue<pos,std::vector,comp> candidates;
to
std::priority_queue<pos,std::vector<pos>,comp> candidates;
and it should work
took the liberty to read through the code, and found a few mistakes:
// in generate_borders()if (x == 0 || x == Width - 1 || y == 0 || y == Width - 1)// should beif (x == 0 || x == Width - 1 || y == 0 || y == Height - 1)// in compute_path()for(;;)// should imho be (for clarity)while(true)// or preferably (perhaps with some checks after the loop)while( !candidates.empy() ) // to avoid calling candidates.top(); when candidates is empty// in compute_path()if (next = pos(Width-2,Height-2)) break;//should probably beif (next == pos(Width-2,Height-2)) break;
All proposed corrections are necessary and justified. I should probably install a C++ compiler on this computer :) although I disagree with the for(;;) versus while (true) issue. An alternative would have been:

for(;;){  assert (!candidates.empty());  // .. code}

This topic is closed to new replies.

Advertisement