Example #1
0
int main(int argc, char **argv)
{
    char *filename;
    FILE *fd;
    int left = (9*9)*9;
    int count=0;

    if (argc == 2) {
        filename = argv[1];
    } else {
        filename = "fields.sud";
    }

    bf_backups = malloc(sizeof(struct bf_backups));

    if (!(fd = fopen(filename, "r"))) {
        printf("error opening file\n");
        exit(1);
    }
    if(readfield(fd)) {
        printf("error reading field\n");
        exit(1);
    }

    if (initialize())
        exit(1);

    fill_all();
    check_filled();
    printfield(wfield, 1);
    bruteforced = 0;

    /* main loop */
    while (left > 0) {
        check_validity();
        solve_run(&count);
        check_validity();
        left = get_left();
        count++;
    }
    if (final_check()) {
        winprintf(wtext, "\n\rSolved successfully\n\r");
    } else {
        winprintf(wtext, "\n\rThere are still some errors\n\r");
    }
    printfield(wfield, 1);
    press_any_key();
    endwin();
    return(0);
}
Example #2
0
void main()
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int left, top, right, bottom;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "E:\TC\BGI");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }
   cleardevice();
create();
/*temp=head;
temp=temp->down;
for(i=0;i<3;i++)
temp=temp->right;
temp->data=2;
temp=head;
temp=temp->down->down;
temp=temp->right;
temp->data=2;   */
setcolor(5);
setlinestyle(1,1,3);
line(250,100,50,200);
line(50,200,250,225);
line(250,225,25,325);
line(500,100,300,200);
line(300,200,500,225);
line(500,225,275,325);
settextstyle(1,0,6);
outtextxy(150,375,"PRESENTS");
getch();
cleardevice();
settextstyle(1,0,6);
outtextxy(150,150,"MYSTERIES");
outtextxy(190,250,"OF");
outtextxy(170,350,"1024");
getch();
cleardevice();
setcolor(15);
settextstyle(0,0,1);
sprintf(s,"RULES=>");
outtextxy(5,5,s);
sprintf(s,"You Have To Create The Number 1024");
  outtextxy(5,20,s);
sprintf(s,"Use arrow Keys to Move");
  outtextxy(5,35,s);
sprintf(s,"Press N At Any Point To Quit...");
  outtextxy(5,45,s);
sprintf(s,"Are You Ready....");
  outtextxy(5,60,s);
getch();
cleardevice();
display();
while(k==0)
{
y=0;
 display();
 sprintf(s,"Enter Your Move");
 outtextxy(5,5,s);

 ch=getch();
 switch(ch)
 {
  case 72:    move='W';
		break;
  case 80:  move='S';
		break;
  case 77: move='D';
		break;
  case 75:  move='A';
		break;
  case 'n':     k=1;
		break;
  default:      y=1;
 }
if(k==1)
{
outtextxy(5,25,"Thanks for playing.....");
break;
}
if(y==1)
{
outtextxy(5,25,"Wrong Move....");
}
else
{
 movem();
// display();
// getch();
 check();
 movem();
 newnum();
 k=final_check();
 display();
 }
if(k==2)
outtextxy(5,25,"congratulation!!!!! You Have WON THE GAME...");
if(k==1)
outtextxy(55,25,"SORRY!!! GAME OVER");

}
getch();
//getch();
//getch();
closegraph();
}