2018-06-08 14:30:50 -07:00
|
|
|
from zulip_bots.test_lib import BotTestCase, DefaultTests
|
2017-12-04 20:34:52 -08:00
|
|
|
|
2021-05-28 17:00:04 +08:00
|
|
|
|
2018-06-08 14:30:50 -07:00
|
|
|
class TestChessBot(BotTestCase, DefaultTests):
|
2018-05-26 14:18:37 -07:00
|
|
|
bot_name = "chessbot"
|
2017-12-04 20:34:52 -08:00
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
START_RESPONSE = """New game! The board looks like this:
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
a b c d e f g h
|
|
|
|
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
|
|
|
|
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
|
|
|
|
6 · · · · · · · · 6
|
|
|
|
5 · · · · · · · · 5
|
|
|
|
4 · · · · · · · · 4
|
|
|
|
3 · · · · · · · · 3
|
|
|
|
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 2
|
|
|
|
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
|
|
|
|
a b c d e f g h
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Now it's **white**'s turn.
|
|
|
|
|
|
|
|
|
|
|
|
To make your next move, respond to Chess Bot with
|
|
|
|
|
|
|
|
```do <your move>```
|
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
*Remember to @-mention Chess Bot at the beginning of your response.*"""
|
2017-12-04 20:34:52 -08:00
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
DO_E4_RESPONSE = """The board was like this:
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
h g f e d c b a
|
|
|
|
1 ♖ ♘ ♗ ♔ ♕ ♗ ♘ ♖ 1
|
|
|
|
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 2
|
|
|
|
3 · · · · · · · · 3
|
|
|
|
4 · · · · · · · · 4
|
|
|
|
5 · · · · · · · · 5
|
|
|
|
6 · · · · · · · · 6
|
|
|
|
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
|
|
|
|
8 ♜ ♞ ♝ ♚ ♛ ♝ ♞ ♜ 8
|
|
|
|
h g f e d c b a
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Then *white* moved *e4*:
|
|
|
|
|
|
|
|
```
|
|
|
|
h g f e d c b a
|
|
|
|
1 ♖ ♘ ♗ ♔ ♕ ♗ ♘ ♖ 1
|
|
|
|
2 ♙ ♙ ♙ · ♙ ♙ ♙ ♙ 2
|
|
|
|
3 · · · · · · · · 3
|
|
|
|
4 · · · ♙ · · · · 4
|
|
|
|
5 · · · · · · · · 5
|
|
|
|
6 · · · · · · · · 6
|
|
|
|
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
|
|
|
|
8 ♜ ♞ ♝ ♚ ♛ ♝ ♞ ♜ 8
|
|
|
|
h g f e d c b a
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Now it's **black**'s turn.
|
|
|
|
|
|
|
|
|
|
|
|
To make your next move, respond to Chess Bot with
|
|
|
|
|
|
|
|
```do <your move>```
|
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
*Remember to @-mention Chess Bot at the beginning of your response.*"""
|
2017-12-04 20:34:52 -08:00
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
DO_KE4_RESPONSE = """Sorry, the move *Ke4* isn't legal.
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
h g f e d c b a
|
|
|
|
1 ♖ ♘ ♗ ♔ ♕ ♗ ♘ ♖ 1
|
|
|
|
2 ♙ ♙ ♙ · ♙ ♙ ♙ ♙ 2
|
|
|
|
3 · · · · · · · · 3
|
|
|
|
4 · · · ♙ · · · · 4
|
|
|
|
5 · · · · · · · · 5
|
|
|
|
6 · · · · · · · · 6
|
|
|
|
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
|
|
|
|
8 ♜ ♞ ♝ ♚ ♛ ♝ ♞ ♜ 8
|
|
|
|
h g f e d c b a
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
To make your next move, respond to Chess Bot with
|
|
|
|
|
|
|
|
```do <your move>```
|
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
*Remember to @-mention Chess Bot at the beginning of your response.*"""
|
2017-12-04 20:34:52 -08:00
|
|
|
|
2021-05-28 17:05:11 +08:00
|
|
|
RESIGN_RESPONSE = """*Black* resigned. **White** wins!
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
h g f e d c b a
|
|
|
|
1 ♖ ♘ ♗ ♔ ♕ ♗ ♘ ♖ 1
|
|
|
|
2 ♙ ♙ ♙ · ♙ ♙ ♙ ♙ 2
|
|
|
|
3 · · · · · · · · 3
|
|
|
|
4 · · · ♙ · · · · 4
|
|
|
|
5 · · · · · · · · 5
|
|
|
|
6 · · · · · · · · 6
|
|
|
|
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
|
|
|
|
8 ♜ ♞ ♝ ♚ ♛ ♝ ♞ ♜ 8
|
|
|
|
h g f e d c b a
|
2021-05-28 17:05:11 +08:00
|
|
|
```"""
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
def test_bot_responds_to_empty_message(self) -> None:
|
2021-05-28 17:05:11 +08:00
|
|
|
with self.mock_config_info({"stockfish_location": "/foo/bar"}):
|
|
|
|
response = self.get_response(dict(content=""))
|
|
|
|
self.assertIn("play chess", response["content"])
|
2017-12-04 20:34:52 -08:00
|
|
|
|
|
|
|
def test_main(self) -> None:
|
2021-05-28 17:05:11 +08:00
|
|
|
with self.mock_config_info({"stockfish_location": "/foo/bar"}):
|
2021-05-28 17:03:46 +08:00
|
|
|
self.verify_dialog(
|
|
|
|
[
|
2021-05-28 17:05:11 +08:00
|
|
|
("start with other user", self.START_RESPONSE),
|
|
|
|
("do e4", self.DO_E4_RESPONSE),
|
|
|
|
("do Ke4", self.DO_KE4_RESPONSE),
|
|
|
|
("resign", self.RESIGN_RESPONSE),
|
2021-05-28 17:03:46 +08:00
|
|
|
]
|
|
|
|
)
|