ARS + TGM random

This commit is contained in:
dan63047 2023-11-17 23:06:19 +03:00
parent 18410079c6
commit dca0bb10be
4 changed files with 209 additions and 4 deletions

View File

@ -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<usize>,
seed: u32
}
impl Randomizer for Bag {
fn populate_next(&mut self, pieces_data: &PiecesData, board_width: isize, board_height: isize) -> Vec<Piece> {
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<Piece> {
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
}
}

View File

@ -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 {

View File

@ -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
};
}

View File

@ -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);
}