Spaces:
Running
Running
Update index.html
Browse files1 unmodified line23456725 unmodified lines33343536373832 unmodified lines717273747576777879808182838485868788899091929394959697988 unmodified lines10710810911011111211 unmodified lines1241251261271281298 unmodified lines1381391401411421432 unmodified lines14614714814915015115215315415515615715815916016 unmodified lines17717817918018118217 unmodified lines2002012022032042052062072082092102112122132142152166 unmodified lines22322422522622722848 unmodified lines27727827928028128213 unmodified lines2962972982993003012 unmodified lines3043053063073083091 unmodified line<html><head><title>Cancer Game Theory</title><style>body {font-family: Arial, sans-serif;25 unmodified lines}.rules ul {line-height: 1.6;}canvas {border: 2px solid #1e3799;32 unmodified linesbutton:hover {background-color: #0c2461;}</style></head><body><div class="header"><h1>Cancer Game Theory</h1></div><div class="rules"><h2>Simulation Rules</h2><ul><li>🦠 Cancer cells die when surrounded by 3+ cells within 40px</li><li>🩺 Cancer cells convert isolated healthy cells (no nearby healthy)</li><li>🧬 Cells reproduce based on type-specific rates</li><li>⚡ Cancer cells move faster than healthy cells</li><li>🧠 Neural networks control movement decisions</li><li>🎮 Adjust parameters below to influence outcomes</li></ul></div><div class="controls"><h2>Simulation Parameters</h2><div class="param-group"><label>Initial Healthy: <input type="number" id="initialHealthy" value="15" min="1"></label><label>Initial Cancer: <input type="number" id="initialCancer" value="8" min="1"></label><label>Mutation Rate: <input type="number" id="mutationRate" value="0.1" step="0.01" min="0"></label>8 unmodified linesHealthy: <span id="healthyCount">0</span> |Cancer: <span id="cancerCount">0</span></div></div><canvas id="simCanvas" width="800" height="500"></canvas>11 unmodified lineslet generation = 1;let frameCount = 0;const cellRadius = 5;function getNormal(mean = 0, std = 1) {let u, v, s;8 unmodified linesclass NeuralNetwork {constructor(parent = null) {if(parent) {this.weights1 = parent.weights1.map(row =>row.map(w => w + getNormal(0, parseFloat(document.getElementById('mutationRate').value)))2 unmodified linesrow.map(w => w + getNormal(0, parseFloat(document.getElementById('mutationRate').value))));} else {this.weights1 = Array.from({length: 8}, () =>Array.from({length: 4}, () => getNormal(0, 1)));this.weights2 = Array.from({length: 4}, () =>Array.from({length: 2}, () => getNormal(0, 1)));}}activate(x) {return x; // Linear activation for unlimited speed}predict(inputs) {16 unmodified linesthis.y = parent ?parent.y + (Math.random() * 40 - 20) :Math.random() * canvas.height;}getNearbyCells() {17 unmodified linesconst [vx, vy] = this.brain.predict(inputs);// Unlimited speed based on neural network outputthis.x += vx;this.y += vy;// Cancer cells get inherent speed boostif(this.type === 'cancer') {this.x += vx * 0.5; // Additional 50% speed boostthis.y += vy * 0.5;}// Wrap around edgesthis.x = (this.x + canvas.width) % canvas.width;this.y = (this.y + canvas.height) % canvas.height;}6 unmodified lines}}function checkCollisions() {cells.forEach((cell, i) => {if(cell.type === 'cancer') {48 unmodified linesgeneration++;reproduceCells();updateStatus();}cells.forEach(cell => cell.update());13 unmodified linesgeneration = 1;frameCount = 0;cells = [];const initialHealthy = parseInt(document.getElementById('initialHealthy').value);const initialCancer = parseInt(document.getElementById('initialCancer').value);2 unmodified linesfor(let i = 0; i < initialCancer; i++) cells.push(new Cell('cancer'));updateStatus();ctx.clearRect(0, 0, canvas.width, canvas.height);cells.forEach(cell => cell.draw());});1 unmodified line234567825 unmodified lines343536373839404132 unmodified lines74757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241258 unmodified lines13413513613713813914014114214314414514614714814915015115215315415515615715815916011 unmodified lines1721731741751761771781791808 unmodified lines1891901911921931941951961972 unmodified lines20020120220320420520620720820921021121221321416 unmodified lines23123223323423523623717 unmodified lines2552562572582592602612622632642652662672682692706 unmodified lines27727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734848 unmodified lines39739839940040140240313 unmodified lines4174184194204214224234242 unmodified lines4274284294304314324334341 unmodified line<html><head><title>Cancer Game Theory</title><script src="https://cdn.jsdelivr.net/npm/chart.js"></script><style>body {font-family: Arial, sans-serif;25 unmodified lines}.rules ul {line-height: 1.6;list-style-type: none;padding-left: 0;}canvas {border: 2px solid #1e3799;32 unmodified linesbutton:hover {background-color: #0c2461;}.data-panel {display: grid;grid-template-columns: 1fr 1fr;gap: 20px;margin-top: 20px;}.generations-table {max-height: 300px;overflow-y: auto;}table {width: 100%;border-collapse: collapse;}th, td {padding: 8px;text-align: left;border-bottom: 1px solid #ddd;}th {background-color: #1e3799;color: white;}</style></head><body><div class="header"><h1>Cancer Game Theory Simulation</h1></div><div class="rules"><h2>Simulation Rules</h2><ul><li>Cancer cells die when surrounded by 3+ cells within 40px</li><li>Cancer cells convert isolated healthy cells (no nearby healthy)</li><li>Cells reproduce based on type-specific rates</li><li>Cancer cells move faster than healthy cells</li><li>Neural networks control movement decisions</li><li>Adjust parameters below to influence outcomes</li></ul></div><div class="controls"><h2>Simulation Parameters</h2><div class="param-group"><label>Hidden Dimension: <input type="number" id="hiddenDim" value="4" min="1"></label><label>Initial Healthy: <input type="number" id="initialHealthy" value="15" min="1"></label><label>Initial Cancer: <input type="number" id="initialCancer" value="8" min="1"></label><label>Mutation Rate: <input type="number" id="mutationRate" value="0.1" step="0.01" min="0"></label>8 unmodified linesHealthy: <span id="healthyCount">0</span> |Cancer: <span id="cancerCount">0</span></div><div class="data-panel"><div class="generations-table"><h3>Generation History (Every 10 gens)</h3><table id="generationTable"><thead><tr><th>Generation</th><th>Healthy</th><th>Cancer</th><th>Avg Speed</th></tr></thead><tbody id="tableBody"></tbody></table></div><div><h3>Population Trends</h3><canvas id="populationChart"></canvas></div></div></div><canvas id="simCanvas" width="800" height="500"></canvas>11 unmodified lineslet generation = 1;let frameCount = 0;const cellRadius = 5;let populationChart = null;let generationsData = [];let currentHiddenDim = 4;function getNormal(mean = 0, std = 1) {let u, v, s;8 unmodified linesclass NeuralNetwork {constructor(parent = null) {const inputSize = 8;const outputSize = 2;if(parent) {this.weights1 = parent.weights1.map(row =>row.map(w => w + getNormal(0, parseFloat(document.getElementById('mutationRate').value)))2 unmodified linesrow.map(w => w + getNormal(0, parseFloat(document.getElementById('mutationRate').value))));} else {this.weights1 = Array.from({length: inputSize}, () =>Array.from({length: currentHiddenDim}, () => getNormal(0, 1)));this.weights2 = Array.from({length: currentHiddenDim}, () =>Array.from({length: outputSize}, () => getNormal(0, 1)));}}activate(x) {return x;}predict(inputs) {16 unmodified linesthis.y = parent ?parent.y + (Math.random() * 40 - 20) :Math.random() * canvas.height;this.speed = 0;}getNearbyCells() {17 unmodified linesconst [vx, vy] = this.brain.predict(inputs);this.x += vx;this.y += vy;this.speed = Math.hypot(vx, vy);if(this.type === 'cancer') {this.x += vx * 0.5;this.y += vy * 0.5;this.speed *= 1.5;}this.x = (this.x + canvas.width) % canvas.width;this.y = (this.y + canvas.height) % canvas.height;}6 unmodified lines}}function updateChart() {const ctx = document.getElementById('populationChart').getContext('2d');if(populationChart) {populationChart.destroy();}populationChart = new Chart(ctx, {type: 'line',data: {labels: generationsData.map(d => d.generation),datasets: [{label: 'Healthy Cells',data: generationsData.map(d => d.healthy),borderColor: '#00ff00',tension: 0.1}, {label: 'Cancer Cells',data: generationsData.map(d => d.cancer),borderColor: '#ff0000',tension: 0.1}]},options: {responsive: true,scales: {y: {beginAtZero: true}}}});}function updateTable() {const tableBody = document.getElementById('tableBody');tableBody.innerHTML = generationsData.map(d => `<tr><td>${d.generation}</td><td>${d.healthy}</td><td>${d.cancer}</td><td>${d.avgSpeed.toFixed(2)}</td></tr>`).join('');}function saveGenerationData() {if(generation % 10 === 0) {const healthy = cells.filter(c => c.type === 'healthy').length;const cancer = cells.filter(c => c.type === 'cancer').length;const speeds = cells.map(c => c.speed);const avgSpeed = speeds.reduce((a,b) => a + b, 0) / speeds.length || 0;generationsData.push({generation,healthy,cancer,avgSpeed});if(generationsData.length > 20) generationsData.shift();updateChart();updateTable();}}function checkCollisions() {cells.forEach((cell, i) => {if(cell.type === 'cancer') {48 unmodified linesgeneration++;reproduceCells();updateStatus();saveGenerationData();}cells.forEach(cell => cell.update());13 unmodified linesgeneration = 1;frameCount = 0;cells = [];generationsData = [];currentHiddenDim = parseInt(document.getElementById('hiddenDim').value);const initialHealthy = parseInt(document.getElementById('initialHealthy').value);const initialCancer = parseInt(document.getElementById('initialCancer').value);2 unmodified linesfor(let i = 0; i < initialCancer; i++) cells.push(new Cell('cancer'));updateStatus();updateChart();updateTable();ctx.clearRect(0, 0, canvas.width, canvas.height);cells.forEach(cell => cell.draw());});
index.html+141-16