Giter VIP home page Giter VIP logo

my-game-of-life's Introduction

Game of Life

Matrix

Description

The Matrix struct represents a grid with size. It provides methods for matrix a new matrix, updating current matrix with reference and print current matrix.

Usage

You can use the Matrix struct to simulate Conway's Game of Life.

use Creature;

// Example usage
let mut matrix: Matrix = Matrix {
    size: 2,
    grid: vec![
        vec![Creature::new(0, 0, 2), Creature::new(0, 1, 2)],
        vec![Creature::new(1, 0, 2), Creature::new(1, 1, 1)],
    ],
};
let ref_mat: Matrix = matrix.clone();
matrix.update_matrix(&ref_mat);
assert_eq!(
    matrix.grid,
    vec![
        vec![Creature::new(0, 0, 2), Creature::new(0, 1, 2)],
        vec![Creature::new(1, 0, 2), Creature::new(1, 1, 2)],
    ]
);

Creature

Description

The Creature struct represents a creature with coordinates and an alive state. It provides methods for creating a new creature, setting its alive state, checking its neighboring creatures, and counting the number of alive neighbors.

Usage

You can use the Creature struct to simulate and manipulate creatures within a game matrix.

// Example usage
let matrix: Vec<Vec<Creature>> = vec![
    vec![Creature::new(0, 0, 1), Creature::new(0, 1, 2)],
    vec![Creature::new(1, 0, 1), Creature::new(1, 1, 1)]
];
let mut c_0 = matrix[0][0].clone();
c_0.check_still_alive(matrix);
assert_eq!(c_0.alive, false);

Licenses

This project is licensed under the MIT License and Apache 2.0 License - see the LICENSE_* files for details.

my-game-of-life's People

Contributors

jonathanlt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.