diff --git a/vier_gewinnt/JS/vierDiagonalLinks.js b/vier_gewinnt/JS/vierDiagonalLinks.js new file mode 100644 index 0000000..e0d8369 --- /dev/null +++ b/vier_gewinnt/JS/vierDiagonalLinks.js @@ -0,0 +1,12 @@ +function vierDiagonalLinks(allSpaltenArray) { + var Gewinner =0; + for (let i = 3; i <= allSpaltenArray.length; i++) { + for (let j = 0; j <= allSpaltenArray[0].length -3; j++) { + if (allSpaltenArray[j][i]===1 && allSpaltenArray[j+1][i-1]===1 && allSpaltenArray[j+2][i-2]===1 && allSpaltenArray[j+3][i-3]===1) { + Gewinner = 1; + } + } + } + return Gewinner; +} +module.exports = vierDiagonalLinks; \ No newline at end of file diff --git a/vier_gewinnt/tests/test_vierDiagonalLinks.test.js b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js new file mode 100644 index 0000000..9d65ddf --- /dev/null +++ b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js @@ -0,0 +1,12 @@ +const vierDiagonalLinks = require("../JS/vierDiagonalLinks"); + +describe("Test Vier Gewinnt", () => { + it("Test vierDiagonalLinks: Vier Diagonal nach links erkennen und Gewinner 1(Gruen) zuruek geben", () =>{ + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]])).toBe(1); + expect(vierDiagonalLinks([[2, 1, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(1); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 1, 1], [2, 1, 2, 1, 1, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 0, 0, 0]])).toBe(1); + expect(vierDiagonalLinks([[2, 2, 1, 2, 1, 1], [2, 1, 2, 1, 1, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(1); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 1, 0], [2, 1, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]])).toBe(1); + + }) +}) \ No newline at end of file