diff --git a/vier_gewinnt/JS/vierDiagonalLinks.js b/vier_gewinnt/JS/vierDiagonalLinks.js index e0d8369..18e8c79 100644 --- a/vier_gewinnt/JS/vierDiagonalLinks.js +++ b/vier_gewinnt/JS/vierDiagonalLinks.js @@ -4,7 +4,9 @@ function vierDiagonalLinks(allSpaltenArray) { 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; - } + }if (allSpaltenArray[j][i]===2 && allSpaltenArray[j+1][i-1]===2 && allSpaltenArray[j+2][i-2]===2 && allSpaltenArray[j+3][i-3]===2) { + Gewinner = 2; + } } } return Gewinner; diff --git a/vier_gewinnt/tests/test_vierDiagonalLinks.test.js b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js index 9d65ddf..1970e3a 100644 --- a/vier_gewinnt/tests/test_vierDiagonalLinks.test.js +++ b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js @@ -8,5 +8,17 @@ describe("Test Vier Gewinnt", () => { 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); + }) +}) + + +describe("Test Vier Gewinnt", () => { + it("Test vierDiagonalLinks: Vier Diagonal nach links erkennen und Gewinner 2(Rot) zuruek geben", () =>{ + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[1, 2, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 2, 2], [1, 2, 1, 2, 2, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[1, 1, 2, 1, 2, 2], [1, 2, 1, 2, 2, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 2, 0], [1, 2, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0]])).toBe(2); + }) }) \ No newline at end of file