diff --git a/index.html b/index.html
index e69de29..0a9cd71 100644
--- a/index.html
+++ b/index.html
@@ -0,0 +1,156 @@
+
+
+
+
+Strategy Grid
+
+
+
+
+Strategy Grid
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main.js b/main.js
index 3ec727d..c61fc4c 100644
--- a/main.js
+++ b/main.js
@@ -61,4 +61,96 @@ class Party {
}
}
}
+
+ step() {
+ const T = 5;
+ const R = 3;
+ const P = 1;
+ const S = 0;
+
+ const nbRound = 50;
+
+ let scores = [];
+
+ for (let i = 0; i < this.length; i++) {
+ scores[i] = [];
+ for (let j = 0; j < this.length; j++) {
+ scores[i][j] = 0;
+ }
+ }
+
+ // computing scores
+ for (let i = 0; i < this.length; i++) {
+ for (let j = 0; j < this.length; j++) {
+ for (let di = -1; di < 2; di++) {
+ for (let dj = -1; dj < 2; dj ++) {
+ if (di !== 0 || dj !== 0) {
+ const ni = (i + di + this.length) % this.length;
+ const nj = (j + dj + this.length) % this.length;
+
+ let playerHist = [];
+ let playerStrat = this.grid[i][j];
+
+ let foeHist = [];
+ let foeStrat = this.grid[ni][nj];
+
+ for (let k = 0; k < nbRound; k++) {
+ let playerMove = playerStrat(foeHist);
+ let foeMove = foeStrat(playerHist);
+
+ playerHist.push(playerMove);
+ foeHist.push(foeMove);
+
+ if (playerMove && foeMove) { // both shared
+ scores[i][j] += R;
+ scores[ni][nj] += R;
+ } else if (playerMove && !foeMove) { // player lose
+ scores[i][j] += S;
+ scores[ni][nj] += T;
+ } else if (!playerMove && foeMove) { // foe lose
+ scores[i][j] += T;
+ scores[ni][nj] += S;
+ } else { // both lose
+ scores[i][j] += P;
+ scores[ni][nj] += P;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ let newGrid = [];
+
+ for (let i = 0; i < this.length; i++) {
+ newGrid[i] = [];
+ for (let j = 0; j < this.length; j++) {
+ newGrid[i][j] = 0;
+ }
+ }
+
+ // changing strarts
+ for (let i = 0; i < this.length; i++) {
+ for (let j = 0; j < this.length; j++) {
+ let bestScore = scores[i][j];
+ newGrid[i][j] = this.grid[i][j];
+ for (let di = -1; di < 2; di++) {
+ for (let dj = -1; dj < 2; dj ++) {
+ if (di !== 0 || dj !== 0) {
+ const ni = (i + di + this.length) % this.length;
+ const nj = (j + dj + this.length) % this.length;
+
+ if (scores[ni][nj] > bestScore) { // someone has a better strategy
+ newGrid[i][j] = this.grid[ni][nj];
+ bestScore = scores[ni][nj];
+ }
+ }
+ }
+ }
+ }
+ }
+
+ this.grid = newGrid;
+ }
}
\ No newline at end of file