#ifndef STATE_C
#define STATE_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "State.h"
 
State::State (int *vector, int size, int idx, int score, int myMax)
{
   _vector = (int*) calloc(size, sizeof *_vector);
   memcpy(_vector, vector, size * sizeof *vector);
   _size  = size;
   _idx   = idx;
   _score = score;
   _myMax = myMax;
}

State::~State()  {  free(_vector);  }

   // Reversed to get a max-priority-queue
int State::compare(State *rt)
{  return rt->_score - this->_score;  }

char* State::toString()
{  static char work[256]="tmp", patch[64]="tst";
   char *rtnStr;

   sprintf(work, "max possible %d at [%d]:", _myMax, _idx);
   for (int k = 0; k < _size; k++)
   {  sprintf(patch, "%3d", _vector[k]);
      strcat(work, patch);
   }
   rtnStr = (char*) calloc(1+strlen(work), sizeof work);
   strncpy (rtnStr, work, strlen(work)+1);
   return rtnStr;
}
#endif
