{$M 8192,0,0}

Program Suduku_Version_1_200_By_BAZA;

{This Is A Suduku Game Player. It Will Also Generate Suduku Puzzles and
Answers based on User Inputted Starting Points. Ie it can be used to
generate least starting points single answer suduku combinations or also to
solve a suduku puzzle based on starting points. Or it can presolve a puzzle
and give the Suduku Game Player Hints.
Currently It Has:
TextBased Menu to start All Puzzles Generation
Generate Every Suduku Puzzle Combination
Compare the Generated Puzzles Combo To A Starting Point Array
Needs:
StartingPoint Interface to build Starting Point Array from User Data Puzzle Entry
GamePlay InterFace with Active Game Load And Save Game
Puzzle Generation Interface}

Uses Crt,Dos;

Type
  Counter = Integer;

Var
  WPSet,
  Answer,
  Go,
  Save          : Boolean;  {Go and Save - Dec if or not to save}
  IntTStr       : String;
  TB,
  WorkPoint,
  WSPoint,
  Acounter      : Counter;
  FileLineS,
  FileLine      : Array[1..9,1..3] of string; {9 files with 3 strings each}
  ComboFiles    : Array[1..9] of Text;
  Ch            : Array[1..5] of Char;
  UpToPoint,
  Puzzles       : Text; {Current Working Puzzle & 9*9 combos}

Procedure InitalizeVars;
Var
  L,S : Counter;

Begin
  TB:=1;
  Go:=False;
  Save:=False;
  ACounter:=0;
  WSPoint:=0;
  WPSet:=False;
  For L:=1 to 9 do
  For S:=1 to 3 do
    FileLineS[L,S]:='000';
End;

Procedure OpenFiles;
Begin
  Assign(ComboFiles[1],'CFile1.SKU');
  Assign(ComboFiles[2],'CFile2.SKU');
  Assign(ComboFiles[3],'CFile3.SKU');
  Assign(ComboFiles[4],'CFile4.SKU');
  Assign(ComboFiles[5],'CFile5.SKU');
  Assign(ComboFiles[6],'CFile6.SKU');
  Assign(ComboFiles[7],'CFile7.SKU');
  Assign(ComboFiles[8],'CFile8.SKU');
  Assign(ComboFiles[9],'CFile9.SKU');
  Reset(ComboFiles[1]);
  Reset(ComboFiles[2]);
  Reset(ComboFiles[3]);
  Reset(ComboFiles[4]);
  Reset(ComboFiles[5]);
  Reset(ComboFiles[6]);
  Reset(ComboFiles[7]);
  Reset(ComboFiles[8]);
  Reset(ComboFiles[9]);
End;

Procedure CloseFiles;
Begin
  Close(ComboFiles[1]);
  Close(ComboFiles[2]);
  Close(ComboFiles[3]);
  Close(ComboFiles[4]);
  Close(ComboFiles[5]);
  Close(ComboFiles[6]);
  Close(ComboFiles[7]);
  Close(ComboFiles[8]);
  Close(ComboFiles[9]);
  If Save=True then Close(Puzzles);
End;

Procedure WriteXy(x,y : Integer; S : String);
Begin
  GotoXy(x,y);
  Write(S);
End;

Procedure DrawGridTmode(Typ : Integer);
Var
 eL,L : Counter;

Begin
  Case Typ of
    1 : Begin
	  Writexy(5,12,'Suduku Grid For Start Data Point Entry');
	  Writexy(5,13,'------ ---- --- ----- ---- ----- -----');
	  Writexy(5,15,'Please Choose a nontet to work with ');
	End;
    2 : Begin
	  Writexy(5,12,'Suduku Individual Square Grid For Start Data Point Entry');
	  Writexy(5,13,'------ ---------- ------ ---- --- ----- ---- ----- -----');
	  Writexy(5,15,'Please Choose a square for data entry ');
	End;
    3 : Begin
	End;
  End;
End;

Procedure DrawSquare;
Var
  L : Counter;

Begin

End;

Function CompareSPoints(WP : Integer) : Boolean;
Var
  S,D : Counter;

Begin
  For S:=1 to 3 do
  For D:=1 to 3 do
  If (FileLine[WP,S][D]=FileLineS[WP,S][D]) or
     (FileLineS[WP,S][D]='0') then
       CompareSPoints:=True
     Else
       CompareSPoints:=False
End;

Procedure GetStartingPoints;
Var
  Grid          : Integer;
  IntVal, Code  : Integer;
  StartPGenID   : Array [1..4] of Integer;

Begin
  Grid:=1;
  Repeat
    WriteXy(10,10,'Suduku Starting Points Main Menu');
    WriteXy(10,20,'****** ******** ****** **** ****');
    WriteXy(10,40,'Enter To Select Square/Cell');
    WriteXy(10,60,'ESC To Deselect a Square/Cell');
    WriteXy(10,70,'1,2,3,4,5,6,7,8,9 keys to Enter Nontet or Cell Number');
    WriteXy(10,80,'0 To Delete a Starting Point');
    WriteXy(10,90,'D for Done');
    WriteXy(10,100,'S Save Points');
    WriteXy(10,110,'T Test For Maximum Suduku Combinations With Current S Points');
    DrawGridTmode(Grid);
    Ch[1]:=Readkey;
    Case Ord(Ch[1]) of
      49,50,51,
      52,53,55,
      56,57    : Begin
		   Grid:=2;
		   Val(Ch[1], IntVal, Code);
		   StartPGenID[1]:=IntVal;
		   Repeat
		     DrawGridTmode(Grid);
		     Ch[2]:=Readkey;
		     Case Ord(Ch[2]) of
		       49,50,51,
		       52,53,54,
		       55,56,57 : Begin
				    Grid:=3;
				    Val(Ch[2], IntVal, Code);
				    StartPGenID[2]:=IntVal;
				    Repeat
				      DrawGridTMode(Grid);
				      Ch[3]:=Readkey;
				      Case Ord(ch[3]) of
					49,50,51,
					52,53,54,
					55,56,57 : Begin
						     Val(Ch[3], IntVal, Code);
						     StartPGenID[4]:=Intval;
						     Case StartPGenID[2] of
						       1 : Begin
							     StartPGenID[2]:=1;
							     StartPGenID[3]:=1;
							   End;
						       2 : Begin
							     StartPGenID[2]:=1;
							     StartPGenID[3]:=2;
							   End;
						       3 : Begin
							     StartPGenID[2]:=1;
							     StartPGenID[3]:=3;
							   End;
						       4 : Begin
							     StartPGenID[2]:=2;
							     StartPGenID[3]:=3;
							   End;
						       5 : Begin
							     StartPGenID[2]:=3;
							     StartPGenID[3]:=3;
							   End;
						       6 : Begin
							     StartPGenID[2]:=3;
							     StartPGenID[3]:=2;
							   End;
						       7 : Begin
							     StartPGenID[2]:=3;
							     StartPGenID[3]:=1;
							   End;
						       8 : Begin
							     StartPGenID[2]:=2;
							     StartPGenID[3]:=1;
							   End;
						       9 : Begin
							     StartPGenID[2]:=2;
							     StartPGenID[3]:=2;
							   End;
						     End;
						     Str(StartPGenID[4],InttStr);
						     FileLineS[StartPGenID[1],StartPGenID[2]][StartPGenID[3]]:=InttStr[1];
						   End;
					27       : Begin
						     Grid:=2;
						   End
					Else
					Begin
					End;
				      End;
				    Until Grid=2;
				  End;
		       27       : Begin
				    Grid:=1;
				  End
		       Else
		       Begin
		       End;
		     End;
		   Until Grid=1;
		 End;
      0        : Begin
		 End;

      Else
      Begin
	TextColor(4);
	WriteXy(30,250,'Wrong Key');
	Delay(1000);
	TextColor(0);
	WriteXy(30,250,'Wrong Key');
	TextColor(15);
      End;
    End;
  Until (Upcase(ch[1])='D') or (ord(ch[1])=27);
End;


Function InttoStr(X: Integer) : String;
Var
  S: string;

begin
  Str(X, S);
  IntToStr:=S;
End;

Function StrToInt(X: String) : Integer;
Var
  I,Code: Integer;

Begin
  Val(X, I, Code);
  If Code <> 0 then
    Writeln('Error at positon: ', Code)
  Else
    StrtoInt:=I;
End;

Procedure ValidateAnswer;
Begin
  Answer:=True; {YAY}
End;

Procedure DisplayAnswer;
Var
  L : Counter;
  X : Word;
  S : String;
  KeyF : Text;
  File1: PathStr;

Begin
  Clrscr;
  Rewrite(UptoPoint);
  For X:=1 to Workpoint do
  For L:=1 to 3 do
  Begin
    Writeln(Uptopoint,FileLine[X,L]);
    IF (L=3) then
      Writeln(UptoPoint,'-------');
    End;
  Writeln(UpToPoint,Workpoint);
  Close(UptoPoint);
  TextColor(3);
  Writeln('Lets Watch The Paint Dry...YAY and JOYV1.1!');
  TextColor(6);
  Writeln('---- ----- --- ----- ---   --- --- -------');
  Writeln;
  TextColor(7);
  IF TB<6 then Inc(TB)
  Else TB:=1;
  TextBackGround(TB);
  Case WorkPoint of
    1 : Begin
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln('      ',FileLine[1,1]);
	  Writeln('      ',FileLine[1,2]);
	  Writeln('      ',FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    2 : Begin
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln('   ',FileLine[2,1],FileLine[1,1]);
	  Writeln('   ',FileLine[2,2],FileLine[1,2]);
	  Writeln('   ',FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    3 : Begin
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    4 : Begin
	  Writeln;
	  Writeln;
	  Writeln;
	  Writeln(FileLine[4,1]);
	  Writeln(FileLine[4,2]);
	  Writeln(FileLine[4,3]);
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    5 : Begin
	  Writeln(FileLine[5,1],'      ');
	  Writeln(FileLine[5,2],'      ');
	  Writeln(FileLine[5,3],'      ');
	  Writeln(FileLine[4,1],'      ');
	  Writeln(FileLine[4,2],'      ');
	  Writeln(FileLine[4,3],'      ');
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    6 : Begin
	  Writeln(FileLine[5,1],FileLine[6,1],'   ');
	  Writeln(FileLine[5,2],FileLine[6,2],'   ');
	  Writeln(FileLine[5,3],FileLine[6,3],'   ');
	  Writeln(FileLine[4,1],'      ');
	  Writeln(FileLine[4,2],'      ');
	  Writeln(FileLine[4,3],'      ');
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    7 : Begin
	  Writeln(FileLine[5,1],FileLine[6,1],FileLine[7,1]);
	  Writeln(FileLine[5,2],FileLine[6,2],FileLine[7,2]);
	  Writeln(FileLine[5,3],FileLine[6,3],FileLine[7,3]);
	  Writeln(FileLine[4,1],'      ');
	  Writeln(FileLine[4,2],'      ');
	  Writeln(FileLine[4,3],'      ');
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    8 : Begin
	  Writeln(FileLine[5,1],FileLine[6,1],FileLine[7,1]);
	  Writeln(FileLine[5,2],FileLine[6,2],FileLine[7,2]);
	  Writeln(FileLine[5,3],FileLine[6,3],FileLine[7,3]);
	  Writeln(FileLine[4,1],'   ',FileLine[8,1]);
	  Writeln(FileLine[4,2],'   ',FileLine[8,2]);
	  Writeln(FileLine[4,3],'   ',FileLine[8,3]);
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds of Joy!!!');
	End;
    9 : Begin
	  Writeln(FileLine[5,1],FileLine[6,1],FileLine[7,1]);
	  Writeln(FileLine[5,2],FileLine[6,2],FileLine[7,2]);
	  Writeln(FileLine[5,3],FileLine[6,3],FileLine[7,3]);
	  Writeln(FileLine[4,1],FileLine[9,1],FileLine[8,1]);
	  Writeln(FileLine[4,2],FileLine[9,2],FileLine[8,2]);
	  Writeln(FileLine[4,3],FileLine[9,3],FileLine[8,3]);
	  Writeln(FileLine[3,1],FileLine[2,1],FileLine[1,1]);
	  Writeln(FileLine[3,2],FileLine[2,2],FileLine[1,2]);
	  Writeln(FileLine[3,3],FileLine[2,3],FileLine[1,3]);
	  Writeln;
	  Writeln('Total of ',ACounter,' Kinds Of Joy!!!');
	  Writeln;
	  Writeln('567');
	  Writeln('498');
	  Writeln('321');
	  Writeln;
	  File1:='';
	  File1:=FSearch('Key.Prs',GetEnv('PATH'));
	  If File1<>'' then
	  Begin
	    Assign(KeyF,'Key.PRS');
	    Reset(KeyF);
	    Readln(KeyF,CH[1]);
	    Close(KeyF);
	    SwapVectors;
	      Exec(GetEnv('COMSPEC'),'/C Del Key.Prs');
	    SwapVectors;
	  End;
	  If (Go<>True) then
	  Begin
	    Writeln('N To Find the Next Suduku Square Answer or');
	    Writeln('A to continue Untill all Possible Puzzles Have Been Solved - YAY or');
	    Writeln('S to Save all Possible Sukuku Puzzles in a Text File - JOY ');
	    Repeat
	      Ch[1]:=Readkey;
	      Case Ord(Ch[1]) of
		27       : Begin {Mandatory Key Capture}
			   End;
		78,110   : Begin
			     Save:=False;
			   End;
		97,65    : Begin
			     Go:=True;
			     Save:=False;
			   End;
		83,115   : Begin
			     Go:=True;
			     Save:=True;
			   End
		Else
		Begin
		  GotoXy(1,30);
		  Writeln('Try Another Key---And Read Instructions');
		End;
	      End;
	    Until (Ord(Ch[1])=27) or (UpCase(Ch[1])='N') or (Upcase(CH[1])='A') or (UpCase(Ch[1])='S');
	    ClrScr;
	  End;
	  If Save=True then
	  Begin
	    Writeln(Puzzles,FileLine[5,1]+FileLine[6,1]+FileLine[7,1]);
	    Writeln(Puzzles,FileLine[5,2]+FileLine[6,2]+FileLine[7,2]);
	    Writeln(Puzzles,FileLine[5,3]+FileLine[6,3]+FileLine[7,3]);
	    Writeln(Puzzles,FileLine[4,1]+FileLine[9,1]+FileLine[8,1]);
	    Writeln(Puzzles,FileLine[4,2]+FileLine[9,2]+FileLine[8,2]);
	    Writeln(Puzzles,FileLine[4,3]+FileLine[9,3]+FileLine[8,3]);
	    Writeln(Puzzles,FileLine[3,1]+FileLine[2,1]+FileLine[1,1]);
	    Writeln(Puzzles,FileLine[3,2]+FileLine[2,2]+FileLine[1,2]);
	    Writeln(Puzzles,FileLine[3,3]+FileLine[2,3]+FileLine[1,3]);
	    Writeln(Puzzles,'----');
	    Writeln(Puzzles,ACounter);
	  End;
	End;
  End;
  TextBackground(0);
End;

Procedure ReadSPoints;
Var
  L : Counter;
  S : Counter;
  D : Text;
  R : String;

Begin
  Assign(D,'UPtopoint.txt');
  Reset(D);
  For S:=1 to 9 do
  For L:=1 to 3 do
  Begin
    ReadLn(D,R);
    IF R[1]='-' then
      Readln(D,R);
    IF Eof(D)=True then
    Begin
      WSPoint:=StrtoInt(R);
      S:=9;
      L:=3;
    End
    Else
    Begin
      FileLineS[S,L]:=R;
    End;
  End;
  Close(D);
End;

Procedure AnswerPlease;
Var
  Continue:Boolean;
  X,L : Counter;

Begin
  Answer:=False;
  Assign(UptoPoint,'UPtopoint.txt');
  Repeat
    WorkPoint:=1;
    Continue:=False;
    If WorkPoint=WSPoint then
    Begin
      WPset:=True;
      WSPoint:=0;
    End;
    Readln(ComboFiles[1],FileLine[1,1]);
    Readln(ComboFiles[1],FileLine[1,2]);
    Readln(ComboFiles[1],FileLine[1,3]);
    Readln(ComboFiles[1]);
    DisplayAnswer;
    IF CompareSPoints(WorkPoint)=True then
      IF WPSet=False then Continue:=True
      Else If WPSet=True then
      Begin
	Continue:=True;
	For X:= 1 to 9 do
	For L:= 1 to 3 do FileLineS[X,L]:='000';
	WPSet:=False;
      End;
    IF WSPoint=0 then Continue:=True;
    If Continue=True then
    Repeat
      WorkPoint:=2;
      Continue:=False;
      If WorkPoint=WSPoint then
      Begin
	WPset:=True;
	WSPoint:=0;
      End;
      Readln(ComboFiles[2],FileLine[2,1]);
      Readln(ComboFiles[2],FileLine[2,2]);
      Readln(ComboFiles[2],FileLine[2,3]);
      Readln(ComboFiles[2]);
      IF (WSPoint>0) then
	IF (CompareSPoints(WorkPoint)=True) then
	  IF (WPSet=False) then Continue:=True
	  Else If (WPSet=True) Then
	  Begin
	    Continue:=True;
	    For X:=1 to 9 do
	    For L:=1 to 3 do FileLineS[X,L]:='000';
	    WPSet:=False;
	  End;
      If WSPoint=0 then Continue:=True;
      IF Continue=True then
      For L:=1 to 3 do
      For X:=1 to 3 do
	If (FileLine[2,1][L]=FileLine[1,1][X]) or
	   (FileLine[2,2][L]=FileLine[1,2][X]) or
	   (FileLine[2,3][L]=FileLine[1,3][X]) then
	   Begin
	     L:=3;
	     X:=3;
	     Continue:=False;
	   End
	   Else If (X=3) and (L=3) then Continue:=True;
      If Continue=True Then DisplayAnswer;
      If Continue=True then
      Begin
	Repeat
	  WorkPoint:=3;
	  Continue:=False;
	  IF WorkPoint=WSPoint then
	  Begin
	    WPset:=True;
	    WSPoint:=0;
	  End;
	  Readln(ComboFiles[3],FileLine[3,1]);
	  Readln(ComboFiles[3],FileLine[3,2]);
	  Readln(ComboFiles[3],FileLine[3,3]);
	  Readln(ComboFiles[3]);
	  IF (WSPoint>0) then
	    IF (CompareSPoints(WorkPoint)=True) then
	      IF (WPSet=False) then Continue:=True
	      Else If (WPSet=True) Then
	      Begin
		Continue:=True;
		For X:= 1 to 9 do
		For L:= 1 to 3 do FileLineS[X,L]:='000';
		WPSet:=False;
	      End;
	  IF WSPoint=0 then Continue:=True;
	  IF Continue=True then
	  For L:=1 to 3 do
	  For X:= 1 to 3 do
	    If (FileLine[3,1][L]=FileLine[2,1][X]) or
	       (FileLine[3,2][L]=FileLine[2,2][X]) or
	       (FileLine[3,3][L]=FileLine[2,3][X]) or
	       (FileLine[3,1][L]=FileLine[1,1][X]) or
	       (FileLine[3,2][L]=FileLine[1,2][X]) or
	       (FileLine[3,3][L]=FileLine[1,3][X]) then
	       Begin
		 X:=3;
		 L:=3;
		 Continue:=False;
	       End
	       Else If (X=3) and (L=3) then Continue:=True;
	  If Continue=True Then DisplayAnswer;
	  If Continue=True then
	  Begin
	    Repeat
	      WorkPoint:=4;
	      Continue:=False;
	      IF WorkPoint=WSPoint then
	      Begin
		WPset:=True;
		WSPoint:=0;
	      End;
	      Readln(ComboFiles[4],FileLine[4,1]);
	      Readln(ComboFiles[4],FileLine[4,2]);
	      Readln(ComboFiles[4],FileLine[4,3]);
	      Readln(ComboFiles[4]);
	      IF WSPoint>0 Then
		IF (CompareSPoints(WorkPoint)=True) then
		  IF (WPSet=False) then Continue:=True
		  Else If (WPSet=True) Then
		  Begin
		    Continue:=True;
		    For X:= 1 to 9 do
		    For L:= 1 to 3 do FileLineS[X,L]:='000';
		    WPSet:=False;
		  End;
	      IF WSPoint=0 then Continue:=True;
	      IF Continue=True then
	      For L:=1 to 3 do
	      For X:=1 to 3 do
		If (FileLine[4,X][1]=FileLine[3,L][1]) or
		   (FileLine[4,X][2]=FileLine[3,L][2]) or
		   (FileLine[4,X][3]=FileLine[3,L][3]) then
		   Begin
		     L:=3;
		     X:=3;
		     Continue:=False;
		   End
		   Else If (X=3) and (L=3) then Continue:=True;
	      If Continue=True Then DisplayAnswer;
	      If Continue=True Then
	      Begin
		Repeat
		  WorkPoint:=5;
		  Continue:=False;
		  If WorkPoint=WSPoint then
		  Begin
		    WPset:=True;
		    WSPoint:=0;
		  End;
		  Readln(ComboFiles[5],FileLine[5,1]);
		  Readln(ComboFiles[5],FileLine[5,2]);
		  Readln(ComboFiles[5],FileLine[5,3]);
		  Readln(ComboFiles[5]);
		  IF WSPoint>0 then
		    IF (CompareSPoints(WorkPoint)=True) then
		      IF (WPSet=False) then Continue:=True
		      Else If (WPSet=True) Then
		      Begin
			Continue:=True;
			For X:= 1 to 9 do
			For L:= 1 to 3 do FileLineS[X,L]:='000';
			WPSet:=False;
		      End;
		  IF WSPoint=0 then Continue:=True;
		  If Continue=True then
		  For L:=1 to 3 do
		  For X:=1 to 3 do
		    If (FileLine[5,X][1]=FileLine[4,L][1]) or
		       (FileLine[5,X][2]=FileLine[4,L][2]) or
		       (FileLine[5,X][3]=FileLine[4,L][3]) or
		       (FileLine[5,X][1]=FileLine[3,L][1]) or
		       (FileLine[5,X][2]=FileLine[3,L][2]) or
		       (FileLine[5,X][3]=FileLine[3,L][3]) then
		       Begin
			 L:=3;
			 X:=3;
			 Continue:=False;
		       End
		       Else If (X=3) and (L=3) then Continue:=True;
		  If Continue=True Then DisplayAnswer;
		  If Continue=True Then
		  Begin
		    Repeat
		      WorkPoint:=6;
		      Continue:=False;
		      If WorkPoint=WSPoint then
		      Begin
			WPset:=True;
			WSPoint:=0;
		      End;
		      Readln(ComboFiles[6],FileLine[6,1]);
		      Readln(ComboFiles[6],FileLine[6,2]);
		      Readln(ComboFiles[6],FileLine[6,3]);
		      Readln(ComboFiles[6]);
		      IF (WSPoint>0) then
			IF (CompareSPoints(WorkPoint)=True) then
			  IF (WPSet=False) then Continue:=True
			  Else If (WPSet=True) Then
			  Begin
			    Continue:=True;
			    For X:= 1 to 9 do
			    For L:= 1 to 3 do FileLineS[X,L]:='000';
			    WPSet:=False;
			  End;
		      IF WSpoint=0 then Continue:=True;
		      If Continue=True then
		      For L:=1 to 3 do
		      For X:= 1 to 3 do
			If (FileLine[6,1][L]=FileLine[5,1][X]) or
			   (FileLine[6,2][L]=FileLine[5,2][X]) or
			   (FileLine[6,3][L]=FileLine[5,3][X]) or
			   (FileLine[6,X][1]=FileLine[2,L][1]) or
			   (FileLine[6,X][2]=FileLine[2,L][2]) or
			   (FileLine[6,X][3]=FileLine[2,L][3]) then
			   Begin
			     L:=3;
			     X:=3;
			     Continue:=False;
			   End
			   Else If (X=3) and (L=3) then Continue:=True;
		      If Continue=True Then DisplayAnswer;
		      If Continue=True Then
		      Begin
			Repeat
			  WorkPoint:=7;
			  Continue:=False;
			  If WorkPoint=WSPoint then
			  Begin
			    WPset:=True;
			    WSPoint:=0;
			  End;
			  Readln(ComboFiles[7],FileLine[7,1]);
			  Readln(ComboFiles[7],FileLine[7,2]);
			  Readln(ComboFiles[7],FileLine[7,3]);
			  Readln(ComboFiles[7]);
			  If (WSPoint>0) Then
			    IF (CompareSPoints(WorkPoint)=True) then
			      IF (WPSet=False) then Continue:=True
			      Else If (WPSet=True) Then
			      Begin
				Continue:=True;
				For X:= 1 to 9 do
				For L:= 1 to 3 do FileLineS[X,L]:='000';
				WPSet:=False;
			      End;
			  IF WSPoint=0 Then Continue:=True;
			  If Continue=True then
			  For L:=1 to 3 do
			  For X:= 1 to 3 do
			    If (FileLine[7,1][L]=FileLine[6,1][X]) or
			       (FileLine[7,2][L]=FileLine[6,2][X]) or
			       (FileLine[7,3][L]=FileLine[6,3][X]) or
			       (FileLine[7,1][L]=FileLine[5,1][X]) or
			       (FileLine[7,2][L]=FileLine[5,2][X]) or
			       (FileLine[7,3][L]=FileLine[5,3][X]) or
			       (FileLine[7,X][1]=FileLine[1,L][1]) or
			       (FileLine[7,X][2]=FileLine[1,L][2]) or
			       (FileLine[7,X][3]=FileLine[1,L][3]) then
			       Begin
				 Continue:=False;
				 L:=3;
				 X:=3;
			       End
			       Else If (X=3) and (L=3) then Continue:=True;
			  If Continue=True Then DisplayAnswer;
			  If Continue=True Then
			  Begin
			    Repeat
			      WorkPoint:=8;
			      Continue:=False;
			      If WorkPoint=WSPoint then
			      Begin
				WPset:=True;
				WSPoint:=0;
			      End;
			      Readln(ComboFiles[8],FileLine[8,1]);
			      Readln(ComboFiles[8],FileLine[8,2]);
			      Readln(ComboFiles[8],FileLine[8,3]);
			      Readln(ComboFiles[8]);
			      IF (WSPoint>0) then
				IF (CompareSPoints(WorkPoint)=True) then
				  IF (WPSet=False) then Continue:=True
				  Else If (WPSet=True) Then
				  Begin
				    Continue:=True;
				    For X:= 1 to 9 do
				    For L:= 1 to 3 do FileLineS[X,L]:='000';
				    WPSet:=False;
				  End;
			      IF WSPoint=0 then Continue:=True;
			      If Continue=True then
			      For L:=1 to 3 do
			      For X:= 1 to 3 do
				If (FileLine[8,X][1]=FileLine[7,L][1]) or
				   (FileLine[8,X][2]=FileLine[7,L][2]) or
				   (FileLine[8,X][3]=FileLine[7,L][3]) or
				   (FileLine[8,1][L]=FileLine[4,1][X]) or
				   (FileLine[8,2][L]=FileLine[4,2][X]) or
				   (FileLine[8,3][L]=FileLine[4,3][X]) or
				   (FileLine[8,X][1]=FileLine[1,L][1]) or
				   (FileLine[8,X][2]=FileLine[1,L][2]) or
				   (FileLine[8,X][3]=FileLine[1,L][3]) then
				   Begin
				     L:=3;
				     X:=3;
				     Continue:=False;
				   End
				   Else If (X=3) and (L=3) then Continue:=True;
			      If Continue=True then DisplayAnswer;
			      If Continue=True then
			      Begin
				Repeat
				  WorkPoint:=9;
				  Continue:=False;
				  If WorkPoint=WSPoint then
				  Begin
				    WPset:=True;
				    WSPoint:=0;
				  End;
				  Readln(ComboFiles[9],FileLine[9,1]);
				  Readln(ComboFiles[9],FileLine[9,2]);
				  Readln(ComboFiles[9],FileLine[9,3]);
				  Readln(ComboFiles[9]);
				  IF (WSPoint>0) Then
				    IF (CompareSPoints(WorkPoint)=True) then
				      IF (WPSet=False) then Continue:=True
				      Else If (WPSet=True) Then
				      Begin
					Continue:=True;
					For X:= 1 to 9 do
					For L:= 1 to 3 do FileLineS[X,L]:='000';
					WPSet:=False;
				      End;
				  If WSPoint=0 Then Continue:=True;
				  If Continue=True then
				  For L:=1 to 3 do
				  For X:= 1 to 3 do
				    If (FileLine[9,1][L]=FileLine[8,1][X]) or
				       (FileLine[9,2][L]=FileLine[8,2][X]) or
				       (FileLine[9,3][L]=FileLine[8,3][X]) or
				       (FileLine[9,X][1]=FileLine[6,L][1]) or
				       (FileLine[9,X][2]=FileLine[6,L][2]) or
				       (FileLine[9,X][3]=FileLine[6,L][3]) or
				       (FileLine[9,1][L]=FileLine[4,1][X]) or
				       (FileLine[9,2][L]=FileLine[4,2][X]) or
				       (FileLine[9,3][L]=FileLine[4,3][X]) or
				       (FileLine[9,X][1]=FileLine[2,L][1]) or
				       (FileLine[9,X][2]=FileLine[2,L][2]) or
				       (FileLine[9,X][3]=FileLine[2,L][3]) then
				       Begin
					 L:=3;
					 X:=3;
					 Continue:=False;
				       End
				       Else If (X=3) and (L=3) then
				       Begin
					 Answer:=True;
					 ValidateAnswer;
				       End;
				  If Answer=True then
				  Begin
				    Inc(ACounter);
				    DisplayAnswer;
				    If Eof(ComboFiles[1])<>True then Answer:=False
				  End;
				Until Eof(ComboFiles[9]) or (Answer=True) or (Ord(Ch[1])=27);
			      End;
			      If Eof(ComboFiles[9])=True then Reset(ComboFiles[9]);
			    Until Eof(ComboFiles[8]) or (Answer=True) or (Ord(Ch[1])=27);
			  End;
			  If Eof(ComboFiles[8])=True then Reset(ComboFiles[8]);
			Until Eof(ComboFiles[7]) or (Answer=True) or (Ord(Ch[1])=27);
		      End;
		      If Eof(ComboFiles[7])=True then Reset(ComboFiles[7]);
		    Until Eof(ComboFiles[6]) or (Answer=True) or (Ord(Ch[1])=27);
		  End;
		  If Eof(ComboFiles[6])=True then Reset(ComboFiles[6]);
		Until Eof(ComboFiles[5]) or (Answer=True) or (Ord(Ch[1])=27);
	      End;
	      If Eof(ComboFiles[5])=True then Reset(ComboFiles[5]);
	    Until Eof(ComboFiles[4]) or (Answer=True) or (Ord(Ch[1])=27);
	  End;
	  If Eof(ComboFiles[4])=True then Reset(ComboFiles[4]);
	Until Eof(ComboFiles[3]) or (Answer=True) or (Ord(Ch[1])=27);
      End;
      If Eof(ComboFiles[3])=True then Reset(ComboFiles[3]);
    Until Eof(ComboFiles[2]) or (Answer=True) or (Ord(Ch[1])=27);
    If Eof(ComboFiles[2])=True then Reset(ComboFiles[2]);
  Until Eof(ComboFiles[1]) or (Answer=True) or (Ord(Ch[1])=27);
End;

Procedure DetSolutionFile;
Var
  File1 : PathStr;
  St : String;

Begin
  Assign(Puzzles,'PFile.Sku');
  File1:=FSearch('Pfile.Sku',GetEnv('PATH'));
  if File1 = '' then
  Begin
    Textcolor(4);
    WriteLn('Combination File not found...Lets Start');
    Writeln;
    Textcolor(15);
    Writeln('Press Any Key To Begin Suduku Puzzle and Combo Generator ');
    CH[1]:=Readkey;
    ReWrite(Puzzles);
    Save:=True;
    Clrscr;
  End
  else
  Begin
    File1:=FSearch('UpToPoint.txt',GetEnv('PATH'));
    If File1 = '' then  {***********Needs work}
      Writeln('All Combinations Generated')
    Else
    Begin
      TextColor(5);
      Writeln('Would You Like To Contine Generating Combinations?');
      Writeln('Y/N ');
      Repeat
	CH[1]:=ReadKey;
	Case Ord(Ch[1]) of
	   89,121 : Begin
		      Reset(Puzzles);
		      Repeat
			Readln(Puzzles,St);
		      Until (Eof(Puzzles)=True);
		      ACounter:=StrtoInt(St);
		      Append(Puzzles);
		      Go:=True;
		      Save:=True;
		      ReadSpoints;
		    End;
	    78,110: Begin
		      ReWrite(Puzzles);
		      Go:=False;
		      ClrScr;
		    End
	    Else
	    Begin
	      GotoXy(1,33);
	      Writeln('Try A Better Key');
	    End;
	End;
      Until (Ord(Ch[1])=27) or (Upcase(Ch[1])='Y') or (Upcase(Ch[1])='N');
    End
  End;
End;

{-----------------Main Program-----------------}

Begin
  InitalizeVars;
  OpenFiles;
  DetSolutionFile;
  {GetStartingPoints;} {--------Work}
  AnswerPlease;
  CloseFiles;
End.
