Library tutorials & articles

AI 1 - Problem Solving (Artificial intelligence)

Final bit of code

OKAY, the main cpp file, “EightPuzz.cpp”

Here’s the code that kicks the thing off ! Its very simple.

#include"Eightpuzz.h"

int main() {

   char Choice=0;

   cout << "Choose Search Method...\n"
        << "    [1] Blind Breadth First Search\n"
        << "    [2] Blind Depth First Search\n"
        << "    [3] A*(Tiles in the wrong position)\n"
        << "    [4] A*(Manhattan Distance)\n" << endl;
       
   cin >> Choice;

   switch(Choice) {

   case '1':
       // call Blind Breadth First Search
       GeneralSearch(BREADTH_FIRST, NOT_USED);
       break;
   case '2':
       // call Blind Depth First Search
       GeneralSearch(DEPTH_FIRST, NOT_USED);
       break;
   case '3':
       // call A* with wrong tiles heuristic
       GeneralSearch(DEPTH_FIRST, WRONG_TILES);
       break;
   case '4':
       // call A* with manhatten heuristic
       GeneralSearch(DEPTH_FIRST, MANHATTAN_DISTANCE);
       break;
   }

   return 0;

}

Comments

  1. 27 Jul 2005 at 20:11

    i need help with an error im recieving.


    i have a template linked list class


    template <class LT>
    class LList
    {
    private:
     class LNode
       {
       public:
         LNode ();
         LT data;
         LNode * next;
       };


    public:
     LList();
     LList( const LList & other);
     ~LList ();
     LList & operator = (const LList & other);
     bool operator == (const LList & other);
     int Size() const;
     friend ostream & operator << <> (ostream & outs, const LList<LT> & L);
     bool InsertFirst (const LT & value);
     bool InsertLast (const LT & value);
     bool DeleteFirst ();
     bool DeleteLast ();
    private:
     LNode * first;
     int size;
    };


    and the friend function is giving me an error:


    template <class LT>
    ostream & operator << (ostream & outs, const LList<LT> & L)
    {
     if (L.first == NULL)
       return outs;


     outs << L.first -> data;


     for (LList<LT>::LNode * n = L.first -> next; n != NULL; n = n -> next)
      {
        outs << ' ' << n -> data;
      }
     return outs;
    }


    i get an error at the for loop... the error is :


    LLIST.tmp: In function std:<img src="images/smilies/redface.gif" width=15>stream& operator&lt;&lt;(std:<img src="images/smilies/redface.gif" width=15>stream&, const LList&lt;LT&gt;&)': <br> LLIST.tmp:111: error: n' undeclared (first use this function)
    LLIST.tmp:111: error: (Each undeclared identifier is reported only once for each function it appears in.)
    LLIST.tmp:33: error: LList&lt;int&gt;::LNode*LList&lt;int&gt;::first' is private <br> LLIST.tmp:106: error: within this context <br> LLIST.tmp:33: error: LList<int>::LNode*LList<int>::first' is private
    LLIST.tmp:109: error: within this context
    application.cpp:19:   instantiated from here
    LLIST.tmp:33: error: LList&lt;int&gt;::LNode*LList&lt;int&gt;::first' is private <br> LLIST.tmp:111: error: within this context <br> LLIST.tmp:111: error: dependent-name LList<LT>::LNode' is parsed as a non-type, but instantiation yields a type
    LLIST.tmp:111: note: say `typename  LList<LT>::LNode' if a type is meant


    i know these all have to do with friend and being private, what do i do?!?!

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of AI 1 - Problem Solving (Artificial intelligence).

Leave a comment

Sign in or Join us (it's free).

Chris Stones

Want to stay in touch with what's going on? Follow us on twitter!