Browse Source

Test: Vier Diagonal nach links erkannt für Spieler 2 (rot)

main
Raphael Elström 2 years ago
parent
commit
618debcb06
  1. 4
      vier_gewinnt/JS/vierDiagonalLinks.js
  2. 12
      vier_gewinnt/tests/test_vierDiagonalLinks.test.js

4
vier_gewinnt/JS/vierDiagonalLinks.js

@ -4,7 +4,9 @@ function vierDiagonalLinks(allSpaltenArray) {
for (let j = 0; j <= allSpaltenArray[0].length -3; j++) { 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) { 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; 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; return Gewinner;

12
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([[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); 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);
}) })
}) })
Loading…
Cancel
Save