-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulation.java
More file actions
31 lines (26 loc) · 1.11 KB
/
Simulation.java
File metadata and controls
31 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Random;
/**
* Monte Carlo Simulation to test the Percolation threshold.
*/
public class Simulation {
public static void main(String[] args) {
int dimension = 10; // 10x10 Grid
Percolation grid = new Percolation(dimension);
Random random = new Random();
int strikes = 0;
System.out.println("Starting Cosmic Ray Percolation Simulation...\n");
// Continuously strike random cells until the system percolates
while (!grid.percolates()) {
int row = random.nextInt(dimension);
int col = random.nextInt(dimension);
// The strike method safely handles already-open cells
grid.strike(row, col);
strikes++;
}
System.out.println("SHORT CIRCUIT ACHIEVED (SYSTEM PERCOLATES)");
System.out.println("Total cosmic ray strikes required: " + strikes);
System.out.println("\nFinal Grid State:");
System.out.println(grid.toString());
System.out.println("Legend: [.] Insulator | [X] Conductor | [*] Triggering Strike");
}
}