Skip to content

Commit

Permalink
Update new.js
Browse files Browse the repository at this point in the history
Added rivers
  • Loading branch information
Avid-Xenoblade-Player authored Mar 18, 2024
1 parent c3cf225 commit 87a4a7a
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const WeatherState = {
BLUE: "blue",
MOUNTAIN:"grey",
SNOW: "snow",
RIVER: "river",
};

// Grid size
Expand Down Expand Up @@ -39,11 +40,12 @@ function setCell(x, y, state) {

function initializeGrid() {
const weatherProbabilities = {
[WeatherState.WHITE]: 0.37, // 45% chance
[WeatherState.BLACK]: 0.63, // 55% chance
[WeatherState.WHITE]: 0.34, // 34% chance
[WeatherState.BLACK]: 0.63, // 63% chance
[WeatherState.BLUE]: 0.0, // 0% chance
[WeatherState.MOUNTAIN]: 0.0, // 0% chance
[WeatherState.SNOW]: 0.0, // 0% chance
[WeatherState.RIVER]: 0.0, // 0% chance
};

for (let x = 0; x < gridSize; x++) {
Expand Down Expand Up @@ -74,6 +76,7 @@ function updateCell(x, y) {
[WeatherState.BLUE]: 0,
[WeatherState.MOUNTAIN]: 0,
[WeatherState.SNOW]: 0,
[WeatherState.RIVER]: 0,
};

for (let dx = -1; dx <= 1; dx++) {
Expand All @@ -89,6 +92,11 @@ function updateCell(x, y) {

// Apply transition rules based on current state and surroundings
switch (currentState) {
case WeatherState.RIVER:
if ((stateCounts[WeatherState.BLUE] + stateCounts[WeatherState.WHITE]) > 1) {
newState = WeatherState.WHITE;
}
break;
case WeatherState.SNOW:
if (stateCounts[WeatherState.MOUNTAIN] > 0) {
newState = WeatherState.SNOW;
Expand All @@ -100,6 +108,13 @@ function updateCell(x, y) {
if (stateCounts[WeatherState.BLACK] > 1) {
newState = WeatherState.MOUNTAIN;
}
if ((stateCounts[WeatherState.SNOW] == 4) &&
(getCell (x - 1, y - 1) == WeatherState.SNOW) ||
(getCell (x - 1, y + 1) == WeatherState.SNOW) &&
(getCell (x + 1, y - 1) == WeatherState.SNOW) ||
(getCell (x + 1, y + 1) == WeatherState.SNOW)) {
newState = WeatherState.RIVER;
}
break;

case WeatherState.MOUNTAIN:
Expand All @@ -110,21 +125,29 @@ function updateCell(x, y) {
}
if (stateCounts[WeatherState.MOUNTAIN] > 3 &&
(getCell(x + 4, y + 4) == WeatherState.MOUNTAIN ||
getCell(x + 4, y + 4) == WeatherState.SNOW) &&
getCell(x + 4, y + 4) == WeatherState.SNOW ||
getCell(x + 4, y + 4) == WeatherState.RIVER) &&
(getCell(x + 4, y - 4) == WeatherState.MOUNTAIN ||
getCell(x + 4, y - 4) == WeatherState.SNOW) &&
getCell(x + 4, y - 4) == WeatherState.SNOW ||
getCell(x + 4, y - 4) == WeatherState.RIVER) &&
(getCell(x - 4, y + 4) == WeatherState.MOUNTAIN ||
getCell(x - 4, y + 4) == WeatherState.SNOW) &&
getCell(x - 4, y + 4) == WeatherState.SNOW ||
getCell(x - 4, y + 4) == WeatherState.RIVER) &&
(getCell(x - 4, y - 4) == WeatherState.MOUNTAIN ||
getCell(x - 4, y - 4) == WeatherState.SNOW) &&
getCell(x - 4, y - 4) == WeatherState.SNOW ||
getCell(x - 4, y - 4) == WeatherState.RIVER) &&
stateCounts[WeatherState.BLACK] < 1) {
newState = WeatherState.SNOW;
newState = WeatherState.SNOW;
} else {
newState = WeatherState.MOUNTAIN;
}
if (stateCounts[WeatherState.WHITE] > 0) {
newState = WeatherState.BLACK;
}
if((stateCounts[WeatherState.RIVER] < 2) &&
getCell(x, y - 1) == WeatherState.RIVER) {
newState = WeatherState.RIVER;
}
break;
case WeatherState.WHITE:
if (stateCounts[WeatherState.BLACK] > stateCounts[WeatherState.WHITE]) {
Expand Down Expand Up @@ -176,6 +199,10 @@ function updateCell(x, y) {
getCell(x, y - 1) == WeatherState.BLUE)) {
newState = WeatherState.BLUE;
}
if((stateCounts[WeatherState.RIVER] < 2) &&
getCell(x, y - 1) == WeatherState.RIVER) {
newState = WeatherState.RIVER;
}
break;
case WeatherState.BLUE:
if (stateCounts[WeatherState.BLACK] > (stateCounts[WeatherState.WHITE] + stateCounts[WeatherState.BLUE])) {
Expand Down

0 comments on commit 87a4a7a

Please sign in to comment.