int main(int argc, char* argv[])
{
	Parser P;
	Eval E;

	char input[1000];
	char current[1000];
	char alter[1000];


	Tree* dList=new Tree();

	cout<<"\n LISP INTERPRETER\n";
	cout<<"To terminate a particular input, please type EOF at the end\n";

	memset(input,0,1000);

	fgets(input, 1000, stdin);
	Interpreter I;

	// Read input till the last parenthesis.
	while(I.scanUntil(input)<0)
	{
		// memcpy and memset for faster performances.
		memcpy(current,input,1000);
		memset(alter,0,1000);
		memset(input,0,1000);

		fgets(alter, 1000, stdin);
		sprintf(input,"%s\n%s",current,alter);
	}

	// Convert to UpperCase Characters
	for(unsigned int i=0;i<strlen(input);i++){
		if (input[i] >= 'a' && input[i]<= 'z')
			input[i] = ('A' + input[i] - 'a');
	}
	Tree* T = P.parse(input,strlen(input));
	if(T==NULL)
	{
	}
	else
	{
		for (int i=0;i<T->getSize();i++)
		{
			SExp* aList = new SExp(0);
			SExp* Sin = T->get(i);
			E.def=0;
			SExp* Sout=E.eval(Sin,aList,dList);
			if(Sout!=NULL && E.def==0)
			{
				memset(alter,0,1000);
				Sout->convertStringList(alter);
				printf("%s\n",alter);
			}
		}
	}

	return 0;
}
예제 #2
0
void InHC4Revise::ibwd(const Function& f, const Domain& y, IntervalVector& x, const IntervalVector& xin) {

	Eval e;

	if (!xin.is_empty()) {
		e.eval(f,xin);

		assert(!f.expr().deco.d->is_empty());

		for (int i=0; i<f.nb_nodes(); i++)
			*f.node(i).deco.p = *f.node(i).deco.d;
	}
	else {
		for (int i=0; i<f.nb_nodes(); i++)
			f.node(i).deco.p->set_empty();
	}

	e.eval(f,x);

	assert(!f.expr().deco.d->is_empty());

	*f.expr().deco.d = y;

	try {

		f.backward<InHC4Revise>(*this);

		f.read_arg_domains(x);

	} catch(EmptyBoxException&) {
		x.set_empty();
	}
}
예제 #3
0
 void operator () (Eval &eval,StepId dep,Expr::Mul *ptr)
  {
   auto step=eval.createStep(MulStep(ret),dep);
   
   eval.createStep(ExprStep(ptr->arg1,step.obj.arg1),step.id);
   eval.createStep(ExprStep(ptr->arg2,step.obj.arg2),step.id);
  }
예제 #4
0
bool InHC4Revise::ibwd(const Function& f, const Domain& y, ExprLabel** x) {

	Eval e;

	// the box to be inflated is found
	// in the "p" field of the x labels:
	Array<Domain> argP(f.nb_arg());
	for (int i=0; i<f.nb_arg(); i++) {
		argP.set_ref(i,*x[i]->p);
	}

	if (!argP[0].is_empty()) { // if the first domain is empty, so they all are
		e.eval(f,argP);

		assert(!f.expr().deco.d->is_empty());

		for (int i=0; i<f.nb_nodes(); i++)
			*f.node(i).deco.p = *f.node(i).deco.d;
	}
	else {
		for (int i=0; i<f.nb_nodes(); i++)
			f.node(i).deco.p->set_empty();
	}

	e.eval(f,x);

	assert(!f.expr().deco.d->is_empty());

	*f.expr().deco.d = y;

	Array<Domain> argD(f.nb_arg());

	for (int i=0; i<f.nb_arg(); i++) {
		argD.set_ref(i,*(x[i]->d));
	}

	try {

		f.backward<InHC4Revise>(*this);

		f.read_arg_domains(argD);

	} catch(EmptyBoxException&) {
		// should we force argD to be the empty set here?
		// (probably no, as long as this function is called
		// inside InHC4Revise)
		return false;
	}

	return true;
}
예제 #5
0
void InHC4Revise::iproj(const Function& f, const Domain& y, IntervalVector& x, const IntervalVector& xin) {

	Eval e;

	if (!xin.is_empty()) {
		e.eval(f,xin);
		for (int i=0; i<f.nb_nodes(); i++)
			*f.node(i).deco.p = *f.node(i).deco.d;
	}
	else {
		for (int i=0; i<f.nb_nodes(); i++)
			f.node(i).deco.p->set_empty();
	}

	e.eval(f,x);

	*f.expr().deco.d = y;

	try {

		f.backward<InHC4Revise>(*this);

		if (f.all_args_scalar()) {
			int j;
			for (int i=0; i<f.nb_used_vars; i++) {
				j=f.used_var[i];
				x[j]=f.arg_domains[j].i();
			}
		}
		else
			load(x,f.arg_domains,f.nb_used_vars,f.used_var);

	} catch(EmptyBoxException&) {
		x.set_empty();
	}
}
예제 #6
0
  void operator () (Eval &eval,StepId dep,Expr::Var *ptr)
   {
    ulen index=ptr->index;
    Var &var=eval->table[index];
    
#if 1      
    
    var.gate->createStep(GetVarStep(var.value,ret),dep);
    
#else
    
    auto step=eval.createStep(GetVarStep(var.value,ret),dep);
    
    var.gate->delay(step.id);
    
#endif      
   }
