Compare commits

...

25 Commits

Author SHA1 Message Date
Palash Tyagi
339c44b70e
Merge 960fd345c2ea712ab9d1da449d8af367085585c1 into 3e279b813843ce9fa9ba29fba9ccfc538712f8f7 2025-07-05 19:22:23 +01:00
Palash Tyagi
3e279b8138 Fix image height attribute in README.md 2025-07-05 15:35:16 +01:00
Palash Tyagi
a06725686f using http api instead of gh cli 2025-07-05 15:34:31 +01:00
Palash Tyagi
7106f6ccf7 Add a blank line at the beginning of README.md for better formatting 2025-07-05 00:58:31 +01:00
Palash Tyagi
95911fb0ef Fix GitHub token reference for downloading benchmark report 2025-07-05 00:56:53 +01:00
Palash Tyagi
84b7fc8eec Fix GitHub token reference for downloading benchmark report 2025-07-05 00:53:22 +01:00
7a580327e8
Merge pull request #52 from Magnus167/updating-example
Updating example
2025-07-05 00:51:25 +01:00
Palash Tyagi
1e908b0ac5 Fix token handling for downloading benchmark report in workflow 2025-07-05 00:50:10 +01:00
Palash Tyagi
1f306c59f2 Add instructions for running examples in README.md 2025-07-05 00:47:57 +01:00
Palash Tyagi
48660b1a75 Add rand as a development dependency in Cargo.toml 2025-07-05 00:47:51 +01:00
Palash Tyagi
6858fa4bfa Implement main game loop and board printing for Conway's Game of Life 2025-07-05 00:47:45 +01:00
960fd345c2
Merge branch 'main' into csv 2025-07-04 00:59:25 +01:00
325e75419c
Merge branch 'main' into csv 2025-06-07 13:38:30 +01:00
b1dc18d05b
Merge branch 'main' into csv 2025-05-15 18:35:46 +01:00
8cbb957764
Merge branch 'main' into csv 2025-05-13 00:08:38 +01:00
b937ed1cdf
Merge branch 'main' into csv 2025-05-11 02:00:25 +01:00
2e071a6974
Merge branch 'main' into csv 2025-05-05 02:13:15 +01:00
689169bab2
Merge branch 'main' into csv 2025-05-05 02:01:45 +01:00
a45a5ecf4e
Merge branch 'main' into csv 2025-05-04 02:29:12 +01:00
84e1b423f4
Merge branch 'main' into csv 2025-05-04 02:10:55 +01:00
197739bc2f
Merge branch 'main' into csv 2025-05-04 01:07:58 +01:00
d2c2ebca0f
Merge branch 'main' into csv 2025-05-03 01:32:05 +01:00
f5f3f2c100
Merge branch 'main' into csv 2025-05-02 23:38:37 +01:00
9fcb1ea2cf
Merge branch 'main' into csv 2025-05-01 01:14:09 +01:00
Palash Tyagi
623303cf72 Update README to include upcoming features for CSV I/O, Date Utils, and more math functions 2025-05-01 01:13:34 +01:00
4 changed files with 148 additions and 8 deletions

View File

@ -105,10 +105,21 @@ jobs:
> last-commit-date.json > last-commit-date.json
- name: Download last available benchmark report - name: Download last available benchmark report
env:
GH_TOKEN: ${{ secrets.CUSTOM_GH_TOKEN }}
run: | run: |
artifact_url=$(gh api -H "Accept: application/vnd.github+json" \ artifact_url=$(
/repos/${{ github.repository }}/actions/artifacts \ curl -sSL \
| jq -r '.artifacts[] | select(.name | startswith("benchmark-reports")) | .archive_download_url' | head -n 1) -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts" \
| jq -r '
.artifacts[]
| select(.name | startswith("benchmark-reports"))
| .archive_download_url
' \
| head -n 1
)
if [ -z "$artifact_url" ]; then if [ -z "$artifact_url" ]; then
echo "No benchmark artifact found!" echo "No benchmark artifact found!"
@ -117,7 +128,7 @@ jobs:
exit 0 exit 0
fi fi
curl -L -H "Authorization: Bearer ${{ secrets.CUSTOM_GH_TOKEN }}" \ curl -L -H "Authorization: Bearer ${GH_TOKEN}" \
"$artifact_url" -o benchmark-report.zip "$artifact_url" -o benchmark-report.zip
# Print all files in the current directory # Print all files in the current directory

View File

@ -15,6 +15,9 @@ crate-type = ["cdylib", "lib"]
chrono = "^0.4.10" chrono = "^0.4.10"
criterion = { version = "0.5", features = ["html_reports"], optional = true } criterion = { version = "0.5", features = ["html_reports"], optional = true }
[dev-dependencies]
rand = "^0.9.1"
[features] [features]
bench = ["dep:criterion"] bench = ["dep:criterion"]

View File

