Browse Source
Merge branch 'main' of https://gitlab2.informatik.hs-fulda.de/fdai7359/gesellschaftsspiele-sammlung
main
Merge branch 'main' of https://gitlab2.informatik.hs-fulda.de/fdai7359/gesellschaftsspiele-sammlung
main
Richard Halsall
2 years ago
17 changed files with 264 additions and 48 deletions
-
8vier_gewinnt/JS/allSpaltenArrays.js
-
8vier_gewinnt/JS/gewinnErmitteln.js
-
9vier_gewinnt/JS/naechsteFreierPlatz.js
-
10vier_gewinnt/JS/regeln.js
-
9vier_gewinnt/JS/steinSetzen.js
-
23vier_gewinnt/JS/steineInReihe.js
-
10vier_gewinnt/JS/steineInSpalte.js
-
14vier_gewinnt/JS/vierDiagonalLinks.js
-
15vier_gewinnt/JS/vierDiagonalRechts.js
-
18vier_gewinnt/JS/vierInReihe.js
-
18vier_gewinnt/JS/vierInSpalte.js
-
8vier_gewinnt/tests/test_naechsterFreierPlatz.test.js
-
24vier_gewinnt/tests/test_vierDiagonalLinks.test.js
-
21vier_gewinnt/tests/test_vierDiagonalRechts.test.js
-
10vier_gewinnt/tests/test_vierInReihe.test.js
-
10vier_gewinnt/tests/test_vierInSpalte.test.js
-
97vier_gewinnt/vierGewinnt.html
@ -0,0 +1,8 @@ |
|||||
|
function allSpaltenArrays() { |
||||
|
var allSpaltenArray =[]; |
||||
|
for (let i = 1; i <= 7; i++) { |
||||
|
allSpaltenArray.push(steinInSpalte(i)) |
||||
|
} |
||||
|
|
||||
|
return allSpaltenArray |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
function gewinnErmitteln(spalte,reihe) { |
||||
|
if (vierInSpalte(steinInSpalte(spalte)) === 1 || vierInReihe(steinInReihe(reihe)) === 1 || vierDiagonalRechts(allSpaltenArrays()) === 1 || vierDiagonalLinks(allSpaltenArrays()) === 1) { |
||||
|
alert("Herzlichen Glückwunsch Spieler 1 (Grün) du hast gewonnen") |
||||
|
}if (vierInSpalte(steinInSpalte(spalte)) === 2 || vierInReihe(steinInReihe(reihe)) === 2 || vierDiagonalRechts(allSpaltenArrays()) === 2 || vierDiagonalLinks(allSpaltenArrays()) === 2){ |
||||
|
alert("Spieler 2 (Rot) hat gewonnen") |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
function ersterFreierPlatz(arr) { |
||||
|
for (let elem = 0; elem < arr.length; elem++) { |
||||
|
if (arr[elem] === 0) { |
||||
|
return elem+1; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
module.exports= ersterFreierPlatz; |
@ -0,0 +1,10 @@ |
|||||
|
function regelAnzeige() { |
||||
|
if (document.getElementById("regeln").innerHTML === '') { |
||||
|
document.getElementById("regelButton").innerHTML = "Regeln ausblenden"; |
||||
|
document.getElementById("regeln").innerHTML = "Vier Gewinnt ist ein Spiel, indem Spieler abwechseld Steine in Felder legen, wer als erstes vier Steine nebeneinader, übereinander oder diagonal hat, hat gewonnen."; |
||||
|
}else { |
||||
|
document.getElementById("regelButton").innerHTML = "Regeln anzeigen"; |
||||
|
document.getElementById("regeln").innerHTML = ""; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
function steinInReihe(reiheImFeld) { |
||||
|
// Feld mit Steinen in Reihe
|
||||
|
// O = kein Stein
|
||||
|
// 1 = gruener Stein
|
||||
|
// 2 = roter Stein
|
||||
|
var reihe = []; |
||||
|
|
||||
|
for (let i = 1; i <= 7; i++) { |
||||
|
var color = document.getElementById(reiheImFeld + "/" + i).style.backgroundColor; |
||||
|
|
||||
|
if (color == "red") { |
||||
|
reihe.push(2); |
||||
|
}else if (color == "green") { |
||||
|
reihe.push(1); |
||||
|
} else { |
||||
|
reihe.push(0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return reihe; |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
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; |
||||
|
}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; |
||||
|
} |
||||
|
module.exports = vierDiagonalLinks; |
@ -0,0 +1,15 @@ |
|||||
|
function vierDiagonalRechts(allSpaltenArray) { |
||||
|
var Gewinner =0; |
||||
|
for (let i = 0; i <= allSpaltenArray.length -3; 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; |
||||
|
} |
||||
|
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; |
||||
|
} |
||||
|
module.exports = vierDiagonalRechts; |
@ -0,0 +1,18 @@ |
|||||
|
function vierInReihe(arr){ |
||||
|
var Gewinner = 0; |
||||
|
//Spieler Gruen
|
||||
|
for (let i = 0; i < arr.length - 3; i++) { |
||||
|
if (arr[i] === 1 && arr[i + 1] === 1 && arr[i + 2] === 1 && arr[i + 3] === 1) { |
||||
|
Gewinner = 1; |
||||
|
} |
||||
|
} |
||||
|
//Spieler Rot
|
||||
|
for (let i = 0; i < arr.length - 3; i++) { |
||||
|
if (arr[i] === 2 && arr[i + 1] === 2 && arr[i + 2] === 2 && arr[i + 3] === 2) { |
||||
|
Gewinner = 2; |
||||
|
} |
||||
|
} |
||||
|
return Gewinner; |
||||
|
|
||||
|
} |
||||
|
module.exports = vierInReihe; |
@ -0,0 +1,18 @@ |
|||||
|
function vierInSpalte(arr){ |
||||
|
var Gewinner = 0; |
||||
|
//Spieler Gruen
|
||||
|
for (let i = 0; i < arr.length - 3; i++) { |
||||
|
if (arr[i] === 1 && arr[i + 1] === 1 && arr[i + 2] === 1 && arr[i + 3] === 1) { |
||||
|
Gewinner = 1; |
||||
|
} |
||||
|
} |
||||
|
//Spieler Rot
|
||||
|
for (let i = 0; i < arr.length - 3; i++) { |
||||
|
if (arr[i] === 2 && arr[i + 1] === 2 && arr[i + 2] === 2 && arr[i + 3] === 2) { |
||||
|
Gewinner = 2; |
||||
|
} |
||||
|
} |
||||
|
return Gewinner; |
||||
|
|
||||
|
} |
||||
|
module.exports = vierInSpalte; |
@ -0,0 +1,8 @@ |
|||||
|
const ersterFreierPlatz = require("../JS/naechsteFreierPlatz"); |
||||
|
|
||||
|
describe("Test Vier Gewinnt", () => { |
||||
|
it("Test welcher naechster platz ist frei", () =>{ |
||||
|
expect(ersterFreierPlatz([1, 1, 0, 0, 0, 0])).toBe(3); |
||||
|
expect(ersterFreierPlatz([1, 1, 2, 1, 0, 0])).toBe(5); |
||||
|
}) |
||||
|
}) |
@ -0,0 +1,24 @@ |
|||||
|
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); |
||||
|
|
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
|
||||
|
}) |
||||
|
}) |
@ -0,0 +1,21 @@ |
|||||
|
const vierDiagonalRechts = require("../JS/vierDiagonalRechts"); |
||||
|
|
||||
|
describe("Test Vier Gewinnt", () => { |
||||
|
it("Test vierDiagonalRechts: Vier Diagonal erkennen und Gewinner 1(Gruen) zuruek geben", () =>{ |
||||
|
expect(vierDiagonalRechts([[1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(1); |
||||
|
expect(vierDiagonalRechts([[1, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 1, 2, 1, 0], [2, 2, 1, 2, 1, 1], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(1); |
||||
|
expect(vierDiagonalRechts([[2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 2, 1, 0]])).toBe(1); |
||||
|
expect(vierDiagonalRechts([[2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 2, 1, 1, 0], [2, 2, 1, 2, 1, 1]])).toBe(1); |
||||
|
expect(vierDiagonalRechts([[2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 2, 1, 1, 0], [2, 2, 1, 2, 1, 1], [1, 0, 0, 0, 0, 0]])).toBe(1); |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
describe("Test Vier Gewinnt", () => { |
||||
|
it("Test vierDiagonalRechts: Vier Diagonal erkennen und Gewinner 2 (rot) zuruek geben", () =>{ |
||||
|
expect(vierDiagonalRechts([[2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); |
||||
|
expect(vierDiagonalRechts([[2, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 2, 2, 1, 2, 0], [1, 1, 2, 1, 2, 2], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); |
||||
|
expect(vierDiagonalRechts([[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 1, 2, 0]])).toBe(2); |
||||
|
expect(vierDiagonalRechts([[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 2, 1, 2, 2, 0], [1, 1, 2, 1, 2, 2]])).toBe(2); |
||||
|
expect(vierDiagonalRechts([[1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 2, 1, 2, 2, 0], [1, 1, 2, 1, 2, 2], [2, 0, 0, 0, 0, 0]])).toBe(2); |
||||
|
}) |
||||
|
}) |
@ -0,0 +1,10 @@ |
|||||
|
const vierInSpalte = require("../JS/vierInSpalte"); |
||||
|
|
||||
|
describe("Test Vier Gewinnt", () => { |
||||
|
it("Test vier Steine nebeneinander in einer Reihe vorhanden und gebe Gewinner 1 aus", () =>{ |
||||
|
expect(vierInSpalte([0, 1, 1, 1, 1, 0, 0])).toBe(1); |
||||
|
}) |
||||
|
it("Test vier Steine nebeneinander in einer Reihe vorhanden und gebe Gewinner 2 aus", () =>{ |
||||
|
expect(vierInSpalte([0, 0, 2, 2, 2, 2, 0])).toBe(2); |
||||
|
}) |
||||
|
}) |
@ -0,0 +1,10 @@ |
|||||
|
const vierInSpalte = require("../JS/vierInSpalte"); |
||||
|
|
||||
|
describe("Test Vier Gewinnt", () => { |
||||
|
it("Test vier Stein in einer Spalte vorhanden und gebe Gewinner 1 aus", () =>{ |
||||
|
expect(vierInSpalte([1, 1, 1, 1, 0, 0])).toBe(1); |
||||
|
}) |
||||
|
it("Test vier Stein in einer Spalte vorhanden und gebe Gewinner 2 aus", () =>{ |
||||
|
expect(vierInSpalte([0, 2, 2, 2, 2, 0])).toBe(2); |
||||
|
}) |
||||
|
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue