GithubHelp home page GithubHelp logo

sudoku1.0's Introduction

sudoku1.0

这次版本存在瑕疵,给用户填写的数独有不唯一解的可能,这将会在以后改进

1.界面展示

2.实现方法

2.1生成数独

(1)定义并初始化数组sudoku

var sudoku=[
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
     [0,0,0,0,0,0,0,0,0],
  ]; 

(2)执行generateSudoku()函数

function generateSudoku(){
    for(var i=1;i<10;i++){
      for(var j=0;j<9;j++){

      //把数字i填入第j个小九宫格中
        fillNumberInOneArray(i,j);
      }
    }
}

(3)fillNumberInOneArray(num,n)

①执行collectNumPosition(num,n)
      收集数字num在第n个九宫格上可以填入的位置
②执行flashBack(num,n)
       当数字num在第n个小九宫格上没有可以填入的位置时执行

(4)collectNumPosition(num,n)

①判断num在该行是否已填过
②判断num在该列上是否已填过
③判断该位置上是否有其他数字
④存入数组numPosition中

(4)flashBack(num,n)

①依次提取数组numPosition中的元素
②将导致程序无法进行的元素删除,直到找到合适的位置

2.2生成界面

根据用户选择的难度系数来决定要挖掉的格子数blank
随机生成blank个位置
在页面上渲染出除这bank个位置外,其他位置上的数字

2.3显示答案

将用户填入的数字存到数组userAnswer中
将userAnswer与sudoku进行对比
相同的显示为蓝色,不同的保留错误答案,并以红色显示

sudoku1.0's People

Contributors

michwh avatar

Watchers

新无止竞博客 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.