์๊ฐ
ํ ..... ๋๋ฌด ์ด๋ ค์ ๊ณ ๋ฌธ์ ๋ฅผ ์ดํดํ๋ ๊ฒ๋ถํฐ ํ๋ค์์ต๋๋ค. ํธ์ฆ๊น์ง๋ ๋ชป ํ์์ง๋ง Rook๊ณผ ๋๊ฐ์ ์
๊ดํ ๊ฒ์ ์๋ฃํด๋ณด์์ต๋๋ค. solves๋ ๋ชป ํ์๋ค๋ ๋น๋ฐ.....
hasRowConflictAt: function (rowIndex) { // ํ ์์ฒด์
// console.log("hasRow: ",this.attributes)
let chass = this.attributes[rowIndex];
// console.log(this.attributes) ์ฐ์ด๋ณด๋ฉด ์ ์ฌ๋ฐฐ์ด๋ก ์๋๊ฐ ๋์ต๋๋ค.
// ์ฌ๊ธฐ์, ์ฐจ๊ทผ์ฐจ๊ทผ ๊ฐ์ผํฉ๋๋ค.
// {0: Array(4), 1: Array(4), 2: Array(4), 3: Array(4), n: 4}
let count = 0;
// console.log('first',chass)
for(let i = 0 ; i < chass.length; i++){
// ๊ฐ ํ์ ๋๋ฉด์ 1์ ์ฐพ๊ฒ๋๋ฉด count๋ฅผ ๋๋ ค์ 2๊ฐ ๋๋ฉด true๋ฅผ ํด์ ธ์ ๋นจ๊ฐ๊ฒ ๋ง๋ญ๋๋ค.
if(chass[i] === 1){ // 0 1 0 0
count++; // 0 0 0 1
} // 1 0 0 0
} // 0 0 1 0
return count > 1; // fixme
}
* ์ ์ฒด ํ์ ๊ด๋ฆฌ
```javascript
hasAnyRowConflicts: function () { // ํ ์์ฒด์์ ์ฒดํฌ
let isConflict = false; // _.every ์ฒ๋ผ ํ๋ค๊ณ ์๊ฐํ์์ต๋๋ค.
let chassLength = this.attributes.n; // ๊ธธ์ด๋ง ๊ฐ์ ธ์ต๋๋ค.
for (let i = 0; i < chassLength; i++) { // ์์์ ์ฌ์ฉํ๊ฒ์ ํ ๋๋ก ๊ฒฐ๊ณผ ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
this.hasRowConflictAt(i) && (isConflict = true);
}
return isConflict; // fixme
},
์ธ๋ก ํ์ ์ฒ์์ ์ดํดํ๋๋ฐ ์กฐ๊ธ ์๊ฐ์ด ๊ฑธ๋ ธ์ต๋๋ค. key ๊ฐ์ ์์ง์ฌ ์ธ๋ก๋ก ๊ฐ๋ค๊ณ ์๊ฐํ์์ต๋๋ค.
hasColConflictAt: function (colIndex) {
let chass = this.attributes;
// console.log(chass)
let count = 0;
for(let key in chass){ // key 0, 1, 2, 3
if(chass[key][colIndex] === 1){
count++
}
}
return count > 1; // fixme
},
hasAnyColConflicts: function () { // ์์ ํ๋๊ฑฐ์ ๋๊ฐ์ด ํ๋ฉด ๋์๋ค.
let isConflict = false;
let chassLength = this.attributes.n;
for (let i = 0; i < chassLength; i++) {
this.hasColConflictAt(i) && (isConflict = true);
}
return isConflict; // fixme
},
i(ํ)์์ j(์ด)๋นผ์
hasMajorDiagonalConflictAt: function (majorDiagonalColumnIndexAtFirstRow) {
let chass = Object.values(this.attributes)
let chassLength = chass[4]
let count = 0;
// console.log('top', majorDiagonalColumnIndexAtFirstRow)
for (let i = 0; i < chassLength; i++ ){
for (let j = 0; j < chassLength; j++) {
if(i - j === majorDiagonalColumnIndexAtFirstRow && chass[j][i]){
count++
}
}
}
// [0, 1, 2, 3] [0,0,0,1]
// [-1,0, 1, 2] [0,0,0,1]
// [-2,-1,0, 1] [1,0,0,0]
// [-3,-2,-1,0] [0,1,0,0]
return count > 1 // fixme
},
ํน์ ๋ ธ๋์์ ์ ๋ง์ฑ์ ์ ๊ฒํ๊ณ , ์ ๋งํ์ง ์์ผ๋ฉด ๋ค์ ๋ ธ๋์ ๋ถ๋ชจ๋ก ๋์๊ฐ์ ๋ค์ ๋ ธ๋์ ๋ํ
๊ฒ์์ ๊ณ์ ํ๊ฒ๋๋ ์ ์ฐจ ์ ๋๋ค.