#include <iostream>

#include "Lime.h"
#include "data.h"
#include "prototypes.h"

#define m "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1"
//6k1/7p/4p3/2r5/P3p3/8/2r1B1PP/R2K4 b - - 0 32

using namespace std;

s_Move newmove;

/*
I haven't commented this file at all - whenever I need a debug function,
I write it in here. Otherwise, these functions play no part in the program
*/

int plyok()
{
    if(histply >= 1024)  return TRUE;
    if(p->side < 0) return TRUE;
    if(p->side > 1) return TRUE;
    if(p->ply > 31) return TRUE;

    return FALSE;
}

int moveok(int move)
{
    int from = FROM(move);
    int to = TO(move);
    if(from > 144) return FALSE;
    if(to > 144) return FALSE;
    if(from <0 ) return FALSE;
    if(to <0 )  return FALSE;

    return TRUE;
}
//6rk/5pbp/3p2b1/4p3/8/2P5/PP3PPP/R4RK1 b - - 1 22
string test[2] = {
"6k1/4b3/p3p1r1/2p2pp1/2P2B2/PP6/8/1K4R1 b - - 0 43 ",
"r5k1/6bp/p3p3/3pp3/8/5P2/PPr1BKPP/RR6 b - - 0 1"
};

//this a q explosion test position
string qexp[1] = {
"1B1Q2K1/q1p4P/4P3/3Pk1p1/1r1NrR1b/4pn1P/1pRp2n1/1B2N2b w - - 0 1"
};


string positional[20] = {
"1qr3k1/p2nbppp/bp2p3/3p4/3P4/1P2PNP1/P2Q1PBP/1N2R1K1 b - - 0 1",
"1r2r1k1/3bnppp/p2q4/2RPp3/4P3/6P1/2Q1NPBP/2R3K1 w - - 0 1",
"2b1k2r/2p2ppp/1qp4n/7B/1p2P3/5Q2/PPPr2PP/R2N1R1K b k - 0 1",
"2b5/1p4k1/p2R2P1/4Np2/1P3Pp1/1r6/5K2/8 w - - 0 1",
"2brr1k1/ppq2ppp/2pb1n2/8/3NP3/2P2P2/P1Q2BPP/1R1R1BK1 w - - 0 1",
"2kr2nr/1pp3pp/p1pb4/4p2b/4P1P1/5N1P/PPPN1P2/R1B1R1K1 b - - 0 1",
"2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qkbnr/pp2pppp/3p4/2p5/4P3/3B1N2/PPPP1PPP/RNBQK2R w KQkq - 0 1",
"rnbqk2r/pppp1ppp/3b1n2/4p3/2P5/3P4/PP2PPPP/RNBQKBNR b KQkq - 0 1",
"r1r1r1k1/3n1ppp/pq4n1/2Pp4/1P6/P2BpN1P/6PB/R5K1 w - b3 0 16",
"r5k1/6pb/p2bPn1p/1p6/2pP4/PQ4N1/3N1PPP/R1R1R1K1 b - b6 0 1",
"rn1q1rk1/4ppbp/5npP/2p2PP1/pp1P4/1QN1Pb2/PPPBB3/2KR1R2 w - - 0 1",
"2kr1r2/pppbb3/1qn1pB2/PP1p4/2P2pp1/5NPp/4PPBP/RN1Q1RK1 b - - 0 1",
"1kr1q1nr/pbpp4/Ppn5/1PP2p2/4P1pp/2bP1NQ1/3BBPPP/2R1R1K1 w - - 0 1",
"2r1r1k1/3bbppp/2Bp1nq1/4p1PP/1pp2P2/pPN5/PBPP4/1KR1Q1NR b - - 0 1"
};



void printboard()
{
     for (int r = 7; r >= 0; r--)
     {
         cout<<"\n";;
         for (int f = 0; f < 8; ++f)
         {
             if (p->board[fileranktosquare(f, r)].typ != ety)
             {
              cout<<setw(3)<<piecetochar[p->board[fileranktosquare(f, r)].typ];
             }
             else
             {
                 cout<<setw(3)<<".";
             }

         }
     }

     /**/
      cout<<"\n Castle Flags ";
      if(p->castleflags & 8) cout<<"K";
      if(p->castleflags & 4) cout<<"Q";
      if(p->castleflags & 2) cout<<"k";
      if(p->castleflags & 1) cout<<"q";
      cout<<"\n en_pas "<<returnsquare(p->en_pas);
      cout<<"\n hashkey "<<p->hashkey;
      cout<<"\n side = "<<colours[p->side];
      cout<<"\n majors = "<<p->majors;
      cout<<"\n ply = "<<p->ply;
      cout<<"\n wk = "<<returnsquare(p->k[white]);
      cout<<"\n bk = "<<returnsquare(p->k[black]);
      cout<<"\n white material = "<<p->material[white];
      cout<<" black material = "<<p->material[black];
      cout<<" (diff = "<<p->material[white]-p->material[black]<<")";
      cout<<"\n fifty = "<<p->fifty;
      cout<<"\n\n";
}


