#include "scr_Board.h"
#include "scr_Server.h"

//this isn't derived from anything yet, but a common base ancestor will give rise
//to the ability to create an scr_RemoteNetworkServer-one over a network- providing
//a seamless interface for local and network servers
class scr_LocalServer: public scr_Server{
private:
 scr_Board *TheBoard;
 scr_Bag *Bag;
 scr_Dictionary *Dict;
 scr_Player *ThePlayaz[10];
 int curplayer,quit,numplayers,totalplayers,guillotine;
 int BSIZE, TILENUM,BINGO;

 char* DeterminePlayedTiles(scr_Move* move);
 
 int RemoveTiles(char* remove, int exchange);

 void FillCurPlayerTiles(){
  char a;
  for(a=0;a<TILENUM;a++){
   if(ThePlayaz[curplayer]->GetTile(a)==0)
    ThePlayaz[curplayer]->SetTile(a,Bag->GetTile());
  }
 }

 void RequestCurPlayerDrop();

 char TranslateBoardLetter(char x, char y){
  if(TheBoard->Letter(x,y)){
   if(TheBoard->HasBlank(x,y)) return(TheBoard->Letter(x,y)+64);
   else return(TheBoard->Letter(x,y)+96);
  }
  else return(0);
 }
 
 void NextPlayer(){
  if(numplayers>1){
   do{
    if(curplayer==totalplayers-1) curplayer=0;
    else  curplayer++;
   }while (ThePlayaz[curplayer]==0);
  }
 }
 
 void RemoveCurPlayerTiles(char* remove){
 char a;
  for(a=0;a<TILENUM;a++)
   if(remove[a]) ThePlayaz[curplayer]->RemoveTile(a);
 }
 
public:
 scr_LocalServer();
 ~scr_LocalServer();

 //Functions called externally; interface functions
 void RunGame();

 void CreatePlayer(PLAYERTYPE type);
 
 int GetCurPlayerNum(){
  return curplayer;
 }

 int SubmitMove(scr_Move* move);

 int GetCurPlayerScore(){
  return ThePlayaz[curplayer]->GetScore();
 }

 void CopyCurPlayerTiles(char* outtiles){
  char a,b;
  for(a=0;a<TILENUM;a++){
   b=Bag->Translate(ThePlayaz[curplayer]->GetTile(a));
   switch(b){
    case 0 :{
     outtiles[a]='_';
     break;
    }
    case 64 :{
     outtiles[a]='*';
     break;
    }
    default :{
     outtiles[a]= b+96;
     break;
    }
   }
  }
 }

 void GetCopyOfBoard(char** representation);

 int HowManyInBag(){
  return(Bag->HowMany());
 }

 int BoardSize(){
  return(BSIZE);
 }

 int GetNumberTilesInRack(){
  return(TILENUM);
 }
 
};
