From d63e70714603032e2ed5121961347a532fb611b9 Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:39:44 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E7=89=A9=E4=BD=93=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?(=E4=BB=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/patterns.js | 284 +++++++++++++++++++++++++++++++++++ src/life-game/life-game.html | 3 +- src/life-game/life-game.js | 40 +++++ 3 files changed, 326 insertions(+), 1 deletion(-) create mode 100644 src/lib/patterns.js diff --git a/src/lib/patterns.js b/src/lib/patterns.js new file mode 100644 index 0000000..2c7381c --- /dev/null +++ b/src/lib/patterns.js @@ -0,0 +1,284 @@ +//defaultBoardSize = 20 では収まらないパターンもあるので注意 + +export const patterns = { + + //振動子, Oscillators + pulsar: { + names: { + en: "Pulsar", + ja: "パルサー" + }, + shape: [ + [0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0] + ] + }, + pentadecathlon: { + names: { + en: "Pentadecathlon", + ja: "ペンタデカスロン" + }, + shape: [ + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [1, 1, 0, 1, 1, 1, 1, 0, 1, 1], + [0, 0, 1, 0, 0, 0, 0, 1, 0, 0] + ] + }, + galaxy: { + names: { + en: "Galaxy", + ja: "銀河" + }, + shape: [ + [1, 1, 1, 1, 1, 1, 0, 1, 1], + [1, 1, 1, 1, 1, 1, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 1, 1, 1, 1, 1, 1], + [1, 1, 0, 1, 1, 1, 1, 1, 1] + ] + }, + octagon: { + names: { + en: "Octagon", + ja: "八角形" + }, + shape: [ + [0, 0, 1, 1, 0, 0], + [0, 1, 0, 0, 1, 0], + [1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1], + [0, 1, 0, 0, 1, 0], + [0, 0, 1, 1, 0, 0] + ] + }, + figureEight: { + names: { + en: "Figure eight", + ja: "8の字" + }, + shape: [ + [0, 0, 1, 1, 1, 0], + [0, 0, 1, 0, 1, 0], + [0, 0, 1, 0, 1, 0], + [0, 1, 0, 1, 0, 0], + [0, 1, 0, 1, 0, 0], + [0, 1, 1, 1, 0, 0] + ] + }, + tumbler: { + names: { + en: "Tumbler", + ja: "タンブラー" + }, + shape: [ + [0, 1, 1, 0, 1, 1, 0], + [0, 1, 1, 0, 1, 1, 0], + [0, 0, 1, 0, 1, 0, 0], + [1, 0, 1, 0, 1, 0, 1], + [1, 1, 1, 0, 1, 1, 1] + ] + }, + barberPole: { + names: { + en: "Barber's pole", + ja: "床屋の看板" + }, + shape: [ + [0, 0, 1, 1, 0, 0], + [0, 1, 0, 0, 1, 0], + [0, 1, 0, 0, 1, 0], + [0, 0, 1, 1, 0, 0] + ] + }, + clock: { + names: { + en: "Clock", + ja: "時計" + }, + shape: [ + [0, 0, 1, 0], + [0, 1, 0, 1], + [0, 1, 0, 1], + [0, 0, 1, 0] + ] + }, + hertzOscillator: { + names: { + en: "Hertz oscillator", + ja: "ヘルツ振動子" + }, + shape: [ + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0] + ] + }, + + //移動物体, Spaceships + glider: { + names: { + en: "Glider", + ja: "グライダー" + }, + shape: [ + [0, 1, 0], + [0, 0, 1], + [1, 1, 1] + ] + }, + lightweightSpaceship: { + names: { + en: "Lightweight Spaceship (LWSS)", + ja: "軽量級宇宙船" + }, + shape: [ + [0, 1, 0, 0, 1], + [1, 0, 0, 0, 0], + [1, 0, 0, 0, 1], + [1, 1, 1, 1, 0] + ] + }, + middleweightSpaceship: { + names: { + en: "Middleweight Spaceship (MWSS)", + ja: "中量級宇宙船" + }, + shape: [ + [0, 1, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 0] + ] + }, + heavyweightSpaceship: { + names: { + en: "Heavyweight Spaceship (HWSS)", + ja: "重量級宇宙船" + }, + shape: [ + [0, 1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1, 0] + ] + }, + shuttle: { + names: { + en: "Shuttle", + ja: "シャトル" + }, + shape: [ + [1, 1, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 1, 1] + ] + }, + + //繁殖型, Breeders + gosperGliderGun: { + names: { + en: "Gosper Glider Gun", + ja: "グライダー銃" + }, + shape: [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + ] + }, + PufferTrain: { + names: { + en: "Puffer Train", + ja: "シュシュポッポ列車" + }, + shape: [ + [0,0,0,1,0], + [0,0,0,0,1], + [1,0,0,0,1], + [0,1,1,1,1], + [0,0,0,0,0], + [0,0,0,0,0], + [0,0,0,0,0], + [1,0,0,0,0], + [0,1,1,0,0], + [0,0,1,0,0], + [0,0,1,0,0], + [0,1,0,0,0], + [0,0,0,0,0], + [0,0,0,0,0], + [0,0,0,1,0], + [0,0,0,0,1], + [1,0,0,0,1], + [0,1,1,1,1], + ] + }, + Max: { + names: { + en: "Max", + ja: "マックス" + }, + shape: [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0,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ff --git a/src/life-game/life-game.html b/src/life-game/life-game.html index 4b35c51..0afe1bc 100644 --- a/src/life-game/life-game.html +++ b/src/life-game/life-game.html @@ -14,6 +14,7 @@

>             - +
+ diff --git a/src/life-game/life-game.js b/src/life-game/life-game.js index 8b00709..b299c83 100644 --- a/src/life-game/life-game.js +++ b/src/life-game/life-game.js @@ -1,4 +1,5 @@ "use strict"; +import { patterns } from "$lib/patterns.js"; let timerId = 0; let timer = "stop"; let generationFigure = 0; @@ -164,3 +165,42 @@ function progressBoard() { generationChange(generationFigure + 1); renderBoard(); } + +function placePattern(patternKey) { + const newBoard = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); + const patternData = patterns[patternKey]; + if (!patternData) { + console.error("パターンが見つかりません:", patternKey); + return; + } + const patternShape = patternData.shape; + const patternHeight = patternShape.length; + const patternWidth = patternShape[0].length; + if (boardSize < patternHeight || boardSize < patternWidth) { + console.error("盤面が小さすぎます:", patternKey); + return; + } + const startCol = Math.floor((20 - patternWidth) / 2); + const startRow = Math.floor((20 - patternHeight) / 2); + for (let r = 0; r < patternHeight; r++) { + for (let c = 0; c < patternWidth; c++) { + const boardCol = startCol + c; + const boardRow = startRow + r; + newBoard[boardCol][boardRow] = (patternShape[r][c] === 1); + } + } + board = newBoard; + renderBoard(); + generationChange(0); + stop(); +} + +const buttonContainer = document.getElementById('button-container'); +for (const patternKey in patterns) { + const button = document.createElement('button'); + button.textContent = patterns[patternKey].names[ja]; + button.onclick = () => { + placePattern(patternKey) + }; + buttonContainer.appendChild(button); +} \ No newline at end of file From 3f6618724f94aa0e268cbd0ea81e749a0c2736f2 Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:56:24 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E8=BB=BD=E5=BE=AE=E3=81=AA=E3=83=9F?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/life-game/life-game.html | 2 +- src/life-game/life-game.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/life-game/life-game.html b/src/life-game/life-game.html index 0afe1bc..8406a92 100644 --- a/src/life-game/life-game.html +++ b/src/life-game/life-game.html @@ -14,7 +14,7 @@

