Skip to content

Instantly share code, notes, and snippets.

@guilherme
Created April 4, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilherme/2303704 to your computer and use it in GitHub Desktop.
Save guilherme/2303704 to your computer and use it in GitHub Desktop.
// Table.h
class Table {
private:
int h;
int g;
std::vector< std::vector<int> > pecas;
int _delta_l_c(int l_ini, int c_ini, int l_fim, int c_fim);
Table* parent;
public:
Table* getParent();
inline void setParent(Table* parent) { this->parent = parent; };
inline int getPeca(int l, int c) { return pecas[l][c]; };
inline void setPeca(int l, int c, int value) { pecas[l][c] = value; };
inline int _f() { return (this->g + this->h); };
std::priority_queue<Table *, std::vector<Table*>, CompareTable>* neighbors();
void _g(Table* _tab_final);
void _h(Table* _tab_final);
inline int getG() { return this->g; }
inline int getH() { return this->h; }
Table(Table* t);
Table(int p[3][3]);
Table();
~Table();
};
//Table .cpp
Table* Table::getParent() {
return this->parent;
};
//main.cpp
#include "Table.h"
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int pecas_inicial[3][3] = { { 2,8,3 },{ 1,6,4 }, { 7,0,5 } };
int pecas_final[3][3] = { { 1,2,3 }, { 8,0,4 }, { 7,6,5 } };
Table *_tab_inicial = new Table(pecas_inicial);
Table *_tab_final = new Table(pecas_final);
_tab_inicial->_g(_tab_final);
_tab_inicial->_h(_tab_final);
std::priority_queue<Table*, std::vector<Table*>, CompareTable> open_list;
std::priority_queue<Table*, std::vector<Table*>, CompareTable> closed_list;
std::priority_queue<Table*, std::vector<Table*>, CompareTable> _return;
open_list.push(_tab_inicial);
Table *_current_tab;
cout << "Table Size " << open_list.size() << endl;
_current_tab = _tab_inicial->getParent();
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment