Hi everyone. I'm writing a sudoku solving program just for fun currently in free pascal. I don't use any objects, I'm really inexperienced with OOP, and due to the complexity of the problem, I'm skipping on them currently. Later I will get into it, but I'll start with easier programs, because this turns out to be a pretty hard one.

This program doesn't use a Gauss elimination or brute forces it way through the Sudoku to find a pattern that matches the original clues, that's way too boring. I've decided that I'd rather implement very humanlike strategies in it. As I consider myself a decent Sudoku solver, I'm familiar with the concepts and strategies, and making a program doing them is quite challenging.

Here's how it works:

The 9x9 Grid is a Matrix, defined liked this in the program:

Code:
Type 

Cell=Record

Number_of_Candidates:smallint;
Candidates:array[1..9] of smallint;
Solved: Boolean;

end;

Var

Grid:array[1..9,1..9] of Cell;
Now here's how it works...

First, the User inputs the clues line by line, and 0 means there is no clue in that particular cell, these are the cells the program will have to solve.

I don't yet have any procedure or function which checks the validity of the Sudoku, I'm currently using Sudokus for tests that I know to be valid, and will later care about error checking.

When the Grid is read, first the program calculates all the possible candidates for each cell, and then the fun begins.

First, it checks for "Naked Singles". These are cells, that only have one possible candidate remaining, therefore, the solution of these are certain.
After this, it checks for Hidden Singles. These are candidates that only exist in a house(row, column, or box) only once. Since every house must contain 1 of each, these must be solutions.

Each time the program finds a solution, it reevaluates the candidates. This is necessary first to avoid errors, and secondly to not make it go through unnecessary processes.

If no more naked or hidden singles can be found, it gets into the more advanced methods in this order: naked pairs, hidden pairs, pointing pairs, box-line reductions, X-wings, XY-wings.

When I've made my first post, I was struggling with coding the XY-wing process, but it's already done, altough it's pretty much an overkill of a procedure that loops about 80000 times, but I didn't really find any way around this.

Here's how an XY-wing works:

You have a Hinge Cell, and two Wing Cells. Each Cell contain only two possible candidates, and these are related in a way like this: (a,b) (a,c) and (b,c). Which Cell is the Hinge and which the Wings are determined by the position of the Cells, because the Hinge can "see" both Wings, but the Wings can't see each other. This means that if the Hinge is (a,b), one Wing is (a,c) and the other is (b,c) then one of the wings must be a c. If the Hinge is a, then the first one must be a c, if it is a b, then the other must be a c. So then, from all the cells that both wings can see, c can be eliminated as a candidate. Now I don't know if there is a simple way to program that, my way is definitely not simple, but it works, and since the actual comparison and process is short, it still runs like a charm in less than a second despite the huge number of loops. Basically, I read the data of all the cells with two candidates into a two dimensional array and check for every possible combination of three of them whether they are valid or not, and if they do, then I call the elimination for the necessary cells.

Now all this was pretty unrelated to my question, it was just to demonstrate you how my program works in short and what I'm currently capable of programming.

Basically, I want to expand my program a bit because it still can't solve the hardest Sudokus. First I will add Triples, Quads, Simple Coluring, and XY-chains. Now I don't really have an issue with triples and quads, they work the same as pairs, it's only going to take longer to write it and that's all. Now with coluring and chains, that's a whole different story though because these are not so easily defined as the former methods, on a grid. There won't really be a "one way to go about it" for the program. It also must ignore possibilities meanwhile that might confuse the procedure and make it unnecessarily long. I have come across solvers that use these methods flawlessly so it's definitely not something impossible to code.

I'll provide a link of these strategies, and I'm just going to ask the question, is it sensible for me to try and code these strategies without the use of objects? I feel like I can't sidestep them anymore unless I really want my program to loop for even more, and I don't want that. It's ugly already as it is, the reason I haven't pasted the entire code here is because you probably wouldn't understand it. Not because it's so complex but because it's so damn ugly with sometimes 10 or more consecutive "end;"s in some procedures, not to mention the 5 or even more "for loops" and the other things that would make any serious programmer cry themselves to sleep if they looked at my code

Links:
http://www.sudokuwiki.org/Singles_Chains
http://www.sudokuwiki.org/XY_Chains

Thanks, in advance, peace