Software Engineering Fundamentals Project - Sudoku Problem

Github project address: https://github.com/WX78yyj/sudoku (Because I have a bad habit of not naming names, so I forgot to name it, and the submitted file name is Unnamed 3, I found that I can't change it, depressed)

PSP2.1

Personal Software Process Stages

Estimated time (minutes)

Actual time (minutes)

Planning

plan

60

 

Estimate

Estimate how long this task will take

15

 

Development

develop

400

 

Analysis

Needs analysis (including learning new technologies)

115

 

Design Spec

Generate design documentation

60

 

Design Review

Design Review (review design documents with colleagues)

30

 

Coding Standard

Code Specifications (to develop appropriate specifications for current development)

15

 

Design

specific design

200

 

Coding

specific code

210

 

Code Review

code review

200

 

Test

Testing (self-testing, modifying code, committing changes)

15

 

Reporting

Report

30

 

Test Report

testing report

30

 

Size Measurement

Computational workload

15

 

Postmortem & Process lmprovement Plan

Post-event summary and process improvement plan

15

 

 

total

1000

 

Briefly talk about the estimated time arrangement, make a plan in two hours, estimate the time, etc., in fact, it is not so detailed, because there are many softwares that have not been used or even heard of many things, so at the beginning, my heart was actually It was very frustrating, so the progress was very slow at the beginning, and many times I didn’t know what to do. Even if there was a detailed plan from the teacher, I originally planned to use it for one hour a day, but in fact, the effective use of time may be less than half. In the above table, many parts of the time are overlapping, so the real total time is about 700 minutes, coupled with such a low time utilization efficiency, in fact, the work that can be completed quickly ended up being done for more than four weeks. It was made by my roommate who taught me to do it, so my heart was actually very uncomfortable. Even though I did it seriously, I still didn’t know anything. I really felt that it was pointless to continue learning.

After I first got the title, wow, I was at a loss. The above requirements are completely incomprehensible, pass, pass. When it comes to the specific problem, the Sudoku problem, yes, I understand what to do, but what is going on with the file, I haven't dealt with it before. And also requires that you must use Visual Studio. Although we have been asked to use Visual Studio, I have been using DEV c++ without any problems before, and I have to download and adapt to new programming tools. It can be said that a lot of time is wasted on the use and learning of Visual Studio. . After that, there are still so many people who don't understand, God is annoying. So I decided to solve the Sudoku problem first. At the beginning, I thought about it and had some ideas, but I found that it was very troublesome to implement. So I went to the Internet to collect some methods about generating and solving Sudoku. Regarding the generation of Sudoku, there are many methods, but it is difficult to implement with code, and there is another problem, that is, it is difficult to ensure that the generated endings are not repeated. Later came across a simple way to achieve 10 6 different endgames online. Fix the first position (required by the title), and arrange all the remaining 8 numbers, so there are 8! = 40320 different first lines, and then push the first line back by 3, 6, 1, 4, 7, 2, 5, and 8, respectively, to generate a qualified finale. Next, you can transform each endgame and find that after exchanging the vertical lines of the endgame with each other, it actually changes the order of the full arrangement, and cannot generate a new endgame. In this way, only the rows or 3*3 blocks are exchanged, compared to The exchange of blocks, the exchange of lines is easier, and the three lines in each block are exchanged with each other, and it is still guaranteed that the end of Sudoku will be generated, and there will be no repetition. Because the first row can't move. There are 2 cases for the second and third rows, 6 for 4, 5, 6, and the same for 7, 8, 9, so each final game can be transformed into 2*3*3=72 cases. 72*40320=2903040 cases, which fully meet the requirements.

void quanpai(int x)//Generate 8-bit full array, the first position is fixed, x is the number of digits, and each time a new number is selected from the number that has not been selected
{
 if (x == 9)
 {
  for (int i = 1; i <= 9; i++)
   Fist[m][i] = F[i];
  m++;
  return ;
 }
 else
 {
  int k;
  for (int i = x; i <=9; i++)
  {
   k = F[x];
   F[x] = F[i];
   F[i] = k;
   quanpai(x + 1);
   k = F[i];
   F[i] = F[x];
   F[x] = k;
  }
  return ;
 }
}

The method of generating other endings for each Sudoku end can be achieved simply by using loops, but the generation of all permutations really stumped me. Finally, with the help of my classmates, I realized it through recursion.

Regarding solving Sudoku, there are many methods and techniques for solving Sudoku. At first, I always regarded it as a game, trying to achieve a simple solution of Sudoku through some rules and tricks, but in the end I gave up, some skills are really useful , but it is not easy to realize by computer, similar to Gongsuiyu solution, digital elimination, it is quite troublesome to realize. In particular, we need to combine those methods, and most of these methods are to find all solutions, and our requirement is to find only one group, so we use the method of backtracking, and fill in every time a new space is found. A number, continue to meet the conditions, even if the grid is full, even if a feasible solution is found, output, otherwise change the number, or go back and change the unreasonable part before.

void result(int i,int j)
{
 if (i == 9 && j == 0)
 {
  flag = 1;
  return;
 }
 if (a[i][j] != 0)
 {  ans[i][j] = a[i][j];
  if (j < 8)
   result(i, j + 1);
  else
   result(i + 1, 0);
  if (flag)
   return;
 }
 else
 {
  for (int k = 1,x,y; k <= 9; k++)
  {
   for (x = 0; x <= 8; x++)
    if (a[x][j] == k)
     break;
   for (y = 0; y <= 8; y++)
    if (a[i][y] == k)
     break;
   if (y == 9 && x == 9)
   {
    for (x = (i / 3) * 3; x <= (i / 3) * 3 + 2; x++)
    {
     for (y = (j / 3) * 3; y <= (j / 3) * 3 + 2; y++)
     {
      if (a[x][y] == k)
       y = x = 100;
     }
    }
     if (x == (i / 3) * 3 + 3 && y == (j / 3) * 3 + 3)
      {
       a[i][j] = k;
       ans[i][j] = a[i][j];
       if (j < 8)
        result(i, j + 1);
       else
        result(i + 1, 0);
       if (flag)
        return;
       a[i][j] = 0;
      }
   }
  }
 }
}

A total of five functions are used to complete the generation of full permutation and the generation of Sudoku finals, realize backtracking and judge whether the rules are met, the main function calls these functions to achieve the final effect, and read and write files from the file. operate. Because there is no habit of drawing flowcharts, before writing functions, it is usually assumed that the required steps are roughly completed, and they are written directly after preliminary determination, and they are continuously optimized and improved during the writing process, and finally the code that can complete the task is written.

PSP2.1

Personal Software Process Stages

Estimated time (minutes)

Actual time (minutes)

Planning

plan

60

100

Estimate

Estimate how long this task will take

15

30

Development

develop

40

100

Analysis

Needs analysis (including learning new technologies)

115

150

Design Spec

Generate design documentation

60

50

Design Review

Design Review (review design documents with colleagues)

30

50

Coding Standard

Code Specifications (to develop appropriate specifications for current development)

15

10

Design

specific design

200

290

Coding

specific code

210

250

Code Review

code review

200

210

Test

Testing (self-testing, modifying code, committing changes)

15

30

Reporting

Report

30

60

Test Report

testing report

30

30

Size Measurement

Computational workload

15

20

Postmortem & Process lmprovement Plan

Post-event summary and process improvement plan

15

20

 

total

1000

1360

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324608063&siteId=291194637