@ -1,4 +1,5 @@
# <img align="center" alt="Rustframe" src=".github/rustframe_logo.png" height="50" /> rustframe
# <img align="center" alt="Rustframe" src=".github/rustframe_logo.png" height="50px" /> rustframe
<!-- though the centre tag doesn't work as it would noramlly, it achieves the desired effect --> <!-- though the centre tag doesn't work as it would noramlly, it achieves the desired effect -->
@ -25,6 +26,12 @@ Rustframe keeps things simple, safe, and readable. It is handy for quick numeric
- **Datecentric row index** - businessday ranges and calendar slicing built in. - **Datecentric row index** - businessday ranges and calendar slicing built in.
- **Pure safe Rust** - 100% safe, zero `unsafe`. - **Pure safe Rust** - 100% safe, zero `unsafe`.
### Coming soon
- **CSV I/O** - read/write CSV files with a simple API.
- **Date Utils** - date math, calendar slicing, indexing, and more.
- **More math** - more math functions and aggregations.
### Heads up ### Heads up
- **Not memoryefficient (yet)** - footprint needs work. - **Not memoryefficient (yet)** - footprint needs work.
@ -34,6 +41,7 @@ Rustframe keeps things simple, safe, and readable. It is handy for quick numeric
- Optional GPU help (Vulkan or similar) for heavier workloads. - Optional GPU help (Vulkan or similar) for heavier workloads.
- Straightforward Python bindings using `pyo3`. - Straightforward Python bindings using `pyo3`.
- Integration with common ML libraries, or introduce simple ML features.
--- ---
@ -102,3 +110,15 @@ assert!(check);
### More examples ### More examples
See the [examples](./examples/) directory for some demonstrations of Rustframe's syntax and functionality. See the [examples](./examples/) directory for some demonstrations of Rustframe's syntax and functionality.
To run the examples, use:
```bash
cargo run --example <example_name>
```
E.g. to run the `game_of_life` example:
```bash
cargo run --example game_of_life
```

View File

@ -1,7 +1,113 @@
// src/gol.rs
use rand::{self, Rng}; use rand::{self, Rng};
use rustframe::matrix::{BoolMatrix, IntMatrix, Matrix}; use rustframe::matrix::{BoolMatrix, BoolOps, IntMatrix, Matrix};
use std::{thread, time};
const BOARD_SIZE: usize = 50; // Size of the board (50x50)
const TICK_DURATION_MS: u64 = 10; // Milliseconds per frame
fn main() {
// Initialize the game board.
// This demonstrates `BoolMatrix::from_vec`.
let mut current_board =
BoolMatrix::from_vec(vec![false; BOARD_SIZE * BOARD_SIZE], BOARD_SIZE, BOARD_SIZE);
let primes = generate_primes((BOARD_SIZE * BOARD_SIZE) as i32);
add_simulated_activity(&mut current_board, BOARD_SIZE);
let mut generation_count: u32 = 0;
// `previous_board_state` will store a clone of the board.
// This demonstrates `Matrix::clone()` and later `PartialEq` for `Matrix`.
let mut previous_board_state: Option<BoolMatrix> = None;
let mut board_hashes = Vec::new();
// let mut print_board_bool = true;
let mut print_bool_int = 0;
loop {
// print!("{}[2J", 27 as char); // Clear screen and move cursor to top-left
// if print_board_bool {
if print_bool_int % 10 == 0 {
print!("{}[2J", 27 as char);
println!("Conway's Game of Life - Generation: {}", generation_count);
print_board(&current_board);
println!("Alive cells: {}", &current_board.count());
// print_board_bool = false;
print_bool_int = 0;
} else {
// print_board_bool = true;
print_bool_int += 1;
}
// `current_board.count()` demonstrates a method from `BoolOps`.
board_hashes.push(hash_board(&current_board, primes.clone()));
if detect_stable_state(&current_board, &previous_board_state) {
println!(
"\nStable state detected at generation {}.",
generation_count
);
add_simulated_activity(&mut current_board, BOARD_SIZE);
}
if detect_repeating_state(&mut board_hashes) {
println!(
"\nRepeating state detected at generation {}.",
generation_count
);
add_simulated_activity(&mut current_board, BOARD_SIZE);
}
if !&current_board.any() {
println!("\nExtinction at generation {}.", generation_count);
add_simulated_activity(&mut current_board, BOARD_SIZE);
}
// `current_board.clone()` demonstrates `Clone` for `Matrix`.
previous_board_state = Some(current_board.clone());
// This is the core call to your game logic.
let next_board = game_of_life_next_frame(&current_board);
current_board = next_board;
generation_count += 1;
thread::sleep(time::Duration::from_millis(TICK_DURATION_MS));
// if generation_count > 500 { // Optional limit
// println!("\nReached generation limit.");
// break;
// }
}
}
/// Prints the Game of Life board to the console.
///
/// - `board`: A reference to the `BoolMatrix` representing the current game state.
/// This function demonstrates `board.rows()`, `board.cols()`, and `board[(r, c)]` (Index trait).
fn print_board(board: &BoolMatrix) {
let mut print_str = String::new();
print_str.push_str("+");
for _ in 0..board.cols() {
print_str.push_str("--");
}
print_str.push_str("+\n");
for r in 0..board.rows() {
print_str.push_str("| ");
for c in 0..board.cols() {
if board[(r, c)] {
// Using Index trait for Matrix<bool>
print_str.push_str("██");
} else {
print_str.push_str(" ");
}
}
print_str.push_str(" |\n");
}
print_str.push_str("+");
for _ in 0..board.cols() {
print_str.push_str("--");
}
print_str.push_str("+\n\n");
print!("{}", print_str);
}
/// Helper function to create a shifted version of the game board. /// Helper function to create a shifted version of the game board.
/// (Using the version provided by the user) /// (Using the version provided by the user)