void main()
{
	clrscr();
	char pwd[]="bigmanani";
	char ans[20];
	cout<<"Enter password : "******"*";
		}
		else break;
	}
	if(strcmp(ans,pwd))
	{
		cout<<"\nIncorrect password.";
		getch();
		exit(0);
	}



	int op;
	clrscr();
	fout<<"main\n";
	ifstream fin("sdk.txt");
	// cout<<"Enter the puzzle row-wise (Use 0's for empty spaces) :\n";
	for(int i=0;i<=8;++i)
	for(int j=0;j<=8;++j)
	{
	  fin>>space[i][j].value;
	  if(space[i][j].value==0)
	  {
		for(int k=1;k<=9;++k)
			space[i][j].poss[k]=1;
	  }
	  else
	  {
		for(int k=1;k<=9;++k)
		{
			if(k!=space[i][j].value)
				space[i][j].poss[k]=0;
			else
				space[i][j].poss[k]=1;
		}
	  }
	}
	cout<<"Puzzle accepted. Starting Evaluation.\n";  //getch();
	for(int e=1;;++e)
	{
		fout<<"Starting Evaluation "<<e<<"\n";  // getch();
		for(i=0;i<=8;++i)
		{
			for(j=0;j<=8;++j)
			{
				int nop=0;
				cell_one_pos(i,j);
				int the_poss_val=0;
				cout<<"Evaluating space "<<i<<" "<<j<<"\n"; //getch();
				if(space[i][j].value!=0)  // already filled
				{
				   cout<<"space "<<i<<" "<<j<<" is already filled.\n";//getch();
				   continue;
				}
				else cout<<"space "<<i<<" "<<j<<" is empty\n";//getch();
				for(int k=1;k<=9;++k)
				{
					cout<<"Trying value "<<k<<"\n"; //getch ();
					if(!in_col(j,k)&&!in_row(i,k)&&!in_box(i,j,k))       //   check conds
					{
						nop++;
						cout<<k<<" is a possible value.\n";  //getch();
						space[i][j].poss[k]=1;
						the_poss_val=k;
					}

					else if(in_col(j,k)||in_row(i,k)||in_box(i,j,k))
					{
						space[i][j].poss[k]=0;
						cout<<k<<" is not a possible value\n"; // getch();
					}

				}
				if(nop==1)
					{	space[i][j].value=the_poss_val;
						cout<<i<<" "<<j<<" ="<<the_poss_val<<"\n";// getch();
						boxes_filled++;

						for(int d=1;d<=9;d++)
						{
							if(d!=the_poss_val)
								space[i][j].poss[d]=0;
						}
					}
			}
		}
		elim(0,0);elim(0,3);elim(0,6);
		elim(3,0);elim(3,3);elim(3,6);
		elim(6,0);elim(6,3);elim(6,6);
		rem_lin_pos(1133);rem_lin_pos(4769);
		rem_lin_pos(1436);rem_lin_pos(7193);
		rem_lin_pos(1739);rem_lin_pos(7496);
		rem_lin_pos(4163);rem_lin_pos(7799);
		rem_lin_pos(4466);
		cout<<"\nEvaluation "<<e<<" finished. A total of "<<boxes_filled<<" spaces have now been filled.\n";
		Menu :
		cout<<"\n1.View the puzzle solved this far.\n";
		cout<<"2.Continue Evaluation.\n";
		cout<<"3.View the possibilities of a space. [row col]\n";
		cout<<"4.Exit Program.\n";
		cout<<"6.Elimination\n";
		cout<<"7.Set Value. [row col val]\n";
		cout<<"Choose an Option : ";
		cin>>op;
		if(op==1)
		{
			for(i=0;i<=8;++i)
			{
				for(j=0;j<=8;++j)
				{
					//if(space[i][j].value!=0)
						cout<<" "<<space[i][j].value;
				  /*	else
					{
						cout<<" {";
						for(int g=1;g<=9;++g)
						{
							if(space[i][j].poss[g])
							  cout<<g;
						}
						cout<<"}";
					}                        */
				}
				cout<<"\n";
			}
		}
		if(op==2)
		{
			unfilled();
			continue;

		}
		if(op==3)
		{
			int i,j;
			cin>>i>>j;
			cout<<"Possibilities are : ";
			for(int k=1;k<=9;++k)
			{
				if(space[i][j].poss[k]==1)
					cout<<k<<" ";
			}
		}
		if(op==4)
			exit(0);
		if(op==5)
		{
			cout<<"Enter BIN : ";
			int bin;
			cin>>bin;
			double_down(bin);
		}
Esempio n. 2
0
bool Demo::read(yarp::os::ConnectionReader& connection) {
  yarp::os::idl::WireReader reader(connection);
  reader.expectAccept();
  if (!reader.readListHeader()) { reader.fail(); return false; }
  std::string tag = reader.readTag();
  while (!reader.isError()) {
    // TODO: use quick lookup, this is just a test
    if (tag == "get_answer") {
      int32_t _return;
      _return = get_answer();
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeI32(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "add_one") {
      int32_t x;
      if (!reader.readI32(x)) {
        x = 0;
      }
      int32_t _return;
      _return = add_one(x);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeI32(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "double_down") {
      int32_t x;
      if (!reader.readI32(x)) {
        reader.fail();
        return false;
      }
      int32_t _return;
      _return = double_down(x);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeI32(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "add_point") {
       ::yarp::test::PointD x;
       ::yarp::test::PointD y;
      if (!reader.read(x)) {
        reader.fail();
        return false;
      }
      if (!reader.read(y)) {
        reader.fail();
        return false;
      }
       ::yarp::test::PointD _return;
      _return = add_point(x,y);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(3)) return false;
        if (!writer.write(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (reader.noMore()) { reader.fail(); return false; }
    std::string next_tag = reader.readTag();
    if (next_tag=="") break;
    tag = tag + "_" + next_tag;
  }
  return false;
}