]> git.seodisparate.com - EN605.607.81.SP22_ASDM_Project/commitdiff
Refactorings and linter fixes
authorStephen Seo <seo.disparate@gmail.com>
Wed, 9 Mar 2022 09:14:01 +0000 (18:14 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 9 Mar 2022 09:14:01 +0000 (18:14 +0900)
front_end/src/game_logic.rs
front_end/src/state.rs
front_end/src/yew_components.rs

index 9d31d106e0667b121959627f0a4fc61049428e7c..ef22724b5c72bb51db619d02c37a38e01ecac3cf 100644 (file)
@@ -43,8 +43,8 @@ pub fn check_win_draw(board: &BoardType) -> Option<(BoardState, WinType)> {
         for x in 0..((COLS - 3) as usize) {
             let idx = x + y * (COLS as usize);
             let result = check_result(has_right_horizontal_at_idx(idx, board));
-            if result.is_some() {
-                return Some((result.unwrap(), WinType::Horizontal(idx)));
+            if let Some(result) = result {
+                return Some((result, WinType::Horizontal(idx)));
             }
         }
     }
@@ -54,8 +54,8 @@ pub fn check_win_draw(board: &BoardType) -> Option<(BoardState, WinType)> {
         for x in 0..(COLS as usize) {
             let idx = x + y * (COLS as usize);
             let result = check_result(has_down_vertical_at_idx(idx, board));
-            if result.is_some() {
-                return Some((result.unwrap(), WinType::Vertical(idx)));
+            if let Some(result) = result {
+                return Some((result, WinType::Vertical(idx)));
             }
         }
     }
@@ -65,8 +65,8 @@ pub fn check_win_draw(board: &BoardType) -> Option<(BoardState, WinType)> {
         for x in 0..((COLS - 3) as usize) {
             let idx = x + y * (COLS as usize);
             let result = check_result(has_right_up_diagonal_at_idx(idx, board));
-            if result.is_some() {
-                return Some((result.unwrap(), WinType::DiagonalUp(idx)));
+            if let Some(result) = result {
+                return Some((result, WinType::DiagonalUp(idx)));
             }
         }
     }
@@ -76,8 +76,8 @@ pub fn check_win_draw(board: &BoardType) -> Option<(BoardState, WinType)> {
         for x in 0..((COLS - 3) as usize) {
             let idx = x + y * (COLS as usize);
             let result = check_result(has_right_down_diagonal_at_idx(idx, board));
-            if result.is_some() {
-                return Some((result.unwrap(), WinType::DiagonalDown(idx)));
+            if let Some(result) = result {
+                return Some((result, WinType::DiagonalDown(idx)));
             }
         }
     }
index dabbdb1ec1e84cc05a86523e67babcef82e71810..e74c7d60a53a362b3ec5104e2b42dc49bb6ebf04 100644 (file)
@@ -69,16 +69,16 @@ impl BoardState {
         *self == BoardState::Empty
     }
 
-    pub fn into_win(&self) -> Self {
-        match *self {
+    pub fn into_win(self) -> Self {
+        match self {
             BoardState::Empty => BoardState::Empty,
             BoardState::Cyan | BoardState::CyanWin => BoardState::CyanWin,
             BoardState::Magenta | BoardState::MagentaWin => BoardState::MagentaWin,
         }
     }
 
-    pub fn from_win(&self) -> Self {
-        match *self {
+    pub fn from_win(self) -> Self {
+        match self {
             BoardState::Empty => BoardState::Empty,
             BoardState::Cyan | BoardState::CyanWin => BoardState::Cyan,
             BoardState::Magenta | BoardState::MagentaWin => BoardState::MagentaWin,
index 8b78d2984197cc66392aacd2e37bc376304e4245..af4cd4c1554c5a0dc1c8ca25d4fb3d2d6326f89c 100644 (file)
@@ -356,7 +356,7 @@ impl Component for Wrapper {
                                 }
                                 let append_result = element_append_class(
                                     &document,
-                                    &format!("slot{}", idx + 1 * (COLS as usize)),
+                                    &format!("slot{}", idx + (COLS as usize)),
                                     "win",
                                 );
                                 if let Err(e) = append_result {
@@ -380,9 +380,8 @@ impl Component for Wrapper {
                                 }
 
                                 shared.board[idx].replace(shared.board[idx].get().into_win());
-                                shared.board[idx + 1 * (COLS as usize)].replace(
-                                    shared.board[idx + 1 * (COLS as usize)].get().into_win(),
-                                );
+                                shared.board[idx + (COLS as usize)]
+                                    .replace(shared.board[idx + (COLS as usize)].get().into_win());
                                 shared.board[idx + 2 * (COLS as usize)].replace(
                                     shared.board[idx + 2 * (COLS as usize)].get().into_win(),
                                 );
@@ -398,7 +397,7 @@ impl Component for Wrapper {
                                 }
                                 let append_result = element_append_class(
                                     &document,
-                                    &format!("slot{}", idx + 1 - 1 * (COLS as usize)),
+                                    &format!("slot{}", idx + 1 - (COLS as usize)),
                                     "win",
                                 );
                                 if let Err(e) = append_result {
@@ -422,8 +421,8 @@ impl Component for Wrapper {
                                 }
 
                                 shared.board[idx].replace(shared.board[idx].get().into_win());
-                                shared.board[idx + 1 - 1 * (COLS as usize)].replace(
-                                    shared.board[idx + 1 - 1 * (COLS as usize)].get().into_win(),
+                                shared.board[idx + 1 - (COLS as usize)].replace(
+                                    shared.board[idx + 1 - (COLS as usize)].get().into_win(),
                                 );
                                 shared.board[idx + 2 - 2 * (COLS as usize)].replace(
                                     shared.board[idx + 2 - 2 * (COLS as usize)].get().into_win(),
@@ -440,7 +439,7 @@ impl Component for Wrapper {
                                 }
                                 let append_result = element_append_class(
                                     &document,
-                                    &format!("slot{}", idx + 1 + 1 * (COLS as usize)),
+                                    &format!("slot{}", idx + 1 + (COLS as usize)),
                                     "win",
                                 );
                                 if let Err(e) = append_result {
@@ -464,8 +463,8 @@ impl Component for Wrapper {
                                 }
 
                                 shared.board[idx].replace(shared.board[idx].get().into_win());
-                                shared.board[idx + 1 + 1 * (COLS as usize)].replace(
-                                    shared.board[idx + 1 + 1 * (COLS as usize)].get().into_win(),
+                                shared.board[idx + 1 + (COLS as usize)].replace(
+                                    shared.board[idx + 1 + (COLS as usize)].get().into_win(),
                                 );
                                 shared.board[idx + 2 + 2 * (COLS as usize)].replace(
                                     shared.board[idx + 2 + 2 * (COLS as usize)].get().into_win(),