This commit is contained in:
Crispy 2024-05-02 13:27:53 +02:00
parent 46910fa0e7
commit fac71e1b95

View file

@ -10,13 +10,6 @@ AREA :: WIDTH * HEIGHT
main :: proc() {
board : [AREA]bool = ---
// board[0] = true
// board[1] = true
// board[WIDTH] = true
// for x in 4..<14 {
// board[x + WIDTH*8] = true
// }
fmt.print("\e[2J") // clear screen
for {
fmt.print("\e[u") // reset cursor
@ -27,12 +20,12 @@ main :: proc() {
}
print_board :: proc(state: ^[AREA]bool) {
for y := 0; y < HEIGHT; y += 2{
for y := 0; y < HEIGHT; y += 2 {
line := strings.builder_make()
defer strings.builder_destroy(&line)
for x in 0..<WIDTH{
for x in 0..<WIDTH {
top := state[x + y * WIDTH]
bot := state[x + (y+1) * WIDTH ]
bot := state[x + (y+1) * WIDTH]
c : rune
switch {
case top && bot: c = '█'
@ -57,14 +50,12 @@ update_board :: proc(state: ^[AREA]bool) {
px := (x + dx + WIDTH) % WIDTH
for dy in -1..=1 {
py := (y + dy + HEIGHT) % HEIGHT
if state[px + py * WIDTH]{
count += 1
}
}
if state[px + py * WIDTH] do count += 1
}
cell := state[x + y * WIDTH]
new_cell := (count == 3 && !cell) || (cell && count < 5 && count > 2)
new_state[x + y * WIDTH] = new_cell
}
cell := state[x + y * WIDTH]
new_cell := (count == 3 && !cell) || (cell && count < 5 && count > 2)
new_state[x + y * WIDTH] = new_cell
}
}
for i in 0..<AREA {