Tweak "board to string" and back for better info
This commit is contained in:
parent
2e0b29ed70
commit
59bdcc2a34
3 changed files with 22 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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) {
|
||||
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) {
|
||||
if idx == placed {
|
||||
'i'
|
||||
} else {
|
||||
'e'
|
||||
}
|
||||
} else if idx == placed {
|
||||
'g'
|
||||
} else {
|
||||
|
|
|
@ -533,8 +533,10 @@ impl Wrapper {
|
|||
.chars()
|
||||
.nth(idx)
|
||||
.expect("idx into board_string should be in range");
|
||||
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' {
|
||||
} 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,
|
||||
|
|
Loading…
Reference in a new issue