Skip to content

Commit

Permalink
fix o piece
Browse files Browse the repository at this point in the history
  • Loading branch information
ziloka committed Nov 5, 2023
1 parent 7bd11d4 commit 0834e9c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Implement

Counter rotating I piece crashes program
~~Counter rotating I piece crashes program~~
Counter rotating O piece crashes program

when rotating I and O pieces, there must be a offset to center it
look at [true rotations](https://harddrop.com/w/images/3/3d/SRS-pieces.png) to understand and compare it in game
look at [true rotations](https://harddrop.com/wiki/SRS) to understand and compare it in game

- Add Replay
- 180 rotations wallkicks
Expand All @@ -17,4 +17,4 @@ look at [true rotations](https://harddrop.com/w/images/3/3d/SRS-pieces.png) to u
- Be able to set tetromino bag
- Fumen compatibility
- AI tools / PC finders
- set up way for setups / openers
- set up way for setups / openers
2 changes: 2 additions & 0 deletions notes/WALLKICK.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[Four-tris wallkick tables](https://github.com/fiorescarlatto/four-tris/blob/dc08ed253e704a4a68302dfc4392b5e28ad3eccf/Tetris.au3#L3395-L3450)
[Four-tris wallkick](https://github.com/fiorescarlatto/four-tris/blob/dc08ed253e704a4a68302dfc4392b5e28ad3eccf/Tetris.au3#L3395-L3450)

[Rotation System Explanation](https://youtu.be/yIpk5TJ_uaI)
[PieceController.cs Wallkick](https://github.com/JohnnyTurbo/LD43/blob/82de0ac5aa29f6e87d6c5417e0504d6ae7033ef6/Assets/Scripts/PieceController.cs#L297-L340)
- [Last commit using this rotation implementation](https://github.com/ziloka/tetris/blob/5c5f836c42b0b5196fbf9b681195c9d912e901a9/src/tetris/board.rs#L173-L278)

[Implementing 180 wallkicks is impossible unless you use wallkick table (cannot use offset data)](https://www.reddit.com/r/Tetris/comments/p11rtf/srs_how_can_i_convert_wall_kick_tables_to_offset/)

Expand Down
9 changes: 6 additions & 3 deletions scripts/wallkicks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// given HTML table of tetrominos convert it in array representation
// https://harddrop.com/wiki/SRS#Wall_Kick_Illustration
import * as cheerio from "https://esm.sh/cheerio@0.22.0";
const $ = cheerio.load(await Deno.readTextFile("input.txt"));
const $ = cheerio.load(await Deno.readTextFile("page.html"));

function get_rot_indx(s) {
if (s === "R") {
Expand All @@ -19,8 +19,10 @@ function generate_test_case(table, offset, init_rot_indx, dest_rot_index) {
init_rot_indx = get_rot_indx(init_rot_indx);
dest_rot_index = get_rot_indx(dest_rot_index);

const HEIGHT = 7;
const WIDTH = 5;
// const HEIGHT = 7;
// const WIDTH = 5;
const HEIGHT = $(table).find("div").length;
const WIDTH = $($(table).find("div")[0]).find("img").length;

// 35 elements in total
const board = Array.from({length: HEIGHT}, () => (Array.from({length: WIDTH}, () => "N")));
Expand All @@ -40,6 +42,7 @@ function generate_test_case(table, offset, init_rot_indx, dest_rot_index) {

// (6, 0), (6, 1) (6, 2), ...
// (5, 7), (5, 6) (5, 5), ...
// ...
// console.log(`x: ${x}, y: ${y} | column: ${column} row: ${row}`);

if (/(L|J|T|S|Z|I)Tet\.png/.test(name)) { // initial tetromino position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4281,4 +4281,4 @@ <h2><span class="mw-headline" id="External_links">External links</span></h2>
-->

<!-- Saved in parser cache with key harddrop_mw:pcache:idhash:1610-0!canonical and timestamp 20231012024139 and revision id 29046.
-->
-->
4 changes: 2 additions & 2 deletions src/core/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl Board {
relative.x < 0.0 // for the left side
|| relative.x >= self.positions[0].len() as f32 // for the right side
|| relative.y < 0.0
|| relative.y >= self.positions.len() as f32
// for the floor (bottom)
) || dont_allow_overlapping_blocks
&& self.positions[row as usize][column as usize].is_some()
Expand Down Expand Up @@ -233,13 +234,12 @@ impl Board {
)
.add(origin);
}
println!("{}, {}", old_rotation_index, self.active_piece.rotation_index);

let index = Tetromino::find_offset_row_90(
old_rotation_index,
self.active_piece.rotation_index,
);
dbg!(index);

if should_offset
&& !self.wallkick_tetromino(
self.active_piece
Expand Down
25 changes: 18 additions & 7 deletions src/core/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Tetromino {
}
}

// https://tetris.wiki/Super_Rotation_System - READ THE "How Guideline SRS *Really* Works" section
// https://tetris.wiki/Super_Rotation_System
// determine the rotation index of the tetromino
// first number is the number representation, the second is how tetris.wiki refers to the tetromino states
// returning 0 - 0 means it is in its spawn position
Expand Down Expand Up @@ -283,12 +283,23 @@ impl Tetromino {
vec2(2., -1.),
], // 0->L
],
Tetromino::O => vec![vec![
vec2(0.0, 0.0),
vec2(0.0, -1.0),
vec2(-1.0, -1.0),
vec2(-1.0, 0.0),
]],
Tetromino::O => vec![vec![ // 0->R (0->1)
vec2(0., 1.),
], vec![ // R->0
vec2(0., -1.),
], vec![ // R->2 (1->2)
vec2(1., 0.),
], vec![ // 2->R
vec2(-1., 0.),
], vec![ // 2->L (2->3)
vec2(0., -1.),
], vec![ // L->2
vec2(0., 1.),
], vec![ // L->0 (3->0)
vec2(-1., 0.),
], vec![ // 0->L
vec2(1., 0.),
],],
_ => vec![
vec![
vec2(0., 0.),
Expand Down

0 comments on commit 0834e9c

Please sign in to comment.