]> git.seodisparate.com - EN605.607.81.SP22_ASDM_Project/commitdiff
Tweak "board to string" and back for better info
authorStephen Seo <seo.disparate@gmail.com>
Wed, 6 Apr 2022 11:09:22 +0000 (20:09 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 6 Apr 2022 11:09:22 +0000 (20:09 +0900)
backend_protocol_specification.md
front_end/src/state.rs
front_end/src/yew_components.rs

index 7118bdc2d714a2bba99e9ad52ca109cb8af7383d..f9ad2780ef67f6d2064da6e821c292adb82da87a 100644 (file)
@@ -138,6 +138,8 @@ then the back-end will respond with "too\_many\_players".
                               // e - magenta winning piece
                               // f - cyan placed
                               // g - magenta placed
+                              // h - cyan winning and placed piece
+                              // i - magenta winning and placed piece
     }
 ```
 
index 3c952889ebaa25a513a93ccd6e44280c7104a2d0..abea9a8386ff65de7fe632bfe656ccf5592e5dd1 100644 (file)
@@ -413,9 +413,9 @@ pub fn board_from_string(board_string: String) -> BoardType {
         match c {
             'a' => board[idx].replace(BoardState::Empty),
             'b' | 'f' => board[idx].replace(BoardState::Cyan),
-            'd' => board[idx].replace(BoardState::CyanWin),
+            'd' | 'h' => board[idx].replace(BoardState::CyanWin),
             'c' | 'g' => board[idx].replace(BoardState::Magenta),
-            'e' => board[idx].replace(BoardState::MagentaWin),
+            'e' | 'i' => board[idx].replace(BoardState::MagentaWin),
             _ => BoardState::Empty,
         };
     }
@@ -467,7 +467,11 @@ pub fn string_from_board(board: BoardType, placed: usize) -> (String, Option<Boa
             }
             BoardState::Cyan | BoardState::CyanWin => {
                 if win_set.contains(&idx) {
-                    'd'
+                    if idx == placed {
+                        'h'
+                    } else {
+                        'd'
+                    }
                 } else if idx == placed {
                     'f'
                 } else {
@@ -476,7 +480,11 @@ pub fn string_from_board(board: BoardType, placed: usize) -> (String, Option<Boa
             }
             BoardState::Magenta | BoardState::MagentaWin => {
                 if win_set.contains(&idx) {
-                    'e'
+                    if idx == placed {
+                        'i'
+                    } else {
+                        'e'
+                    }
                 } else if idx == placed {
                     'g'
                 } else {
index 64f61f2b373cc395b13bb8950b0d5e3c2388e52a..8b1e4571234f5750dbee8fbf505a69235cc3c684 100644 (file)
@@ -533,8 +533,10 @@ impl Wrapper {
                 .chars()
                 .nth(idx)
                 .expect("idx into board_string should be in range");
-            if char_at_idx == 'f' {
-                element_append_class(&document, &format!("slot{}", idx), "placed").ok();
+            if char_at_idx == 'f' || char_at_idx == 'h' {
+                if char_at_idx == 'f' {
+                    element_append_class(&document, &format!("slot{}", idx), "placed").ok();
+                }
                 if was_open {
                     append_to_info_text(
                         &document,
@@ -544,8 +546,10 @@ impl Wrapper {
                     )
                     .ok();
                 }
-            } else if char_at_idx == 'g' {
-                element_append_class(&document, &format!("slot{}", idx), "placed").ok();
+            } else if char_at_idx == 'g' || char_at_idx == 'i' {
+                if char_at_idx == 'g' {
+                    element_append_class(&document, &format!("slot{}", idx), "placed").ok();
+                }
                 if was_open {
                     append_to_info_text(
                         &document,