Rozwiązanie algorytmu A* w c++

Bash, C, C++, Java, PHP, Ruby, GTK, Qt i wiele innych - wszystko tutaj.
saiqard
Sędziwy Jeż
Sędziwy Jeż
Posty: 52
Rejestracja: 03 lip 2008, 20:42
Płeć: Mężczyzna
Wersja Ubuntu: 10.04
Środowisko graficzne: GNOME
Architektura: x86_64

Rozwiązanie algorytmu A* w c++

Post 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ć:(
Awatar użytkownika
borzole
Serdeczny Borsuk
Serdeczny Borsuk
Posty: 127
Rejestracja: 10 sie 2010, 11:48
Płeć: Mężczyzna
Wersja Ubuntu: inny OS
Środowisko graficzne: GNOME
Architektura: x86_64
Kontakt:

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

Post autor: borzole »

saiqard
Sędziwy Jeż
Sędziwy Jeż
Posty: 52
Rejestracja: 03 lip 2008, 20:42
Płeć: Mężczyzna
Wersja Ubuntu: 10.04
Środowisko graficzne: GNOME
Architektura: x86_64

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

Post 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?:)
Awatar użytkownika
dawwin
Serdeczny Borsuk
Serdeczny Borsuk
Posty: 202
Rejestracja: 18 kwie 2009, 09:16
Płeć: Mężczyzna
Wersja Ubuntu: 11.04
Środowisko graficzne: GNOME
Architektura: x86
Kontakt:

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

Post 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;
Moje programy - http://dawwin.users.sourceforge.net/
Nie pomagam na PW
saiqard
Sędziwy Jeż
Sędziwy Jeż
Posty: 52
Rejestracja: 03 lip 2008, 20:42
Płeć: Mężczyzna
Wersja Ubuntu: 10.04
Środowisko graficzne: GNOME
Architektura: x86_64

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

Post 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?
ODPOWIEDZ

Wróć do „Programowanie”

Kto jest online

Użytkownicy przeglądający to forum: Obecnie na forum nie ma żadnego zarejestrowanego użytkownika i 9 gości