JSFiddle - React, Tailwind, and code Playground

by Researcher

HTML

<!DOCTYPE HTML>

<html>

<head>

    <meta content="text/html; charset=UTF-8"> 

<script type="text/javascript">


</script>

</head>

<body onload="main();">

   <canvas id="mycanvas"></canvas>



<div id="to">



</div> 





</body>



</html>







</body>

</html>

JavaScript

// 8 Queen


function Queen(column, QueenObj){

        // поля данных

    var canvas = document.getElementById('mycanvas');



    // use getContext to use the canvas for drawing

    var ctx = canvas.getContext('2d');



        this.row = 1;

        this.column = column;

        this.neighbor = QueenObj;

        // поиск и печать решения

        this.findSolution = function(){

                // проверить позицию, не атакуют ли соседи

                while(this.neighbor && this.neighbor.canAttack(this.row, this.column)){

                        if(!this.advance())

                        return false;

                }

                        //решение найдено

                return true;

        

        }

        this.advance = function(){

                if(this.row < 8){

                        this.row++;

                        return this.findSolution();

                }

                if(this.neighbor && !this.neighbor.advance())

                        return false;

                this.row = 1;

                return this.findSolution();

        }

        this.print = function(){

                if(this.neighbor)

                        this.neighbor.print();

                print("column = " + this.column + " row = " + this.row);

        }

        this.getPosition = function(theArray){

                if(this.neighbor)

                        this.neighbor.getPosition(theArray);

                var positionData = {"column":this.column, "row":this.row};

                theArray.push(positionData);

        }

        

        // внутренний метод

        this.canAttack = function(testRow, testColumn){

                // проверка горизонтали

                if(this.row == testRow)

                return true;

                // проверка диагоналей

                var columnDifference = testColumn - this.column

                if((this.row + columnDifference == testRow) || (this.row - columnDifference ==...