1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:17:45 +00:00

Games: Add GameOfLife

This patch introduces a new game based on Conway's Game of Life.
This commit is contained in:
Andres Crucitti 2021-04-11 18:46:58 -07:00 committed by Linus Groh
parent e4f61c6f28
commit d99991e39c
18 changed files with 667 additions and 288 deletions

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2021, Andres Crucitti <dasc495@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibGfx/Point.h>
#include <stdio.h>
class Board {
public:
Board(size_t rows, size_t column);
~Board();
size_t total_size() const { return m_columns * m_rows; }
size_t columns() const { return m_columns; }
size_t rows() const { return m_rows; }
size_t calculate_index(size_t row, size_t column) const { return row * m_columns + column; };
void toggle_cell(size_t index);
void toggle_cell(size_t row, size_t column);
void set_cell(size_t row, size_t column, bool on);
void set_cell(size_t index, bool on);
bool cell(size_t row, size_t column) const;
bool cell(size_t index) const;
const Vector<bool>& cells() const { return m_cells; }
void run_generation();
bool is_stalled() const { return m_stalled; }
void clear();
void randomize();
private:
bool calculate_next_value(size_t index) const;
size_t m_columns { 1 };
size_t m_rows { 1 };
bool m_stalled { false };
Vector<bool> m_cells;
};