From 10af20230555cc935d69a84c615c26d00bd91d42 Mon Sep 17 00:00:00 2001 From: zihang Date: Wed, 19 Jun 2024 14:42:00 +0800 Subject: [PATCH] refactor(tetris): modernize --- examples/tetris/lib/utils.mbt | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/examples/tetris/lib/utils.mbt b/examples/tetris/lib/utils.mbt index a5b447c8..04db8d7e 100644 --- a/examples/tetris/lib/utils.mbt +++ b/examples/tetris/lib/utils.mbt @@ -8,30 +8,26 @@ pub fn check_collision( if offset.1 + len_r > grid_row_count { return true } - fn go(l : @immut/list.List[Array[Int]], r : Int) -> Bool { - match l { - Cons(v, n) => { - if r < offset.1 { - return go(n, r + 1) - } - if r >= offset.1 + len_r { - return false + loop grid, 0 { + Cons(v, n), r => { + if r < offset.1 { + continue n, r + 1 + } + if r >= offset.1 + len_r { + return false + } + for c = 0; c < len_c; c = c + 1 { + if shap[r - offset.1][c] == 0 { + continue c + 1 } - for c = 0; c < len_c; c = c + 1 { - if shap[r - offset.1][c] == 0 { - continue c + 1 - } - if v[c + offset.0] != 0 { - return true - } + if v[c + offset.0] != 0 { + return true } - return go(n, r + 1) } - Nil => false + continue n, r + 1 } + Nil, _ => false } - - return go(grid, 0) } pub fn get_effective_height(