Strona 1 z 1

Rozwiązanie algorytmu A* w c++

: 01 gru 2010, 08:16
autor: saiqard
Pisał ktoś z Was program którego zadaniem jest stworzenie drogi wg algorytmu A* na jakiejś mapie? Bo mam parę problemów typu "początkujący programista ma banalny problem" i sam nie mogę sobie z nimi poradzić:(

Odp: Rozwiązanie algorytmu A* w c++

: 01 gru 2010, 10:28
autor: borzole

Odp: Rozwiązanie algorytmu A* w c++

: 01 gru 2010, 10:52
autor: saiqard
borzole pisze:problem komiwojażera?
Nie, nie. Zupełnie nie to:)
Tutaj chodzi bardziej o algorytm rozpatrujący dotarcie z punktu "A" do punktu "B". Czyli typowy GPS:)
Jeśli chodzi o sam algorytm to go znam i nie mam problemu z jego zrozumieniem.
Problemy mam jedynie w gestii wdrożenia tego w c++. Np. jak wrzucić obiekt klasy który sam stworzyłem na listę z biblioteki std?:)

Odp: Rozwiązanie algorytmu A* w c++

: 01 gru 2010, 12:41
autor: dawwin
saiqard pisze: Jeśli chodzi o sam algorytm to go znam i nie mam problemu z jego zrozumieniem.
Jeśli znasz też c++ to w czym problem? Może opisz dokładnie, czego nie wiesz
saiqard pisze: Np. jak wrzucić obiekt klasy który sam stworzyłem na listę z biblioteki std?:)

Kod: Zaznacz cały

list <twoja_klasa> nazwa;

Odp: Rozwiązanie algorytmu A* w c++

: 01 gru 2010, 13:20
autor: saiqard
Program piszę w Visual C++ 2007.
Napisałem klasę pixel która w pliku pixel.h zawiera:

Kod: Zaznacz cały

#pragma once

ref class pixel
{
public:
	pixel(void); 
	 int x;
	 int y;
	 int f;
	 int g;
	 int h;

	 int getx(void);
	 int gety(void);
	 int getf(void);
	 int getg(void);
	 int geth(void);
	 void setx(int a);
	 void sety(int a);
	 void setf(int a);
	 void setg(int a);
	 void seth(int a);
};
Natomiast w pliku pixel.cpp:

Kod: Zaznacz cały

#include "StdAfx.h"
#include "pixel.h"

pixel::pixel(void)
{
	x=0;y=0;f=0;g=0;h=0;
}


int pixel::getx() {
	return x;
}

int pixel::gety() {
	return y;
}

int pixel::getf() {
	return f;
}

int pixel::getg() {
	return g;
}

int pixel::geth() {
	return h;
}

void pixel::setx(int a) {
	x=a;
}

void pixel::sety(int a) {
	y=a;
}

void pixel::setf(int a) {
	f=a;
}

void pixel::setg(int a) {
	g=a;
}

void pixel::seth(int a) {
	h=a;
}
I teraz chcę oprogramować przycisk, który będzie korzystał z tej klasy - narazie zadeklarowanie zmiennej typu nowa klasa, ustawienie w niej wartości y (to działa, ale nie jestem pewien cyz dobrze zadeklarowałem zmienną) a następnie utworzenie listy obiektów pixel (tu się sypie):

Kod: Zaznacz cały

pixel^ aaa = gcnew pixel();
			aaa->sety(22);
			
			list <pixel> lista_otwarta;
Błędy jakie wychodzą to:

Kod: Zaznacz cały

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory(95) : error C3699: '*' : cannot use this indirection on type 'pixel'
        compiler replacing '*' with '^' to continue parsing
        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(50) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
        with
        [
            _Ty=pixel
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(59) : see reference to class template instantiation 'std::_List_nod<_Ty,_Alloc>' being compiled
        with
        [
            _Ty=pixel,
            _Alloc=std::allocator<pixel>
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(79) : see reference to class template instantiation 'std::_List_ptr<_Ty,_Alloc>' being compiled
        with
        [
            _Ty=pixel,
            _Alloc=std::allocator<pixel>
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(96) : see reference to class template instantiation 'std::_List_val<_Ty,_Alloc>' being compiled
        with
        [
            _Ty=pixel,
            _Alloc=std::allocator<pixel>
        ]
        c:\users\saiqard\documents\visual studio 2008\projects\grafika\grafika\Form1.h(476) : see reference to class template instantiation 'std::list<_Ty>' being compiled
        with
        [
            _Ty=pixel
        ]
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory(96) : error C3699: '&' : cannot use this indirection on type 'pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory(97) : error C3699: '*' : cannot use this indirection on type 'const pixel'
        compiler replacing '*' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory(98) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xmemory(153) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(452) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(458) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(509) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(658) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(668) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(697) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(702) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(709) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(724) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(926) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(1163) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(1189) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\list(1221) : error C3699: '&' : cannot use this indirection on type 'const pixel'
        compiler replacing '&' with '^' to continue parsing
Co zrobiłem źle?