void debugatt()
{
     cout<<"\n white attackers...";
     for (int r = 7; r >= 0; r--)
     {
         cout<<"\n";;
         for (int f = 0; f < 8; ++f)
         {
             if (isattacked(fileranktosquare(f, r), white))
             {
              cout<<setw(3)<<"y";
             }
             else
             {
                 cout<<setw(3)<<".";
             }

         }
     }

     cout<<"\n\n black attackers...";
     for (int r = 7; r >= 0; r--)
     {
         cout<<"\n";;
         for (int f = 0; f < 8; ++f)
         {
             if (isattacked(fileranktosquare(f, r), black))
             {
              cout<<setw(3)<<"y";
             }
             else
             {
                 cout<<setw(3)<<".";
             }

         }
     }
}
     /**/
void printnums()
{
     cout<<endl;
     for (int r = 0; r < 144; r++)
     {
              if(r%12 == 0)
               cout<<endl;

       cout<<setw(4)<<p->board[r].typ;
     }

      cout<<"\n\n";

     for (int r = 0; r < 144; r++)
     {
              if(r%12 == 0)
               cout<<endl;

       cout<<setw(4)<<p->board[r].col;
     }

     for (int r = 0; r < 144; r++)
     {
              if(r%12 == 0)
               cout<<endl;

       cout<<setw(4)<<castlebits[r];
     }
      cout<<"\n\n";
}



void debugpiecelists()
{
      cout<<"\n\npiece lists..\n\n";

   /*  int sq;

     //old from the b&w lists, for the future

     for (sq = 0; sq < 144; ++sq)
     {
         if(p->board[sq].typ == edge) continue;
         cout<<setw(5);
         cout<<"sq "<<returnsquare(sq);
         cout<<setw(3);

         cout<<"  black piece num = "<<p->sqtopcenum[black][sq];
         cout<<setw(5);
         cout<<"  white piece num = "<<p->sqtopcenum[white][sq];
         cout<<endl;
     }

     for (sq = 0; sq <= p->pcenum[black]; ++sq)
     {
         cout<<setw(5);
        cout<<"piece "<<sq;
         cout<<setw(3);

         cout<<"  black, square = ";
         cout<<returnsquare(p->pcenumtosq[black][sq]);
         cout<<endl;
     }
     cout<<endl;
     for (sq = 0; sq <= p->pcenum[white]; ++sq)
     {
         cout<<setw(5);
         cout<<"piece "<<sq;
         cout<<setw(3);

         cout<<"  white, square = ";
         cout<<returnsquare(p->pcenumtosq[white][sq]);
         cout<<endl;
     }

     cout<<"\n\n";
     cout<<" black pieces = "<<p->pcenum[black];
     cout<<" white pieces = "<<p->pcenum[white];
     cout<<" \n\n ";*/

     cout<<"\n total pieces = "<<p->pcenum;
     for (int i = 0; i <= p->pcenum; ++i)
     {
         cout<<"\npiece "<<i<<" square "<<returnsquare(p->pcenumtosq[i]);
     }
     cout<<endl<<endl;


}



void debugeval()
{

     /*
     set i and j for the number of loops
     */
     char position[256];
     int i = 0, j = 2;
     int vals[j];
     memset(vals, 0 , sizeof(vals));

    for (i = 0; i < j; ++i)
    {
     if(j == 2)
     {
      test[i].copy(position, 512);
     }
     else
     mirrorevaltestpositions[i].copy(position, 512);

     cout<<"\n"<<position;
     /*
     set up the position
     */
     setboard(position);
     if (j < 4)
     {
      printboard();
     }
     cout<<"\nEVAL....";
     int evali = gameeval();
     cout<<endl<<endl<<evali<<endl;
     cout<<endl<<"-------------------------------------------------";
     vals[i] = evali;
    }
    for (i=0; i < j; ++i)
    {
        if (i == 0 ) {continue;}
        if(i==1)
        {
            if(vals[i] != vals[i-1])
            {cout<<"\nEval error, position "<<i;}
            continue;
        }
        if(i%2 == 1)
        {
             if(vals[i] != vals[i-1])
            {cout<<"\nEval error, position "<<mirrorevaltestpositions[i-1];}
            continue;
        }
    }

}

void debugevalsee()
{

     char position[256];int i;


     evalsee[0].copy(position, 512);
     cout<<"\n"<<position;
     p->ply = 0;
     setboard(position);
     printboard();
     capgen();
     for(i = p->listc[p->ply]; i < p->listc[p->ply+1]; ++i)
	 {
        cout<<endl<<returnmove(p->list[i])<<" : ";
        /*if(see(p->list[i],p->side))
        cout<<"BAD SEE";
        else
        cout<<"GOOD SEE";*/
	 }

}

