diff --git a/front_end/src/game_logic.rs b/front_end/src/game_logic.rs index 9d31d10..ef22724 100644 --- a/front_end/src/game_logic.rs +++ b/front_end/src/game_logic.rs @@ -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))); } } } diff --git a/front_end/src/state.rs b/front_end/src/state.rs index dabbdb1..e74c7d6 100644 --- a/front_end/src/state.rs +++ b/front_end/src/state.rs @@ -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, diff --git a/front_end/src/yew_components.rs b/front_end/src/yew_components.rs index 8b78d29..af4cd4c 100644 --- a/front_end/src/yew_components.rs +++ b/front_end/src/yew_components.rs @@ -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(),