Particle Movement (within the Geometric Amoebot Model) * should move contracted particle to adjacent unoccupied node when moving * should contract expanded particle to one of its nodes when moving
pages/particle
⇐ avoid conflicts between the Simulation and our test cases. Exclude the simulation of particle motion from the Node class (see the node.js file). [⇒ First Animated Program]
// Simulate particle movement setInterval(() => { particles.forEach((particle) => { particle.move(); console.log(`Particle ${particle.id} moved to position (${particle.position.x}, ${particle.position.y})`); }); }, 1000); // Adjust simulation speed as needed
class Particle { constructor(id, position, state) { this.id = id; // Unique identifier for the particle this.position = position; // Current position on the grid this.state = state; // 'contracted' or 'expanded' this.head = null; // Node the particle last expanded into this.tail = null; // Other occupied node } expandTo(node) { this.state = 'expanded'; this.head = node; } contractTo(node) { this.state = 'contracted'; this.tail = node; } move() { // Simulate particle movement based on expansions and contractions if (this.state === 'contracted') { // Particle is contracted, try to expand to adjacent node const adjacentNodes = this.getAdjacentNodes(); for (const node of adjacentNodes) { if (!node.occupied) { this.expandTo(node); node.occupied = true; return; } } } else if (this.state === 'expanded') { // Particle is expanded, try to contract to one of its nodes if (!this.tail.occupied) { this.contractTo(this.tail); this.head.occupied = false; } } } getAdjacentNodes() { // Get adjacent nodes on the triangular grid // Implement your own logic for identifying adjacent nodes based on the triangular grid structure // For simplicity, this implementation assumes a flat grid with triangular cells // and calculates adjacent nodes based on their positions // You may need to adjust this logic based on your specific grid structure const adjacentNodes = []; // Implement logic to identify adjacent nodes based on current position // For example, you could use geometric calculations or pre-defined mappings return adjacentNodes; } }
⇒ class Node