>             -
+
diff --git a/src/life-game/life-game.js b/src/life-game/life-game.js index b299c83..f9144bd 100644 --- a/src/life-game/life-game.js +++ b/src/life-game/life-game.js @@ -198,7 +198,7 @@ function placePattern(patternKey) { const buttonContainer = document.getElementById('button-container'); for (const patternKey in patterns) { const button = document.createElement('button'); - button.textContent = patterns[patternKey].names[ja]; + button.textContent = patterns[patternKey].names["ja"]; button.onclick = () => { placePattern(patternKey) }; From 25a76482941d16d57acd624f9057fc6be39afd96 Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Tue, 21 Oct 2025 17:54:43 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=83=91=E3=82=BF=E3=83=BC=E3=83=B3?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/patterns.js | 311 +++++++++++++++++++++++++------------ src/life-game/life-game.js | 26 ++-- 2 files changed, 221 insertions(+), 116 deletions(-) diff --git a/src/lib/patterns.js b/src/lib/patterns.js index 2c7381c..e504256 100644 --- a/src/lib/patterns.js +++ b/src/lib/patterns.js @@ -1,13 +1,15 @@ -//defaultBoardSize = 20 では収まらないパターンもあるので注意 +//(注)minBoardSizeは、パターンが余裕をもって変形できるために必要なボードのサイズを表し、パターン自体より大きい。 export const patterns = { //振動子, Oscillators pulsar: { + //周期3 names: { en: "Pulsar", ja: "パルサー" }, + minBoardSize: 20, shape: [ [0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -25,10 +27,12 @@ export const patterns = { ] }, pentadecathlon: { + //周期15 names: { en: "Pentadecathlon", ja: "ペンタデカスロン" }, + minBoardSize: 20, shape: [ [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [1, 1, 0, 1, 1, 1, 1, 0, 1, 1], @@ -36,10 +40,12 @@ export const patterns = { ] }, galaxy: { + //周期8 names: { en: "Galaxy", ja: "銀河" }, + minBoardSize: 20, shape: [ [1, 1, 1, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 1, 1], @@ -53,86 +59,100 @@ export const patterns = { ] }, octagon: { + //周期5 names: { en: "Octagon", ja: "八角形" }, + minBoardSize: 20, shape: [ - [0, 0, 1, 1, 0, 0], - [0, 1, 0, 0, 1, 0], - [1, 0, 0, 0, 0, 1], - [1, 0, 0, 0, 0, 1], - [0, 1, 0, 0, 1, 0], - [0, 0, 1, 1, 0, 0] + [0, 0, 0, 1, 1, 0, 0, 0], + [0, 0, 1, 0, 0, 1, 0, 0], + [0, 1, 0, 0, 0, 0, 1, 0], + [1, 0, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 0, 1], + [0, 1, 0, 0, 0, 0, 1, 0], + [0, 0, 1, 0, 0, 1, 0, 0], + [0, 0, 0, 1, 1, 0, 0, 0] ] }, figureEight: { + //周期8 names: { en: "Figure eight", ja: "8の字" }, + minBoardSize: 20, shape: [ - [0, 0, 1, 1, 1, 0], - [0, 0, 1, 0, 1, 0], - [0, 0, 1, 0, 1, 0], - [0, 1, 0, 1, 0, 0], - [0, 1, 0, 1, 0, 0], - [0, 1, 1, 1, 0, 0] + [1, 1, 1, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [0, 0, 0, 1, 1, 1], + [0, 0, 0, 1, 1, 1], + [0, 0, 0, 1, 1, 1] ] }, tumbler: { + //周期14 names: { en: "Tumbler", ja: "タンブラー" }, + minBoardSize: 20, shape: [ [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1], - [1, 1, 1, 0, 1, 1, 1] + [1, 0, 1, 0, 1, 0, 1], + [1, 1, 0, 0, 0, 1, 1] ] }, barberPole: { + //周期2 names: { en: "Barber's pole", ja: "床屋の看板" }, + minBoardSize: 20, shape: [ - [0, 0, 1, 1, 0, 0], - [0, 1, 0, 0, 1, 0], - [0, 1, 0, 0, 1, 0], - [0, 0, 1, 1, 0, 0] + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] }, clock: { + //周期4 names: { en: "Clock", ja: "時計" }, + minBoardSize: 20, shape: [ - [0, 0, 1, 0], - [0, 1, 0, 1], - [0, 1, 0, 1], - [0, 0, 1, 0] - ] - }, - hertzOscillator: { - names: { - en: "Hertz oscillator", - ja: "ヘルツ振動子" - }, - shape: [ - [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0, 0, 0] + [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1], + [0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1], + [1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0], + [1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0] ] }, @@ -142,6 +162,7 @@ export const patterns = { en: "Glider", ja: "グライダー" }, + minBoardSize: 20, shape: [ [0, 1, 0], [0, 0, 1], @@ -150,9 +171,10 @@ export const patterns = { }, lightweightSpaceship: { names: { - en: "Lightweight Spaceship (LWSS)", + en: "Lightweight Spaceship", ja: "軽量級宇宙船" }, + minBoardSize: 20, shape: [ [0, 1, 0, 0, 1], [1, 0, 0, 0, 0], @@ -162,10 +184,12 @@ export const patterns = { }, middleweightSpaceship: { names: { - en: "Middleweight Spaceship (MWSS)", + en: "Middleweight Spaceship", ja: "中量級宇宙船" }, + minBoardSize: 20, shape: [ + [0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1], @@ -174,10 +198,12 @@ export const patterns = { }, heavyweightSpaceship: { names: { - en: "Heavyweight Spaceship (HWSS)", + en: "Heavyweight Spaceship", ja: "重量級宇宙船" }, + minBoardSize: 20, shape: [ + [0, 0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1], @@ -189,14 +215,36 @@ export const patterns = { en: "Shuttle", ja: "シャトル" }, + minBoardSize: 30, shape: [ - [1, 1, 0, 0, 0, 0, 0], - [1, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 1, 1], - [0, 0, 0, 0, 0, 1, 1] + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], + [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + ] + }, + Pufferfish: { + names: { + en: "Pufferfish", + ja: "パファーフィッシュ" + }, + minBoardSize: 40, + shape: [ + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], + [0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0], + [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0], + [1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1], + [1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], ] }, @@ -206,6 +254,7 @@ export const patterns = { en: "Gosper Glider Gun", ja: "グライダー銃" }, + minBoardSize: 40, shape: [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -218,67 +267,123 @@ export const patterns = { [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] }, - PufferTrain: { + Max: { names: { - en: "Puffer Train", - ja: "シュシュポッポ列車" + en: "Max", + ja: "マックス" }, + minBoardSize: 60, shape: [ - [0,0,0,1,0], - [0,0,0,0,1], - [1,0,0,0,1], - [0,1,1,1,1], - [0,0,0,0,0], - [0,0,0,0,0], - [0,0,0,0,0], - [1,0,0,0,0], - [0,1,1,0,0], - [0,0,1,0,0], - [0,0,1,0,0], - [0,1,0,0,0], - [0,0,0,0,0], - [0,0,0,0,0], - [0,0,0,1,0], - [0,0,0,0,1], - [1,0,0,0,1], - [0,1,1,1,1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0], + [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1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, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] }, - Max: { + + //長寿型, Methuselah + Thunderbird: { + //寿命243 names: { - en: "Max", - ja: "マックス" + en: "Thunderbird", + ja: "サンダーバード" }, + minBoardSize: 60, shape: [ - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + [1, 1, 1], + [0, 0, 0], + [0, 1, 0], + [0, 1, 0], + [0, 1, 0] + ] + }, + //寿命128 + Herschel: { + names: { + en: "Herschel", + ja: "ハーシェル" + }, + minBoardSize: 60, + shape: [ + [1, 0, 0], + [1, 1, 1], + [1, 0, 1], + [0, 0, 1] + ] + }, + //寿命148 + BHeptomino: { + names: { + en: "B-Heptomino", + ja: "Bヘプトミノ" + }, + minBoardSize: 60, + shape: [ + [1, 0, 1, 1], + [1, 1, 1, 0], + [0, 1, 0, 0] + ] + }, + //寿命130 + DieHard: { + names: { + en: "Die Hard", + ja: "ダイハード" + }, + minBoardSize: 60, + shape: [ + [0, 0, 0, 0, 0, 0, 1, 0], + [1, 1, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 1, 1, 1] + ] + }, + //寿命1103 + RPentomino: { + names: { + en: "R-Pentomino", + ja: "Rペントミノ" + }, + minBoardSize: 150, + shape: [ + [0, 1, 1], + [1, 1, 0], + [0, 1, 0] + ] + }, + Acorn: { + //寿命5206 + names: { + en: "Acorn", + ja: "どんぐり" + }, + minBoardSize: 300, + shape: [ + [0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0], + [1, 1, 0, 0, 1, 1, 1] ] } }; \ No newline at end of file diff --git a/src/life-game/life-game.js b/src/life-game/life-game.js index f9144bd..5f49126 100644 --- a/src/life-game/life-game.js +++ b/src/life-game/life-game.js @@ -169,24 +169,17 @@ function progressBoard() { function placePattern(patternKey) { const newBoard = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); const patternData = patterns[patternKey]; - if (!patternData) { - console.error("パターンが見つかりません:", patternKey); - return; - } const patternShape = patternData.shape; const patternHeight = patternShape.length; const patternWidth = patternShape[0].length; - if (boardSize < patternHeight || boardSize < patternWidth) { - console.error("盤面が小さすぎます:", patternKey); - return; - } - const startCol = Math.floor((20 - patternWidth) / 2); - const startRow = Math.floor((20 - patternHeight) / 2); + //↓パターンがボードの中央に来るよう、パターンの右上のセルの位置(startrow,startCol)を調整 + const startRow = Math.floor((boardSize - patternHeight) / 2); + const startCol = Math.floor((boardSize - patternWidth) / 2); for (let r = 0; r < patternHeight; r++) { for (let c = 0; c < patternWidth; c++) { - const boardCol = startCol + c; const boardRow = startRow + r; - newBoard[boardCol][boardRow] = (patternShape[r][c] === 1); + const boardCol = startCol + c; + newBoard[boardRow][boardCol] = (patternShape[r][c] === 1); } } board = newBoard; @@ -197,10 +190,17 @@ function placePattern(patternKey) { const buttonContainer = document.getElementById('button-container'); for (const patternKey in patterns) { + const patternData = patterns[patternKey]; const button = document.createElement('button'); - button.textContent = patterns[patternKey].names["ja"]; + button.textContent = patternData.names["ja"]; button.onclick = () => { placePattern(patternKey) }; + //↓ボードに収まるパターンのみクリック可能にする + const requiredSize = patternData.minBoardSize || 0; + if (boardSize < requiredSize) { + button.disabled = true; + button.title = `このパターンには ${requiredSize}x${requiredSize} 以上の盤面が必要です`; + } buttonContainer.appendChild(button); } \ No newline at end of file From 19f1e721ed5fc910c538a4133f353adda9b959e9 Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Tue, 21 Oct 2025 19:31:09 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E3=83=9C=E3=83=BC=E3=83=89=E3=82=B5?= =?UTF-8?q?=E3=82=A4=E3=82=BA=E5=A4=89=E6=9B=B4=E6=A9=9F=E8=83=BD=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/life-game/life-game.html | 4 +- src/life-game/life-game.js | 73 +++++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/life-game/life-game.html b/src/life-game/life-game.html index 8406a92..e7ab551 100644 --- a/src/life-game/life-game.html +++ b/src/life-game/life-game.html @@ -8,13 +8,15 @@

第0世代
停止中

+ ボードのサイズ: +
                   -
+
diff --git a/src/life-game/life-game.js b/src/life-game/life-game.js index 5f49126..aab6bac 100644 --- a/src/life-game/life-game.js +++ b/src/life-game/life-game.js @@ -6,6 +6,8 @@ let generationFigure = 0; //定数 const defaultBoardSize = 20; +const boardSizeMax = 300; +const boardSizeMin = 10; const defaultLiveAroundMax = 3; const defaultLiveAroundMin = 2; const defaultDeadAroundMax = 3; @@ -43,6 +45,18 @@ const startButton = document.getElementById("startbutton"); const stopButton = document.getElementById("stopbutton"); const randomButton = document.getElementById("randombutton"); const resetButton = document.getElementById("resetbutton"); +const sizeChangeButton = document.getElementById("sizeChangeButton"); +const patternButtonContainer = document.getElementById('pattern-button-container'); +//サイズ入力欄 +const sizeInput = document.getElementById("sizeInput"); +const sizeLabel = document.getElementById("sizeLabel"); + +// サイズ入力欄の設定 +sizeInput.min = boardSizeMin; +sizeInput.max = boardSizeMax; +sizeInput.value = defaultBoardSize; +sizeLabel.textContent = `(${boardSizeMin}〜${boardSizeMax})`; + //Boardの初期化 let board = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); const table = document.getElementById("game-board"); @@ -188,19 +202,50 @@ function placePattern(patternKey) { stop(); } -const buttonContainer = document.getElementById('button-container'); -for (const patternKey in patterns) { - const patternData = patterns[patternKey]; - const button = document.createElement('button'); - button.textContent = patternData.names["ja"]; - button.onclick = () => { - placePattern(patternKey) - }; +function createPatternButtons() { + patternButtonContainer.innerHTML = ""; + for (const patternKey in patterns) { + const patternData = patterns[patternKey]; + const button = document.createElement('button'); + button.textContent = patternData.names["ja"]; + button.dataset.patternKey = patternKey; // data-pattern-key属性にキーを保存 + button.onclick = () => { + placePattern(patternKey) + }; + patternButtonContainer.appendChild(button); + } +} +createPatternButtons(); + +function updatePatternButtons() { + const buttons = patternButtonContainer.getElementsByTagName('button'); //↓ボードに収まるパターンのみクリック可能にする - const requiredSize = patternData.minBoardSize || 0; - if (boardSize < requiredSize) { - button.disabled = true; - button.title = `このパターンには ${requiredSize}x${requiredSize} 以上の盤面が必要です`; + for (const button of buttons) { + const patternKey = button.dataset.patternKey; // data-pattern-key 属性からキーを取得 + const patternData = patterns[patternKey]; + const requiredSize = patternData.minBoardSize || 0; + if (boardSize < requiredSize) { + button.disabled = true; + button.title = `このパターンには ${requiredSize}x${requiredSize} 以上の盤面が必要です`; + } else { + button.disabled = false; + button.title = ""; + } } - buttonContainer.appendChild(button); -} \ No newline at end of file +} +updatePatternButtons(); + +sizeChangeButton.onclick = () => { + const newSize = parseInt(sizeInput.value, 10); + if (isNaN(newSize) || newSize < boardSizeMin || boardSizeMax < newSize) { + alert(`サイズは ${boardSizeMin} から ${boardSizeMax} の間で入力してください。`); + sizeInput.value = boardSize; + return; + } + boardSize = newSize; + board = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); + renderBoard(); + generationChange(0); + stop(); + updatePatternButtons(); +}; \ No newline at end of file From 67f7c98db125635205a1d9b290b613dd4758b48f Mon Sep 17 00:00:00 2001 From: coelacanth657 <210202793+coelacanth657@users.noreply.github.com> Date: Tue, 21 Oct 2025 20:25:47 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E3=82=BB=E3=83=AB=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E8=87=AA=E5=8B=95=E5=A4=89=E6=9B=B4=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/patterns.js | 2 ++ src/life-game/life-game.js | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/patterns.js b/src/lib/patterns.js index e504256..649fd15 100644 --- a/src/lib/patterns.js +++ b/src/lib/patterns.js @@ -360,6 +360,7 @@ export const patterns = { [0, 1, 0, 0, 0, 1, 1, 1] ] }, + /*↓minBoardSizeが大きすぎるので保留 //寿命1103 RPentomino: { names: { @@ -386,4 +387,5 @@ export const patterns = { [1, 1, 0, 0, 1, 1, 1] ] } + */ }; \ No newline at end of file diff --git a/src/life-game/life-game.js b/src/life-game/life-game.js index aab6bac..8a0c9d3 100644 --- a/src/life-game/life-game.js +++ b/src/life-game/life-game.js @@ -6,7 +6,8 @@ let generationFigure = 0; //定数 const defaultBoardSize = 20; -const boardSizeMax = 300; +const defaultCellSize = 22; //px +const boardSizeMax = 100; const boardSizeMin = 10; const defaultLiveAroundMax = 3; const defaultLiveAroundMin = 2; @@ -15,6 +16,7 @@ const defaultDeadAroundMin = 3; //変数設定 let boardSize = defaultBoardSize; +let cellSize = defaultCellSize; let livearoundMax = defaultLiveAroundMax; let livearoundMin = defaultLiveAroundMin; let deadaroundMax = defaultDeadAroundMax; @@ -70,8 +72,9 @@ function renderBoard() { const button = document.createElement("button"); button.style.backgroundColor = board[i][j] ? "black" : "white"; //Boardの対応する値によって色を変更 button.style.border = "1px solid black"; - button.style.width = "22px"; - button.style.height = "22px"; + button.style.width = `${cellSize}px`; + button.style.height = `${cellSize}px`; + button.style.padding = "0"; //cellSizeが小さいとき、セルが横長になることを防ぐ button.onclick = () => { if (timer === "stop") { board[i][j] = !board[i][j]; @@ -243,6 +246,7 @@ sizeChangeButton.onclick = () => { return; } boardSize = newSize; + cellSize = Math.floor(defaultCellSize * (defaultBoardSize/newSize)); board = Array.from({ length: boardSize }, () => Array.from({ length: boardSize }, () => false)); renderBoard(); generationChange(0);