void debuginiteval()
{
    int i;
    cout<<"\nnum pawns ";
    cout<<" and pawn ranks : \n";
    for (i = 0; i < 10; ++i)
    {
		cout<<" wP file "<<i<<" num = "<<eval->pawns[white][i];
		cout<<" bP file "<<i<<" num = "<<eval->pawns[black][i];
		cout<<" white file "<<i<<" rank "<<eval->pawn_set[white][i];
		cout<<" black file "<<i<<" rank "<<eval->pawn_set[black][i];
		cout<<endl;
	}
	cout<<"\nwkingsq = "<<returnsquare(p->k[white]);
    cout<<" bkingsq = "<<returnsquare(p->k[black]);
    cout<<" wQc = "<<eval->wQc;
    cout<<" bQc = "<<eval->bQc;
    cout<<" wRc = "<<eval->wRc;
    cout<<" bRc = "<<eval->bRc;
    cout<<" wNc = "<<eval->wNc;
    cout<<" bNc = "<<eval->bNc;
    cout<<" wBc = "<<eval->wBc;
    cout<<" bBc = "<<eval->bBc;
    cout<<"\nwmajors = "<<eval->wmajors;
    cout<<" bmajors = "<<eval->bmajors;

}


void debugorder()
{
    char position[256];
    int i = 0, j = 0;
    int depth = 10;

    FILE *testfile;
    char *finddepth;
    char filename[64];
    char fileline[512];


    double start = 0, stop = 0;
    float fhfa[30], fha[30];
    float onodes = 0, nnodes = 0, qqnodes = 0;

    vector<double> mytime;

    /*cout<<"\nEnter filename..";
    cin>>filename;
    cout<<"\nEnter depth..";
    cin>>depth;*/

    testfile = fopen("positional_short.epd", "r");

    start = double(clock());

    while (fgets(fileline, 512, testfile))
    {
     setboard(fileline);
     //printboard();
     cout<<"\nposition "<<j;
     clearhash();
     p->ply = 0;
     initsearch();
     searchparam->inf = false;
     searchparam->depth = depth;
     searchparam->ucimode = 1;
     searchparam->starttime = double(clock());
     searchparam->stoptime = searchparam->starttime+12800000;
     calc();
     fhfa[i] = fhf;
     fha[i] = fh;
     clearhash();
     onodes += (qnodes+nodes);
     nnodes += nodes;
     qqnodes += qnodes;
     cout<<"\n bestmove : "<<returnmove(best);
     stop = double(clock());
     mytime.push_back(stop-searchparam->starttime);
     j++;
    }
    float total,us;
    float average = 0;

    for(i = 0; i < j; ++i)
    {
        cout<<"\nposition "<<i;
        cout<<",fhf,"<<fhfa[i]<<",fh,"<<fha[i]<<",";
        total = fha[i];us = fhfa[i];
        cout<<","<<((us/total)*100);
        cout<<",time,"<<(mytime[i]/1000)<<",";

    fprintf(log_file, "\n position %d time %f",i,(mytime[i]/1000));
    }
    //cout<<"\n\naverage = "<<(average/30);

    cout<<"\n total nodes,"<<onodes;
    cout<<",q nodes,"<<qqnodes;
    cout<<",normal nodes,"<<nnodes;
    cout<<",%qnodes,"<<(qqnodes/onodes)*100;
    cout<<",Total time,"<<((double(clock())-start)/1000);

    fprintf(log_file, "\n\n qnodes %f Total time %f",((qqnodes/onodes)*100),((double(clock())-start)/1000));

}


void debugprofile()
{
     setboard(m);
    // printboard();
     clearhash();
     p->ply = 0;
     initsearch();
     searchparam->inf = false;
     searchparam->depth = 32;
     searchparam->starttime = double(clock());
     cout<<"\nstart time is "<<searchparam->starttime;
     searchparam->stoptime = searchparam->starttime+60000;

     cout<<"\nstop time allocated is "<<searchparam->stoptime;
     calc();

     clearhash();


}


void debugnps()
{
    char position[256];
    int i;
    int anodes[30], aqnodes[30];


    for (i = 10; i < 20; ++i)
    {
     bt2630[i].copy(position, 512);
     cout<<"\n------------------Position "<<i+1<<" -------------------";
     cout<<"\n"<<position;

     setboard(position);
     //printboard();

     p->ply = 0;
     initsearch();
     searchparam->inf = false;
     searchparam->depth = 32;
     searchparam->starttime = double(clock());
     cout<<"\nstart time is "<<searchparam->starttime;
     searchparam->stoptime = searchparam->starttime+7000;

     cout<<"\nstop time allocated is "<<searchparam->stoptime;
     calc();
     anodes[i] = nodes;
     aqnodes[i] = qnodes;
     clearhash();
    }
    float total = 0,time = 70;

    for(i = 10; i < 20; ++i)
    {
        total += anodes[i]+aqnodes[i];
    }
    cout<<"\n\nnps = "<<(total/time)/1000;
    //cout<<"\nnodes = "<<total;
}






