fn do_generation(board :&mut [[bool; HEIGHT]]) {
    let mut new_board = [[false; HEIGHT]; WIDTH];


    for x in 0..WIDTH {
        for y in 0..HEIGHT {
            let live = count_live_neighbors(board, x, y);
            if board[x][y] && (live < 2 || live > 3) {
                // Die
                new_board[x][y] = false;
            } else if !board[x][y] && live == 3 {
                // Born
                new_board[x][y] = true;
            } else {
                // Carry on
                new_board[x][y] = board[x][y];
            }
        }
    }

    // Copy board (memcpy? something better and safe?)
    copy_board(&new_board, board);
}
// Just overwrite the referenced board at the end
Just overwrite the referenced board at the end
Just overwrite the referenced board at the end
fn do_generation(board :&mut [[bool; HEIGHT]]) {
    let mut new_board = [[false; HEIGHT]; WIDTH];
    for x in 0..WIDTH {
        for y in 0..HEIGHT {
            let live = count_live_neighbors(board, x, y);
            if board[x][y] && (live < 2 || live > 3) {
                // Die
                new_board[x][y] = false;
            } else if !board[x][y] && live == 3 {
                // Born
                new_board[x][y] = true;
            } else {
                // Carry on
                new_board[x][y] = board[x][y];
            }
        }
    }
    // Copy board (memcpy? something better and safe?)
    copy_board(&new_board, board);
}
fn do_generation ( board : & mut [ [ bool ; HEIGHT ] ] ) { let mut new_board = [ [ false ; HEIGHT ] ; WIDTH ] ; for x in 0 .. WIDTH { for y in 0 .. HEIGHT { let live = count_live_neighbors ( board , x , y ) ; if board [ x ] [ y ] && ( live < 2 || live > 3 ) { // Die new_board [ x ] [ y ] = false ; } else if ! board [ x ] [ y ] && live == 3 { // Born new_board [ x ] [ y ] = true ; } else { // Carry on new_board [ x ] [ y ] = board [ x ] [ y ] ; } } } // Copy board (memcpy? something better and safe?) copy_board ( & new_board , board ) ; }
Just overwrite the referenced board at the end
Just overwrite the referenced board at the end
board
&mut [[bool; HEIGHT]]
board
&mut [[bool; HEIGHT]]