Tweak "board to string" and back for better info

This commit is contained in:
Stephen Seo 2022-04-06 20:09:22 +09:00
parent 2e0b29ed70
commit 59bdcc2a34
3 changed files with 22 additions and 8 deletions

View 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
}
```

View 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 {

View 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,