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
|
// e - magenta winning piece
|
||||||
// f - cyan placed
|
// f - cyan placed
|
||||||
// g - magenta 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 {
|
match c {
|
||||||
'a' => board[idx].replace(BoardState::Empty),
|
'a' => board[idx].replace(BoardState::Empty),
|
||||||
'b' | 'f' => board[idx].replace(BoardState::Cyan),
|
'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),
|
'c' | 'g' => board[idx].replace(BoardState::Magenta),
|
||||||
'e' => board[idx].replace(BoardState::MagentaWin),
|
'e' | 'i' => board[idx].replace(BoardState::MagentaWin),
|
||||||
_ => BoardState::Empty,
|
_ => BoardState::Empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,11 @@ pub fn string_from_board(board: BoardType, placed: usize) -> (String, Option<Boa
|
||||||
}
|
}
|
||||||
BoardState::Cyan | BoardState::CyanWin => {
|
BoardState::Cyan | BoardState::CyanWin => {
|
||||||
if win_set.contains(&idx) {
|
if win_set.contains(&idx) {
|
||||||
|
if idx == placed {
|
||||||
|
'h'
|
||||||
|
} else {
|
||||||
'd'
|
'd'
|
||||||
|
}
|
||||||
} else if idx == placed {
|
} else if idx == placed {
|
||||||
'f'
|
'f'
|
||||||
} else {
|
} else {
|
||||||
|
@ -476,7 +480,11 @@ pub fn string_from_board(board: BoardType, placed: usize) -> (String, Option<Boa
|
||||||
}
|
}
|
||||||
BoardState::Magenta | BoardState::MagentaWin => {
|
BoardState::Magenta | BoardState::MagentaWin => {
|
||||||
if win_set.contains(&idx) {
|
if win_set.contains(&idx) {
|
||||||
|
if idx == placed {
|
||||||
|
'i'
|
||||||
|
} else {
|
||||||
'e'
|
'e'
|
||||||
|
}
|
||||||
} else if idx == placed {
|
} else if idx == placed {
|
||||||
'g'
|
'g'
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -533,8 +533,10 @@ impl Wrapper {
|
||||||
.chars()
|
.chars()
|
||||||
.nth(idx)
|
.nth(idx)
|
||||||
.expect("idx into board_string should be in range");
|
.expect("idx into board_string should be in range");
|
||||||
|
if char_at_idx == 'f' || char_at_idx == 'h' {
|
||||||
if char_at_idx == 'f' {
|
if char_at_idx == 'f' {
|
||||||
element_append_class(&document, &format!("slot{}", idx), "placed").ok();
|
element_append_class(&document, &format!("slot{}", idx), "placed").ok();
|
||||||
|
}
|
||||||
if was_open {
|
if was_open {
|
||||||
append_to_info_text(
|
append_to_info_text(
|
||||||
&document,
|
&document,
|
||||||
|
@ -544,8 +546,10 @@ impl Wrapper {
|
||||||
)
|
)
|
||||||
.ok();
|
.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();
|
element_append_class(&document, &format!("slot{}", idx), "placed").ok();
|
||||||
|
}
|
||||||
if was_open {
|
if was_open {
|
||||||
append_to_info_text(
|
append_to_info_text(
|
||||||
&document,
|
&document,
|
||||||
|
|
Loading…
Reference in a new issue