From dca0bb10be8bb53ac2b6288538c2c32053c7206f Mon Sep 17 00:00:00 2001 From: dan63047 Date: Fri, 17 Nov 2023 23:06:19 +0300 Subject: [PATCH] ARS + TGM random --- src/engine/randomizers.rs | 48 ++++++++++ src/engine/resources.rs | 6 +- src/engine/rotation_systems.rs | 157 +++++++++++++++++++++++++++++++++ src/engine/systems.rs | 2 +- 4 files changed, 209 insertions(+), 4 deletions(-) diff --git a/src/engine/randomizers.rs b/src/engine/randomizers.rs index e85424b..bb66ab2 100644 --- a/src/engine/randomizers.rs +++ b/src/engine/randomizers.rs @@ -1,3 +1,5 @@ +use std::time::SystemTime; + use rand::{seq::SliceRandom, random}; use rand::thread_rng; @@ -16,6 +18,11 @@ pub struct RandomWithoutDirectRepetition { memory: usize } +pub struct TGM { + memory: Vec, + seed: u32 +} + impl Randomizer for Bag { fn populate_next(&mut self, pieces_data: &PiecesData, board_width: isize, board_height: isize) -> Vec { let mut bag = vec![]; @@ -70,4 +77,45 @@ impl Randomizer for RandomWithoutDirectRepetition { fn create() -> Self where Self: Sized { RandomWithoutDirectRepetition { memory: 65535 } } +} + +impl TGM { + fn random(n: u32) -> u32{ + n.wrapping_mul(0x41c64e6d).wrapping_add(12345) & 0xffffffff + } + + fn read(&mut self) -> u32 { + self.seed = TGM::random(self.seed); + (self.seed >> 10) & 0x7fff + } +} + +impl Randomizer for TGM { + fn populate_next(&mut self, pieces_data: &PiecesData, board_width: isize, board_height: isize) -> Vec { + let mut b = 0; + for _ in 0..4{ + b = self.read() % 7; + if !self.memory.contains(&(b as usize)){break;} + b = self.read() % 7; + } + self.memory.pop(); + self.memory.insert(0, b as usize); + vec![Piece::create(pieces_data, b as usize, board_width, board_height)] + } + + fn create() -> Self where Self: Sized { + let mut amazon_prime = TGM { + memory: vec![], + seed: match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { + Ok(n) => n.as_secs().try_into().unwrap(), + Err(_) => panic!("CLOCK???? mclock ⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰"), + } + }; + let mut b = 0; + while b == 0 || b == 6 || b == 4 { + b = amazon_prime.read() as usize % 7; + } + amazon_prime.memory = vec![b, 0, 0, 0]; + amazon_prime + } } \ No newline at end of file diff --git a/src/engine/resources.rs b/src/engine/resources.rs index 5d90bf6..9bb7982 100644 --- a/src/engine/resources.rs +++ b/src/engine/resources.rs @@ -252,7 +252,7 @@ impl Engine { y } - fn reset_lock_delay(&mut self, shift: (i8, i8)){ + fn reset_lock_delay(&mut self){ match self.rotation_system.lock_delay_mode { LockDelayMode::Disabled => {}, LockDelayMode::Gravity => { @@ -291,7 +291,7 @@ impl Engine { }else{ 1 }; - self.reset_lock_delay((0, 0)); + self.reset_lock_delay(); for test in &self.rotation_system.kicks[self.current_piece.as_ref().unwrap().id][self.current_piece.as_ref().unwrap().rotation][id_for_kicks]{ let future_position = (self.current_piece.as_ref().unwrap().position.0 + test.0 as isize, self.current_piece.as_ref().unwrap().position.1 + test.1 as isize); if self.position_is_valid(future_position, future_rotation) { @@ -312,7 +312,7 @@ impl Engine { self.current_piece.as_ref().unwrap().position.1 + shift.1 as isize // future Y ); if self.position_is_valid(future_position, self.current_piece.as_ref().unwrap().rotation) { - if shift.0 != 0 {self.reset_lock_delay(shift);} + if shift.0 != 0 {self.reset_lock_delay();} self.current_piece.as_mut().unwrap().position = future_position; true }else { diff --git a/src/engine/rotation_systems.rs b/src/engine/rotation_systems.rs index 54333fb..9267a04 100644 --- a/src/engine/rotation_systems.rs +++ b/src/engine/rotation_systems.rs @@ -298,6 +298,163 @@ lazy_static!{ height_offset: -2, lock_delay_mode: LockDelayMode::Gravity }); + rs.insert(String::from("ARS"), PiecesData { + pieces: vec![ + vec![ // Z + vec![(0, 1), (1, 1), (1, 0), (2, 0)], + vec![(2, 2), (2, 1), (1, 1), (1, 0)], + ], + vec![ // J + vec![(2, 0), (2, 1), (1, 1), (0, 1)], + vec![(0, 0), (1, 0), (1, 1), (1, 2)], + vec![(0, 1), (0, 0), (1, 0), (2, 0)], + vec![(2, 2), (1, 2), (1, 1), (1, 0)], + ], + vec![ // I + vec![(3, 1), (2, 1), (1, 1), (0, 1)], + vec![(2, 3), (2, 2), (2, 1), (2, 0)], + ], + vec![ // T + vec![(1, 0), (2, 1), (1, 1), (0, 1)], + vec![(0, 1), (1, 0), (1, 1), (1, 2)], + vec![(1, 1), (0, 0), (1, 0), (2, 0)], + vec![(2, 1), (1, 2), (1, 1), (1, 0)], + ], + vec![ // O + vec![(0, 0), (0, 1), (1, 1), (1, 0)], + ], + vec![ // L + vec![(0, 0), (0, 1), (1, 1), (2, 1)], + vec![(0, 2), (1, 2), (1, 1), (1, 0)], + vec![(2, 1), (2, 0), (1, 0), (0, 0)], + vec![(2, 0), (1, 0), (1, 1), (1, 2)], + ], + vec![ // S + vec![(0, 0), (1, 0), (1, 1), (2, 1)], + vec![(2, 0), (2, 1), (1, 1), (1, 2)], + ] + ], + kicks: vec![ + vec![ // Z + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 90 + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 180 + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 0 + ], + ], + vec![ // J + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 90 + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 180 + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 0 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 270 + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 90 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 0 + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 180 + ] + ], + vec![ // I + vec![ + vec![( 0, 0)], // 0 -> 90 + vec![( 0, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0)], // 90 -> 180 + vec![( 0, 0)], // 90 -> 0 + ], + ], + vec![ // T + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 90 + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 180 + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 0 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 270 + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 90 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 0 + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 180 + ] + ], + vec![ // O + vec![ + vec![( 0, 0)], // 0 -> 90 + vec![( 0, 0)], // 0 -> 270 + ], + ], + vec![ // L + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 90 + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 180 + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 0 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 270 + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 90 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 0 + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 180 + ] + ], + vec![ // S + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 90 + vec![( 0, 0),(-1, 0),( 1, 0)], // 0 -> 270 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 180 + vec![( 0, 0),(-1, 0),( 1, 0)], // 90 -> 0 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 270 + vec![( 0, 0),(-1, 0),( 1, 0)], // 180 -> 90 + ], + vec![ + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 0 + vec![( 0, 0),(-1, 0),( 1, 0)], // 270 -> 180 + ] + ] + ], + colours: vec![ + Color::GREEN, // Z + Color::Rgba { red: 0.0, green: 0.3, blue: 1.0, alpha: 1.0 }, // J + Color::RED, // I + Color::CYAN, // T + Color::YELLOW, // O + Color::ORANGE, // L + Color::Rgba { red: 1.0, green: 0.0, blue: 1.0, alpha: 1.0 } // s + ], + spawn_offsets: vec![ + (0, 0), // Z + (0, 0), // J + (0, 0), // I + (0, 0), // T + (1, 0), // O + (0, 0), // L + (0, 0) // S + ], + lock_delay_mode: LockDelayMode::ResetOnYChange, + height_offset: -2 + }); rs }; } \ No newline at end of file diff --git a/src/engine/systems.rs b/src/engine/systems.rs index 0701981..c9d4cd1 100644 --- a/src/engine/systems.rs +++ b/src/engine/systems.rs @@ -38,7 +38,7 @@ pub fn init_engine( }, BoardVisual {}, )); - engine.init("NRS", Box::new(RandomWithoutDirectRepetition::create())); + engine.init("ARS", Box::new(TGM::create())); game_next_state.set(GameStates::Gameplay); next_state.set(GameloopStates::Falling); }