#ifndef SCR_BOARD_H

#include "scr_Bag.h"
#include "scr_Dictionary.h"
#include "scr_Move.h"

struct Cube
{
 unsigned long int flags[3];
 char wmult,smult,letter,hasblank;
 char adjacent,value[3];
 char hasneighbor;
};

class scr_Board
{
private:
 scr_Bag *Bag;
 scr_Dictionary *Dict;

 Cube ***Board;
 char BSIZE, xwide, ywide, zwide;
 Coordinate bdim;
 int nummoves;

public:
 scr_Board(char* filename, scr_Bag* BagIn, scr_Dictionary* DictIn);

 scr_Board(char xw, char yw, char zw);

 ~scr_Board(){
 char x,y;
  for(x=0;x<xwide;x++)
   for(y=0; y<ywide; y++) delete [] Board[x][y];
  for(x=0; x<xwide; x++) delete [] Board[x];
  delete [] Board;
 }

 char TranslateBoardLetter(char x, char y, char z){
  if(Letter(x, y, z)){
   if(HasBlank(x, y, z)) return(Letter(x, y, z)+64);
   else return(Letter(x, y, z)+96);
  }
  else return(0);
 }

 char GetXBoardSize()
 {
  return(xwide);
 }

 char GetYBoardSize()
 {
  return(ywide);
 }

 char GetZBoardSize()
 {
  return(zwide);
 }

 char FitLetter(char x, char y, char z, char direction, char letter);
 
 inline char Letter(char x, char y, char z)
 {
  return(Board[x][y][z].letter);
 }

 char WordMult(char x, char y, char z)
 {
  return(Board[x][y][z].wmult);
 }

 char LetterMult(char x, char y, char z)
 {
  return(Board[x][y][z].smult);
 }

 char Value(char x, char y, char z, char direction)
 {
  return(Board[x][y][z].value[direction]);
 }

 char HasBlank(char x, char y, char z)
 {
  return(Board[x][y][z].hasblank);
 }

 char HasNeighbor(char x, char y, char z, char direction)
 {
  return(Board[x][y][z].hasneighbor&(1<<direction));
 }

 inline unsigned long int Flags(char x, char y, char z, char direction)
 {
  return(Board[x][y][z].flags[direction]);
 }

 char Adjacent(char x, char y, char z){
  return Board[x][y][z].adjacent;
 }

 void SetWordMult(char x, char y, char z, char target)
 {
  Board[x][y][z].wmult = target;
 }

 void SetLetterMult(char x, char y, char z, char target)
 {
  Board[x][y][z].smult = target;
 }

 void SetHasNeighbor(char x, char y, char z, unsigned int target)
 {
  Board[x][y][z].hasneighbor |= target;
 }

 void SetAdjacent(char x, char y, char z, unsigned int target)
 {
  Board[x][y][z].adjacent |= target;
 }
 void SetFlags(char x, char y, char z, char direction, unsigned long int target)
 {
  Board[x][y][z].flags[direction]=target;
 }

 void Integrate(Coordinate coords, char direction, char* stringer);
 int Valid(Coordinate coords, char direction, char* stringer);
 int Score(Coordinate coords, char direction, char* stringer);
 int RawScore(Coordinate coords, char direction, char* input);
 int Stringify(char **buf);
 void GetCopyOfBoard(char*** representation);
};
#endif
