From f13c2770bc66de2d6171768d9fd810c53746b25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Elstr=C3=B6m?= Date: Wed, 8 Feb 2023 16:40:26 +0100 Subject: [PATCH] =?UTF-8?q?Test:=20Vier=20Diagonal=20nach=20links=20erkann?= =?UTF-8?q?t=20f=C3=BCr=20Spieler=201=20(gruen)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vier_gewinnt/JS/vierDiagonalLinks.js | 12 ++++++++++++ vier_gewinnt/tests/test_vierDiagonalLinks.test.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 vier_gewinnt/JS/vierDiagonalLinks.js create mode 100644 vier_gewinnt/tests/test_vierDiagonalLinks.test.js 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