예제 #7
0
파일: pr58080.C 프로젝트: 0day-ci/gcc
int main()
{
  Eval<int,void*> eiv; eiv.foo(0,0);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  if (nrhs == 5 && nlhs == 1) {

    // create object
    Map<VectorXd> breaks(mxGetPr(prhs[0]), mxGetNumberOfElements(prhs[0]));
    Map<MatrixXd>      K(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1]));
    Map<MatrixXd>      A(mxGetPr(prhs[2]), mxGetM(prhs[2]), mxGetN(prhs[2]));
    Map<MatrixXd>  alpha(mxGetPr(prhs[3]), mxGetM(prhs[3]), mxGetN(prhs[3]));
    Map<MatrixXd>  gamma(mxGetPr(prhs[4]), mxGetM(prhs[4]), mxGetN(prhs[4]));

    Eval *eval = new Eval(breaks, K, A, alpha, gamma);
    mxClassID cid;
    if (sizeof(eval)==4) cid = mxUINT32_CLASS;
    else if (sizeof(eval)==8) cid = mxUINT64_CLASS;
    else mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:PointerSize","Are you on a 32-bit machine or 64-bit machine??");
    plhs[0] = mxCreateNumericMatrix(1,1,cid,mxREAL);
    memcpy(mxGetData(plhs[0]),&eval,sizeof(eval));
    
    //    mexPrintf("constructor\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow");

  } else {

    // retrieve object
    Eval *eval = NULL;
    if (nrhs==0 || !mxIsNumeric(prhs[0]) || mxGetNumberOfElements(prhs[0])!=1)
      mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:BadInputs","the first argument should be the mex_ptr");
    memcpy(&eval,mxGetData(prhs[0]),sizeof(eval));

    if (nrhs == 1) {
      //      mexPrintf("delete\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow");

      // delete object   
      if (eval)
	delete eval;

    } else {

      //      mexPrintf("eval\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow");

      // eval() function call
      if (nrhs != 2 || nlhs != 2) {
        mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:WrongNumberOfInputs","Usage obj = ExpPlusPPTmex(breaks,K,A,alpha,gamma) or [y,jj] = ExpPlusPPTmex(obj,t)");
      }

      Map<VectorXd> t(mxGetPr(prhs[1]), mxGetNumberOfElements(prhs[1]));

      int m = static_cast<int>(t.rows());
      int d = eval->dim();

      plhs[0] = mxCreateDoubleMatrix(d,m,mxREAL);
      Map<MatrixXd> y(mxGetPr(plhs[0]),d,m);
      plhs[1] = mxCreateDoubleMatrix(m,1,mxREAL);
      Map<MatrixXd> jj(mxGetPr(plhs[1]),m,1);

      eval->compute(t, y, jj);

    }

  }

}
예제 #9
0
파일: eval.t.cpp 프로젝트: JensErat/task
int main (int argc, char** argv)
{
  UnitTest t (52);

  // Test the source independently.
  Variant v;
  t.notok (get ("-", v),                   "true <-- get(-)");

  t.ok (get ("x", v),                      "true <-- get(x)");
  t.is (v.type (), Variant::type_boolean,  "get(x) --> boolean");
  t.is (v.get_bool (), true,               "get(x) --> true");

  Eval e;
  e.addSource (get);
  Variant result;
  e.evaluatePostfixExpression ("x", result);
  t.is (result.type (), Variant::type_boolean, "postfix 'x' --> boolean");
  t.is (result.get_bool (), true,              "postfix 'x' --> true");

  e.evaluatePostfixExpression ("pi", result);
  t.is (result.type (), Variant::type_real,    "postfix 'pi' --> real");
  t.is (result.get_real (), 3.141592, 0.00001, "postfix 'pi' --> 3.14159265");

  e.evaluatePostfixExpression ("foo", result);
  t.is (result.type (), Variant::type_string,  "postfix 'foo' --> string");
  t.is (result.get_string (), "foo",           "postfix 'foo' --> 'foo'");

  // Simple infix arithmetic.
  e.evaluateInfixExpression ("1+2", result);
  t.is (result.type (), Variant::type_integer, "infix '1 + 2' --> integer");
  t.is (result.get_integer (), 3,              "infix '1 + 2' --> 3");

  // Simple postfix arithmetic.
  e.evaluatePostfixExpression ("1 2 +", result);
  t.is (result.type (), Variant::type_integer, "postfix '1 2 +' --> integer");
  t.is (result.get_integer (), 3,              "postfix '1 2 +' --> 3");

  e.evaluatePostfixExpression ("1 2 -", result);
  t.is (result.type (), Variant::type_integer, "postfix '1 2 -' --> integer");
  t.is (result.get_integer (), -1,             "postfix '1 2 -' --> -1");

  e.evaluatePostfixExpression ("2 3 *", result);
  t.is (result.type (), Variant::type_integer, "postfix '2 3 *' --> integer");
  t.is (result.get_integer (), 6,              "postfix '2 3 *' --> 6");

  e.evaluatePostfixExpression ("5 2 /", result);
  t.is (result.type (), Variant::type_integer, "postfix '5 2 /' --> integer");
  t.is (result.get_integer (), 2,              "postfix '5 2 /' --> 2");

  e.evaluatePostfixExpression ("5 2 /", result);
  t.is (result.type (), Variant::type_integer, "postfix '5 2 *' --> integer");
  t.is (result.get_integer (), 2,              "postfix '5 2 *' --> 2");

  // Simple postfix unary operator.
  e.evaluatePostfixExpression ("0 !", result);
  t.is (result.type (), Variant::type_boolean, "postfix '0 !' --> boolean");
  t.is (result.get_bool (), true,              "postfix '0 !' --> true");

  e.evaluatePostfixExpression ("1 !", result);
  t.is (result.type (), Variant::type_boolean, "postfix '1 !' --> boolean");
  t.is (result.get_bool (), false,             "postfix '1 !' --> false");

  // Type promotion simple postfix arithmetic.
  e.evaluatePostfixExpression ("1 2.3 +", result);
  t.is (result.type (), Variant::type_real,    "postfix '1 2.3 +' --> real");
  t.is (result.get_real (), 3.3,               "postfix '1 2.3 +' --> 3.3");

  e.evaluatePostfixExpression ("5 2.0 /", result);
  t.is (result.type (), Variant::type_real,    "postfix '5 2.0 /' --> integer");
  t.is (result.get_real (), 2.5,               "postfix '5 2.0 /' --> 2.5");

  // Simple logic.
  e.evaluatePostfixExpression ("0 0 ||", result);
  t.is (result.type (), Variant::type_boolean, "postfix '0 0 ||' --> boolean");
  t.is (result.get_bool (), false,             "postfix '0 0 ||' --> false");

  e.evaluatePostfixExpression ("0 1 ||", result);
  t.is (result.type (), Variant::type_boolean, "postfix '0 1 ||' --> boolean");
  t.is (result.get_bool (), true,              "postfix '0 1 ||' --> true");

  e.evaluatePostfixExpression ("1 0 ||", result);
  t.is (result.type (), Variant::type_boolean, "postfix '1 0 ||' --> boolean");
  t.is (result.get_bool (), true,              "postfix '1 0 ||' --> true");

  e.evaluatePostfixExpression ("1 1 ||", result);
  t.is (result.type (), Variant::type_boolean, "postfix '1 1 ||' --> boolean");
  t.is (result.get_bool (), true,              "postfix '1 1 ||' --> true");

  e.evaluateInfixExpression ("2*3+1", result);
  t.is (result.type (), Variant::type_integer, "infix '2*3+1' --> integer");
  t.is (result.get_integer (), 7,              "infix '2*3+1' --> 7");

  // TW-1254 - Unary minus support.
  e.evaluateInfixExpression ("2--3", result);
  t.is (result.type (), Variant::type_integer, "infix '2--3' --> integer");
  t.is (result.get_integer (), 5,              "infix '2--3' --> 5");

  //e.debug ();
  e.evaluateInfixExpression ("!false", result);
  t.is (result.type (), Variant::type_boolean, "infix '!false' --> boolean");
  t.is (result.get_bool (), true,              "infix '!false' --> true");

  e.evaluateInfixExpression ("!true", result);
  t.is (result.type (), Variant::type_boolean, "infix '!true' --> boolean");
  t.is (result.get_bool (), false,             "infix '!true' --> false");

  // _neg_
  e.evaluateInfixExpression ("- 1", result);
  t.is (result.type (), Variant::type_integer, "infix '- 1' --> integer");
  t.is (result.get_integer (), -1,             "infix '- 1' --> -1");

  e.evaluateInfixExpression ("- 1.2", result);
  t.is (result.type (), Variant::type_real,    "infix '- 1.2' --> real");
  t.is (result.get_real (), -1.2,              "infix '- 1.2' --> -1.2");

  e.evaluateInfixExpression ("- 2days", result);
  t.is (result.type (), Variant::type_duration, "infix '- 2days' --> duration");
  t.is (result.get_duration (), -86400*2,      "infix '- 2days' --> -86400 * 2");

  return 0;
}
예제 #10
0
파일: main.cpp 프로젝트: petergar/madlenka
int main(int argc, char** argv) {
    cout << "argc=" << argc << endl;
    for (int i=0; i < argc; i++)
        cout << "argv[" << i << "]=" << argv[i] << endl;
    cout << endl;

    /*
    cout << "--------------------------------------------" << endl;
    cout << "--                                        --" << endl;
    cout << "--   Welcome to Magdalena - v 0.1 alpha   --" << endl;
    cout << "--   Chess-Engine                         --" << endl;
    cout << "--                                        --" << endl;
    cout << "--   programmed by Peter Garscha          --" << endl;
    cout << "--   peter [at] rlsux [dot] com           --" << endl;
    cout << "--                                        --" << endl;
    cout << "--------------------------------------------" << endl << endl;
       */
    Position *myPosition = new Position();
    Perft *perft = new Perft();
    Eval *eval = new Eval();
    hashTable = new HashT(pow(2,25)); // 24
    
    pFile = fopen ("/home/peter/magdalena-log.txt","a");
    if (pFile==NULL)
        cout << "can't write to log file" << endl;
    
    char input[256];
    string check;
    
    bool loop=true;
    while (loop) {
        check.clear();
        // cout << "cmd> ";
        cin.getline(input,256);
        check.append(input);
        
        string logStr=check;
        log(logStr);
        
        if (check=="uci") {
            cout << "id name Magdalena\n";
            cout << "id author Peter Garscha\n";
            
            // send option-commands
            
            cout << "uciok\n";
        }
        
        else if (check.size()==0) {}
        
        else if (check=="isready")
            cout << "readyok\n";
        
        
        else if (check=="stop") {}
        
        else if (check=="debug on")
            cout << "debugging on now" << endl;
        
        else if (check=="debug off")
            cout << "debugging off now" << endl;
        
        else if (check=="ucinewgame")
            cout << "ucinewgame ok" << endl;
        
        else if (check=="perft")
            perft->doPerft(*myPosition,5);

        else if (check=="perft all") {
            Position *perftPos = new Position();
            perft->doPerft(*perftPos,4);

            perftPos = new Position("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -");
            perft->doPerft(*perftPos,4);
            
            perftPos = new Position("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -");
            perft->doPerft(*perftPos,4);           
           
            perftPos = new Position("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1");
            perft->doPerft(*perftPos,4);              
            
            perftPos = new Position("r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 1");
            perft->doPerft(*perftPos,4);              
        }
        
        else if (check=="perft list") {
            
            string fenlist[][7]={   
                {"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1","20","400","8902","197281","4865609","119060324"},
                {"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1","48","2039","97862","4085603","193690690","8031647685"},
                {"4k3/8/8/8/8/8/8/4K2R w K - 0 1","15","66","1197","7059","133987","764643"},
                {"4k3/8/8/8/8/8/8/R3K3 w Q - 0 1","16","71","1287","7626","145232","846648"},
                {"4k2r/8/8/8/8/8/8/4K3 w k - 0 1","5","75","459","8290","47635","899442"},
                {"r3k3/8/8/8/8/8/8/4K3 w q - 0 1","5","80","493","8897","52710","1001523"},
                {"4k3/8/8/8/8/8/8/R3K2R w KQ - 0 1","26","112","3189","17945","532933","2788982"},
                {"r3k2r/8/8/8/8/8/8/4K3 w kq - 0 1","5","130","782","22180","118882","3517770"},
                {"8/8/8/8/8/8/6k1/4K2R w K - 0 1","12","38","564","2219","37735","185867"},
                {"8/8/8/8/8/8/1k6/R3K3 w Q - 0 1","15","65","1018","4573","80619","413018"},
                {"4k2r/6K1/8/8/8/8/8/8 w k - 0 1","3","32","134","2073","10485","179869"},
                {"r3k3/1K6/8/8/8/8/8/8 w q - 0 1","4","49","243","3991","20780","367724"},
                {"r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1","26","568","13744","314346","7594526","179862938"},
                {"r3k2r/8/8/8/8/8/8/1R2K2R w Kkq - 0 1","25","567","14095","328965","8153719","195629489"},
                {"r3k2r/8/8/8/8/8/8/2R1K2R w Kkq - 0 1","25","548","13502","312835","7736373","184411439"},
                {"r3k2r/8/8/8/8/8/8/R3K1R1 w Qkq - 0 1","25","547","13579","316214","7878456","189224276"},
                {"1r2k2r/8/8/8/8/8/8/R3K2R w KQk - 0 1","26","583","14252","334705","8198901","198328929"},
                {"2r1k2r/8/8/8/8/8/8/R3K2R w KQk - 0 1","25","560","13592","317324","7710115","185959088"},
                {"r3k1r1/8/8/8/8/8/8/R3K2R w KQq - 0 1","25","560","13607","320792","7848606","190755813"},
                {"4k3/8/8/8/8/8/8/4K2R b K - 0 1","5","75","459","8290","47635","899442"},
                {"4k3/8/8/8/8/8/8/R3K3 b Q - 0 1","5","80","493","8897","52710","1001523"},
                {"4k2r/8/8/8/8/8/8/4K3 b k - 0 1","15","66","1197","7059","133987","764643"},
                {"r3k3/8/8/8/8/8/8/4K3 b q - 0 1","16","71","1287","7626","145232","846648"},
                {"4k3/8/8/8/8/8/8/R3K2R b KQ - 0 1","5","130","782","22180","118882","3517770"},
                {"r3k2r/8/8/8/8/8/8/4K3 b kq - 0 1","26","112","3189","17945","532933","2788982"},
                {"8/8/8/8/8/8/6k1/4K2R b K - 0 1","3","32","134","2073","10485","179869"},
                {"8/8/8/8/8/8/1k6/R3K3 b Q - 0 1","4","49","243","3991","20780","367724"},
                {"4k2r/6K1/8/8/8/8/8/8 b k - 0 1","12","38","564","2219","37735","185867"},
                {"r3k3/1K6/8/8/8/8/8/8 b q - 0 1","15","65","1018","4573","80619","413018"},
                {"r3k2r/8/8/8/8/8/8/R3K2R b KQkq - 0 1","26","568","13744","314346","7594526","179862938"},
                {"r3k2r/8/8/8/8/8/8/1R2K2R b Kkq - 0 1","26","583","14252","334705","8198901","198328929"},
                {"r3k2r/8/8/8/8/8/8/2R1K2R b Kkq - 0 1","25","560","13592","317324","7710115","185959088"},
                {"r3k2r/8/8/8/8/8/8/R3K1R1 b Qkq - 0 1","25","560","13607","320792","7848606","190755813"},
                {"1r2k2r/8/8/8/8/8/8/R3K2R b KQk - 0 1","25","567","14095","328965","8153719","195629489"},
                {"2r1k2r/8/8/8/8/8/8/R3K2R b KQk - 0 1","25","548","13502","312835","7736373","184411439"},
                {"r3k1r1/8/8/8/8/8/8/R3K2R b KQq - 0 1","25","547","13579","316214","7878456","189224276"},
                {"8/1n4N1/2k5/8/8/5K2/1N4n1/8 w - - 0 1","14","195","2760","38675","570726","8107539"},
                {"8/1k6/8/5N2/8/4n3/8/2K5 w - - 0 1","11","156","1636","20534","223507","2594412"},
                {"8/8/4k3/3Nn3/3nN3/4K3/8/8 w - - 0 1","19","289","4442","73584","1198299","19870403"},
                {"K7/8/2n5/1n6/8/8/8/k6N w - - 0 1","3","51","345","5301","38348","588695"},
                {"k7/8/2N5/1N6/8/8/8/K6n w - - 0 1","17","54","835","5910","92250","688780"},
                {"8/1n4N1/2k5/8/8/5K2/1N4n1/8 b - - 0 1","15","193","2816","40039","582642","8503277"},
                {"8/1k6/8/5N2/8/4n3/8/2K5 b - - 0 1","16","180","2290","24640","288141","3147566"},
                {"8/8/3K4/3Nn3/3nN3/4k3/8/8 b - - 0 1","4","68","1118","16199","281190","4405103"},
                {"K7/8/2n5/1n6/8/8/8/k6N b - - 0 1","17","54","835","5910","92250","688780"},
                {"k7/8/2N5/1N6/8/8/8/K6n b - - 0 1","3","51","345","5301","38348","588695"},
                {"B6b/8/8/8/2K5/4k3/8/b6B w - - 0 1","17","278","4607","76778","1320507","22823890"},
                {"8/8/1B6/7b/7k/8/2B1b3/7K w - - 0 1","21","316","5744","93338","1713368","28861171"},
                {"k7/B7/1B6/1B6/8/8/8/K6b w - - 0 1","21","144","3242","32955","787524","7881673"},
                {"K7/b7/1b6/1b6/8/8/8/k6B w - - 0 1","7","143","1416","31787","310862","7382896"},
                {"B6b/8/8/8/2K5/5k2/8/b6B b - - 0 1","6","106","1829","31151","530585","9250746"},
                {"8/8/1B6/7b/7k/8/2B1b3/7K b - - 0 1","17","309","5133","93603","1591064","29027891"},
                {"k7/B7/1B6/1B6/8/8/8/K6b b - - 0 1","7","143","1416","31787","310862","7382896"},
                {"K7/b7/1b6/1b6/8/8/8/k6B b - - 0 1","21","144","3242","32955","787524","7881673"},
                {"7k/RR6/8/8/8/8/rr6/7K w - - 0 1","19","275","5300","104342","2161211","44956585"},
                {"R6r/8/8/2K5/5k2/8/8/r6R w - - 0 1","36","1027","29215","771461","20506480","525169084"},
                {"7k/RR6/8/8/8/8/rr6/7K b - - 0 1","19","275","5300","104342","2161211","44956585"},
                {"R6r/8/8/2K5/5k2/8/8/r6R b - - 0 1","36","1027","29227","771368","20521342","524966748"},
                {"6kq/8/8/8/8/8/8/7K w - - 0 1","2","36","143","3637","14893","391507"},
                {"6KQ/8/8/8/8/8/8/7k b - - 0 1","2","36","143","3637","14893","391507"},
                {"K7/8/8/3Q4/4q3/8/8/7k w - - 0 1","6","35","495","8349","166741","3370175"},
                {"6qk/8/8/8/8/8/8/7K b - - 0 1","22","43","1015","4167","105749","419369"},
                {"6KQ/8/8/8/8/8/8/7k b - - 0 1","2","36","143","3637","14893","391507"},
                {"K7/8/8/3Q4/4q3/8/8/7k b - - 0 1","6","35","495","8349","166741","3370175"},
                {"8/8/8/8/8/K7/P7/k7 w - - 0 1","3","7","43","199","1347","6249"},
                {"8/8/8/8/8/7K/7P/7k w - - 0 1","3","7","43","199","1347","6249"},
                {"K7/p7/k7/8/8/8/8/8 w - - 0 1","1","3","12","80","342","2343"},
                {"7K/7p/7k/8/8/8/8/8 w - - 0 1","1","3","12","80","342","2343"},
                {"8/2k1p3/3pP3/3P2K1/8/8/8/8 w - - 0 1","7","35","210","1091","7028","34834"},
                {"8/8/8/8/8/K7/P7/k7 b - - 0 1","1","3","12","80","342","2343"},
                {"8/8/8/8/8/7K/7P/7k b - - 0 1","1","3","12","80","342","2343"},
                {"K7/p7/k7/8/8/8/8/8 b - - 0 1","3","7","43","199","1347","6249"},
                {"7K/7p/7k/8/8/8/8/8 b - - 0 1","3","7","43","199","1347","6249"},
                {"8/2k1p3/3pP3/3P2K1/8/8/8/8 b - - 0 1","5","35","182","1091","5408","34822"},
                {"8/8/8/8/8/4k3/4P3/4K3 w - - 0 1","2","8","44","282","1814","11848"},
                {"4k3/4p3/4K3/8/8/8/8/8 b - - 0 1","2","8","44","282","1814","11848"},
                {"8/8/7k/7p/7P/7K/8/8 w - - 0 1","3","9","57","360","1969","10724"},
                {"8/8/k7/p7/P7/K7/8/8 w - - 0 1","3","9","57","360","1969","10724"},
                {"8/8/3k4/3p4/3P4/3K4/8/8 w - - 0 1","5","25","180","1294","8296","53138"},
                {"8/3k4/3p4/8/3P4/3K4/8/8 w - - 0 1","8","61","483","3213","23599","157093"},
                {"8/8/3k4/3p4/8/3P4/3K4/8 w - - 0 1","8","61","411","3213","21637","158065"},
                {"k7/8/3p4/8/3P4/8/8/7K w - - 0 1","4","15","90","534","3450","20960"},
                {"8/8/7k/7p/7P/7K/8/8 b - - 0 1","3","9","57","360","1969","10724"},
                {"8/8/k7/p7/P7/K7/8/8 b - - 0 1","3","9","57","360","1969","10724"},
                {"8/8/3k4/3p4/3P4/3K4/8/8 b - - 0 1","5","25","180","1294","8296","53138"},
                {"8/3k4/3p4/8/3P4/3K4/8/8 b - - 0 1","8","61","411","3213","21637","158065"},
                {"8/8/3k4/3p4/8/3P4/3K4/8 b - - 0 1","8","61","483","3213","23599","157093"},
                {"k7/8/3p4/8/3P4/8/8/7K b - - 0 1","4","15","89","537","3309","21104"},
                {"7k/3p4/8/8/3P4/8/8/K7 w - - 0 1","4","19","117","720","4661","32191"},
                {"7k/8/8/3p4/8/8/3P4/K7 w - - 0 1","5","19","116","716","4786","30980"},
                {"k7/8/8/7p/6P1/8/8/K7 w - - 0 1","5","22","139","877","6112","41874"},
                {"k7/8/7p/8/8/6P1/8/K7 w - - 0 1","4","16","101","637","4354","29679"},
                {"k7/8/8/6p1/7P/8/8/K7 w - - 0 1","5","22","139","877","6112","41874"},
                {"k7/8/6p1/8/8/7P/8/K7 w - - 0 1","4","16","101","637","4354","29679"},
                {"k7/8/8/3p4/4p3/8/8/7K w - - 0 1","3","15","84","573","3013","22886"},
                {"k7/8/3p4/8/8/4P3/8/7K w - - 0 1","4","16","101","637","4271","28662"},
                {"7k/3p4/8/8/3P4/8/8/K7 b - - 0 1","5","19","117","720","5014","32167"},
                {"7k/8/8/3p4/8/8/3P4/K7 b - - 0 1","4","19","117","712","4658","30749"},
                {"k7/8/8/7p/6P1/8/8/K7 b - - 0 1","5","22","139","877","6112","41874"},
                {"k7/8/7p/8/8/6P1/8/K7 b - - 0 1","4","16","101","637","4354","29679"},
                {"k7/8/8/6p1/7P/8/8/K7 b - - 0 1","5","22","139","877","6112","41874"},
                {"k7/8/6p1/8/8/7P/8/K7 b - - 0 1","4","16","101","637","4354","29679"},
                {"k7/8/8/3p4/4p3/8/8/7K b - - 0 1","5","15","102","569","4337","22579"},
                {"k7/8/3p4/8/8/4P3/8/7K b - - 0 1","4","16","101","637","4271","28662"},
                {"7k/8/8/p7/1P6/8/8/7K w - - 0 1","5","22","139","877","6112","41874"},
                {"7k/8/p7/8/8/1P6/8/7K w - - 0 1","4","16","101","637","4354","29679"},
                {"7k/8/8/1p6/P7/8/8/7K w - - 0 1","5","22","139","877","6112","41874"},
                {"7k/8/1p6/8/8/P7/8/7K w - - 0 1","4","16","101","637","4354","29679"},
                {"k7/7p/8/8/8/8/6P1/K7 w - - 0 1","5","25","161","1035","7574","55338"},
                {"k7/6p1/8/8/8/8/7P/K7 w - - 0 1","5","25","161","1035","7574","55338"},
                {"3k4/3pp3/8/8/8/8/3PP3/3K4 w - - 0 1","7","49","378","2902","24122","199002"},
                {"7k/8/8/p7/1P6/8/8/7K b - - 0 1","5","22","139","877","6112","41874"},
                {"7k/8/p7/8/8/1P6/8/7K b - - 0 1","4","16","101","637","4354","29679"},
                {"7k/8/8/1p6/P7/8/8/7K b - - 0 1","5","22","139","877","6112","41874"},
                {"7k/8/1p6/8/8/P7/8/7K b - - 0 1","4","16","101","637","4354","29679"},
                {"k7/7p/8/8/8/8/6P1/K7 b - - 0 1","5","25","161","1035","7574","55338"},
                {"k7/6p1/8/8/8/8/7P/K7 b - - 0 1","5","25","161","1035","7574","55338"},
                {"3k4/3pp3/8/8/8/8/3PP3/3K4 b - - 0 1","7","49","378","2902","24122","199002"},
                {"8/Pk6/8/8/8/8/6Kp/8 w - - 0 1","11","97","887","8048","90606","1030499"},
                {"n1n5/1Pk5/8/8/8/8/5Kp1/5N1N w - - 0 1","24","421","7421","124608","2193768","37665329"},
                {"8/PPPk4/8/8/8/8/4Kppp/8 w - - 0 1","18","270","4699","79355","1533145","28859283"},
                {"n1n5/PPPk4/8/8/8/8/4Kppp/5N1N w - - 0 1","24","496","9483","182838","3605103","71179139"},
                {"8/Pk6/8/8/8/8/6Kp/8 b - - 0 1","11","97","887","8048","90606","1030499"},
                {"n1n5/1Pk5/8/8/8/8/5Kp1/5N1N b - - 0 1","24","421","7421","124608","2193768","37665329"},
                {"8/PPPk4/8/8/8/8/4Kppp/8 b - - 0 1","18","270","4699","79355","1533145","28859283"},
                {"n1n5/PPPk4/8/8/8/8/4Kppp/5N1N b - - 0 1","24","496","9483","182838","3605103","71179139"}
            };

            
            Position *perftPos;
            for (int i=0;i<126;i++) {
                cout << fenlist[i][0] << "          ";
                perftPos = new Position(fenlist[i][0]);
                
                long results[6]={       string2int(fenlist[i][1]),
                                        string2int(fenlist[i][2]),
                                        string2int(fenlist[i][3]),
                                        string2int(fenlist[i][4]),
                                        string2int(fenlist[i][5]),
                                        string2int(fenlist[i][6])       };
                perft->doPerftList(*perftPos,5,&results[0]); // <-- sollte 6 sein!!!
                cout << endl;
                delete perftPos;
            }
        
        }

        else if (check.substr(0,5)=="perft" && check.size()>5) {
            int depth=string2int(check.substr(6,check.size()));
            if (depth<8 && depth>0)
                perft->doSpeedPerft(*myPosition,depth);
            else
                cout << "given depth is invalid for perft-test" << endl;
        }
        
        else if (check.substr(0,6)=="pseudo" && check.size()>6) {
            int depth=string2int(check.substr(7,check.size()));
            if (depth<8 && depth>0)
                perft->doPseudoPerft(*myPosition,depth);
            else
                cout << "given depth is invalid for pseudo-test" << endl;
        }
        
        else if (check=="eval" || check.substr(0,2)=="go") {
            // hashTable->updateAges();
            hashTable->clearHash();
            int sum=0;
            string move;
            
            bool side2move=(*myPosition).onMove;
            
            timeval start,end;
            gettimeofday(&start,0);             
            int score = (*myPosition).alphaBetaMax(side2move,-100000, 100000, 1, 7, sum, move);
            gettimeofday(&end,0);
            double seconds = (end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)*0.000001;            
            if (check=="eval") {
                cout << "Move: " << move << endl;
                cout << "Score: " << score << endl;
                cout << "Positions: " << sum << endl;
                cout.setf(ios::fixed, ios::floatfield);
                cout << "Time: " << setprecision(3) << seconds << " seconds" << endl;
            } else {
                cout << "bestmove " << move << endl;
            }
        }
        
        else if (check=="egdb") {
            Egdb egdb;
            egdb.build();
        }
        
        else if (check=="print")
            (*myPosition).printBoard();
        
        else if (check=="info")
            (*myPosition).getInfo();
        
        /*
        else if (check=="go")
            cout << "do something cool :-)" << endl;
            // eval->goEval(*myPosition);
         * */

        else if (check.substr(0,6)=="divide") {
            bool modus=false;
            if (check.substr(0,7)=="divide2")
                modus=true;
            
            size_t found;
            found=check.find(" ");
            
            string strDepth = check.substr(int(found)+1,check.size()-int(found));
            int depth = atoi(strDepth.c_str());
            
            if (depth>0) {
                long sum=0;
                long total=0;
                int color;
                if ((*myPosition).onMove==true)
                    color=1;
                else color=0;
         
                (*myPosition).getDivide(color,1,depth,modus,sum,total);
                cout << "Nodes: " << total << endl;
            } else {
                cout << "no valid depth given. must be a valid number greater than 0" << endl;
            }
        }
        
        else if (check=="new") {
            delete myPosition;
            myPosition=new Position();
        }
        
        else if (check=="fen")
            cout << endl << "fen: " << (*myPosition).getFen() << endl << endl;
        
        else if (check.substr(0,13)=="position fen ") {
            string newFen = check.substr(13,check.size());
            delete myPosition;
            myPosition=new Position(newFen);
        }
        
        else if (check.substr(0,8)=="setboard") {
            if (check.size()>9) {
                string newFen = check.substr(9,check.size()-9);
                cout << newFen << endl;
                delete myPosition;
                myPosition=new Position(newFen);
            }
        }
        
        else if (check=="quit" || check=="exit") {
            cout << endl << "Goodbye!" << endl;
            loop=false;
        }
        
        else if (check=="help" || check=="?") {
            cout << "divide [n] ........... divide position with given depth" << endl;
            cout << "divide2 [n] .......... divide position with given depth" << endl;
            cout << "egdb ................. build end game database" << endl;
            cout << "eval ................. evaluate position" << endl;
            cout << "exit ................. exit engine" << endl;
            cout << "fen .................. print fen of current position" << endl;
            
            cout << "help ................. show this menu" << endl;
            cout << "info ................. print additional info about current position" << endl;
            cout << "new .................. reset position" << endl;
            cout << "perft ................ standard performance test" << endl;
            cout << "                       (with current position)" << endl;
            cout << "perft [n] ............ performance test with given depth" << endl;
            cout << "                       (with current position)" << endl;
            cout << "perft all ............ performance test with 5 positions" << endl;
            cout << "perft list ........... test 126 positions to depth 6 (takes a while)" << endl;
            cout << "print ................ print board of current position" << endl;
            cout << "setboard [fen] ....... set current position to given fen" << endl;
            cout << "quit ................. exit engine" << endl;
            cout << "? .................... show this menu" << endl;
            
        }
        
        else {
            eval->goOpponent(*myPosition,check);
        }

    }
    
    delete myPosition;
    delete perft;
    delete eval;
    
    if (pFile!=NULL)
        fclose(pFile);
   
    return 0;
}
예제 #11
0
 void operator () (Eval &eval,StepId dep,Expr::Neg *ptr)
  {
   auto step=eval.createStep(NegStep(ret),dep);
   
   eval.createStep(ExprStep(ptr->arg,step.obj.arg),step.id);
  }