From 95bc21aeb0568c14d90fd4606bae8b89115c6022 Mon Sep 17 00:00:00 2001 From: Abdullah Jamal Date: Thu, 8 Feb 2024 09:16:52 +0530 Subject: [PATCH] fix issues summary x ship lightning on sink, by shipId and not ship size. x rename density lens as density filter. x when density filter is switched on do not make background greenish. x check possible bug on statistics page, avg number of turns required to win. --- .gitignore | 3 ++- README.md | 2 +- js/classes/botClass.js | 2 +- js/classes/playerClass.js | 16 ++++++++-------- js/classes/shipClass.js | 11 +++++------ js/draw.js | 4 ---- js/setup/sketch.js | 2 +- js/states/singlePlayerState.js | 8 ++++---- js/states/winStateCall.js | 28 ++++++++++------------------ manifest.json | 34 +++++++++++++++++++++------------- 10 files changed, 53 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 91dfed8..14b0d37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -node_modules \ No newline at end of file +node_modules +*.zip \ No newline at end of file diff --git a/README.md b/README.md index c1a8d1f..d1f0e05 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ________________________________________________________________________________ * supports offline multi-player * supports game statistics * AI uses probability-density model to guess shot - * supports density lens option to reveal how the AI works internally + * supports density filter option to reveal how the AI works internally ________________________________________________________________________________________________________ ## Task List diff --git a/js/classes/botClass.js b/js/classes/botClass.js index e8634d2..450d09a 100644 --- a/js/classes/botClass.js +++ b/js/classes/botClass.js @@ -368,7 +368,7 @@ botClass.prototype.play = function () { this.currLife[this.gridActual[botHitX][botHitY] - 1]--; if (this.currLife[this.gridActual[botHitX][botHitY] - 1] <= 0) { triggerShipSunkAlert = true; - sunkShipSize = this.shipName[this.gridActual[botHitX][botHitY] - 1].size; + sunkShipId = this.shipName[this.gridActual[botHitX][botHitY] - 1].id; } else { triggerShipHitAlert = true; } diff --git a/js/classes/playerClass.js b/js/classes/playerClass.js index 6629aa1..3a1fefc 100644 --- a/js/classes/playerClass.js +++ b/js/classes/playerClass.js @@ -127,7 +127,7 @@ player.prototype.drawGridHidden = function () { ); } else { if ( - sunkShipSize === this.shipName[i].size && + sunkShipId === this.shipName[i].id && triggerShipSunkAlert === true && ((this.playerIs === 1 && playerOneTurn === false) || (this.playerIs === 2 && playerOneTurn == true)) && @@ -302,15 +302,15 @@ player.prototype.initializeGrid = function () { this.currLife = [2, 3, 3, 4, 5]; this.ship = [ //patrolBoat : - { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 } }, + { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 }, id: 1 }, //submarine : - { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 } }, + { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 }, id: 2 }, //destroyer : - { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 } }, + { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 }, id: 3 }, //battleship : - { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 } }, + { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 }, id: 4 }, //aircraftCarrier : - { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 } }, + { begin: { x: 0, y: 0 }, end: { x: 0, y: 0 }, id: 5 }, ]; this.sendHtppRequest = true; @@ -396,8 +396,8 @@ player.prototype.play = function (playerIs) { this.currLife[this.gridActual[i - 1][j - 1] - 1]--; if (this.currLife[this.gridActual[i - 1][j - 1] - 1] === 0) { triggerShipSunkAlert = true; - sunkShipSize = - this.shipName[this.gridActual[i - 1][j - 1] - 1].size; + sunkShipId = + this.shipName[this.gridActual[i - 1][j - 1] - 1].id; } else { triggerShipHitAlert = true; } diff --git a/js/classes/shipClass.js b/js/classes/shipClass.js index 3a6db28..3bc525b 100644 --- a/js/classes/shipClass.js +++ b/js/classes/shipClass.js @@ -2,18 +2,17 @@ var shipClass = function () { this.numberOfShips = 5; this.win = false; - // the begin and end coordinate in below array is for sending backend the coordinates of the ship this.shipName = [ //patrolBoat : - { color: { r: 0, g: 240, b: 0 }, size: 2 }, + { color: { r: 0, g: 240, b: 0 }, size: 2, id: 1 }, //submarine : - { color: { r: 153, g: 0, b: 204 }, size: 3 }, + { color: { r: 153, g: 0, b: 204 }, size: 3, id: 2 }, //destroyer : - { color: { r: 255, g: 0, b: 37 }, size: 3 }, + { color: { r: 255, g: 0, b: 37 }, size: 3, id: 3 }, //battleship : - { color: { r: 235, g: 104, b: 65 }, size: 4 }, + { color: { r: 235, g: 104, b: 65 }, size: 4, id: 4 }, //aircraftCarrier : - { color: { r: 255, g: 255, b: 0 }, size: 5 }, + { color: { r: 255, g: 255, b: 0 }, size: 5, id: 5 }, ]; }; diff --git a/js/draw.js b/js/draw.js index 4d9ea75..02dc7d8 100644 --- a/js/draw.js +++ b/js/draw.js @@ -30,10 +30,6 @@ var draw = function () { anim.animationPlay(); - if (densityLens) { - background(0, 300, 0, 100); - } - if (menu === true) { menuState(); } else if (makeNewMap === true) { diff --git a/js/setup/sketch.js b/js/setup/sketch.js index 5b78525..49c211c 100644 --- a/js/setup/sketch.js +++ b/js/setup/sketch.js @@ -39,7 +39,7 @@ var playerSwitchingIterator = 0; var shipHitAlertIterator = 0; var triggerShipHitAlert = false; var triggerShipSunkAlert = false; -var sunkShipSize = 0; +var sunkShipId = -1; var shipSunkAlertIterator = 0; var Base64 = { diff --git a/js/states/singlePlayerState.js b/js/states/singlePlayerState.js index fb79a6a..36f778d 100644 --- a/js/states/singlePlayerState.js +++ b/js/states/singlePlayerState.js @@ -1,7 +1,7 @@ var singlePlayerState = function () { // background(0, 255, 255,100); var backButton1 = new button("Exit", 350, 520); - var DensityLensButton = new button("Density Lens", 550, 520, 230); + var densityLensButton = new button("Density Filter", 550, 520, 230); backButton1.draw(); @@ -14,10 +14,10 @@ var singlePlayerState = function () { } else { player1.drawGridHidden(); - DensityLensButton.draw(); - if (DensityLensButton.insideButton()) { + densityLensButton.draw(); + if (densityLensButton.insideButton()) { if (!mouseIsPressed) { - DensityLensButton.lightUpButton(); + densityLensButton.lightUpButton(); } if (mouseIsPressed) { densityLens = !densityLens; diff --git a/js/states/winStateCall.js b/js/states/winStateCall.js index 38650e1..ce7c30f 100644 --- a/js/states/winStateCall.js +++ b/js/states/winStateCall.js @@ -36,17 +36,14 @@ var winStateCall = function () { bot.drawGridActual(); if (!statTableUpdated) { + // average turns to win + statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] * statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + player1.turn) / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + 1)); // opponent loses match statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesLost]++; - // matches won by player statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon]++; - // average turns to win - statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] += player1.turn; - statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] = roundTo(statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] / statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon]); - // win percentage statTable[statisticsEnum.row.Player1][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost])) * 100); statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesLost])) * 100); @@ -74,14 +71,12 @@ var winStateCall = function () { if (!statTableUpdated) { - statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesLost]++; + // average turns to win + statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] * statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + player1.turn) / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + 1)); + statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesLost]++; statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon]++; - // average turns to win - statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] += player1.turn; - statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] = roundTo(statTable[statisticsEnum.row.Player1][statisticsEnum.col.avgTurnsToWin] / statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon]); - // win percentage statTable[statisticsEnum.row.Player1][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost])) * 100.0); statTable[statisticsEnum.row.Player2][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesLost])) * 100.0); @@ -115,13 +110,12 @@ var winStateCall = function () { if (!statTableUpdated) { + // average turns to win + statTable[statisticsEnum.row.Player2][statisticsEnum.col.avgTurnsToWin] = roundTo((statTable[statisticsEnum.row.Player2][statisticsEnum.col.avgTurnsToWin] * statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] + player2.turn) / (statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] + 1) ); + statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon]++; statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost]++; - // average turns to win - statTable[statisticsEnum.row.Player2][statisticsEnum.col.avgTurnsToWin] += player2.turn; - statTable[statisticsEnum.row.Player2][statisticsEnum.col.avgTurnsToWin] = roundTo(statTable[statisticsEnum.row.Player2][statisticsEnum.col.avgTurnsToWin] / statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon]); - // win percentage statTable[statisticsEnum.row.Player2][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player2][statisticsEnum.col.matchesLost])) * 100.0); statTable[statisticsEnum.row.Player1][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost])) * 100.0); @@ -158,13 +152,11 @@ var winStateCall = function () { if (statTableUpdated === false) { + // average turns to win + statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.avgTurnsToWin] = roundTo((statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.avgTurnsToWin] * statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] + bot.turn )/( statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] + 1 )); statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon]++; statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost]++; - // average turns to win - statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.avgTurnsToWin] += bot.turn; - statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.avgTurnsToWin] = roundTo(statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.avgTurnsToWin] / statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon]); - // win percentage statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.botPlayer][statisticsEnum.col.matchesLost])) * 100); statTable[statisticsEnum.row.Player1][statisticsEnum.col.winPercentage] = roundTo((statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] / (statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesWon] + statTable[statisticsEnum.row.Player1][statisticsEnum.col.matchesLost])) * 100); diff --git a/manifest.json b/manifest.json index 18df070..2cf6c8f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,15 +1,23 @@ { - "name": "Battleship Game - Island Edition", - "version": "0.3", - "description": "Classic Battleship board game with special island edition and tough AI for your browser.", - "action": { - "default_popup": "index.html", - "default_title": "Battleship", - "default_icon": {"128": "assets/i128.png", "32": "assets/i32.png", "16": "assets/i16.png"} - }, - "icons": {"128": "assets/i128.png", "32": "assets/i32.png", "16": "assets/i16.png"}, - "manifest_version": 3, - "permissions": [ - "storage" - ] + "name": "Battleship Game - Island Edition", + "version": "0.3", + "description": "Classic Battleship board game with special island edition and tough AI for your browser.", + "action": { + "default_popup": "index.html", + "default_title": "Play Battleship", + "default_icon": { + "128": "assets/i128.png", + "32": "assets/i32.png", + "16": "assets/i16.png" + } + }, + "icons": { + "128": "assets/i128.png", + "32": "assets/i32.png", + "16": "assets/i16.png" + }, + "manifest_version": 3, + "permissions": [ + "storage" + ] } \ No newline at end of file