def test_try_to_get_shogi_board(self): channel_id = "test_try_to_get_shogi_board" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.get_shogi_board(channel_id)
def start_shogi(channel, message, opponent_name): slacker = message._client.webapi user = User(slacker) opponent_id = user.username_to_id(opponent_name) if opponent_id is None: # In case of mention. In mention, slack transform username to userid # like @username to <@UOIFJ83F> opponent_id = opponent_name if not user.user_in_channel(opponent_id, channel.channel_id): message.reply("Error, sorry. Opponent is not found in this channel") return shogi = ShogiInput.init(channel_id=channel.channel_id, users=[{ "id": channel.own_id, "name": user.id_to_username(channel.own_id), }, { "id": opponent_id, "name": user.id_to_username(opponent_id), }]) if shogi is None: message.reply( "Shogi started already by a user. Sorry.\nIf you want to quit shogi which already exists, please say this command `resign`" ) else: message.reply("Shogi started: " + shogi.id) board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str)
def test_shogi_output_reverse_format(self): # for syntax error and runtime error channel_id = "channel_id" shogi = ShogiInput.init(channel_id, [{"id": "user1", "name": "user1name"}, {"id": "user2", "name": "user2name"}]) board = ShogiInput.get_shogi_board(channel_id) board_str = ShogiOutput.make_board_emoji_reverse(board) self.assertIsNotNone(board_str)
def koma_move(channel, message, destination, piece, position=None, direction=None, promotion=None): movement_str = "".join([ x for x in [destination, piece, position, direction, promotion] if x is not None ]) #def koma_move(channel, message, position, dou, koma, sub_position=None, promote=None): # movement_str = "".join( # [x for x in [position, dou, koma, sub_position, promote] if x is not None]) try: ShogiInput.move(movement_str, channel.channel_id, channel.own_id) except UserDifferentException: message.reply("You cannot move this because *it's not your turn*") except KomaCannotMoveException: message.reply( "You cannot move this with your message *{}*".format(movement_str)) finally: board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str)
def matta(channel, message): try: ShogiInput.matta(channel.channel_id, channel.own_id) message.send("mattaed") except UserDifferentException: message.reply("You cannot matta because *it's not your turn*") except KomaCannotMoveException: message.reply("You cannot matta because koma not moved") finally: board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str)
def test_shogi_output_format(self): # for syntax error and runtime error channel_id = "channel_id" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name" }, { "id": "user2", "name": "user2name" }]) board = ShogiInput.get_shogi_board(channel_id) board_str = ShogiOutput.make_board_emoji(board) self.assertIsNotNone(board_str)
def hifumin(channel, message): board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji_reverse(board) message.send(board_str)
def resign(channel, message): message.send("最終局面") board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str) ShogiInput.clear(channel.channel_id)
def board_info(channel, message): board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str)