예제 #1
0
파일: fsm.py 프로젝트: srsuper/chess-bot
    def on_enter_userplayself(self, event):
        stamp = str(datetime.now().timestamp())
        user_id = event.source.user_id
        self.board.draw(user_id, stamp)
        r = int((len(self.history) + 1) / 2)
        if len(self.history) % 2 == 1:
            board_info = 'Round ' + str(r) + ', white\'s turn.'
            push_text_message(user_id, board_info)
            push_image_message(user_id, domain + '/' + user_id + '/' + stamp)

            if self.board.is_win(pieces.Piece.BLACK):
                push_text_message(user_id, 'BLACK win!')
                self.board.remove(user_id)
                self.go_back(event)
                return
            if self.board.is_check(pieces.Piece.WHITE):
                push_text_message(user_id, 'Check!')
        else:
            board_info = 'Round ' + str(r) + ', black\'s turn.'
            push_text_message(user_id, board_info)
            push_image_message(user_id, domain + '/' + user_id + '/' + stamp)

            if self.board.is_win(pieces.Piece.WHITE):
                push_text_message(user_id, 'White win!')
                self.board.remove(user_id)
                self.go_back(event)
                return
            if self.board.is_check(pieces.Piece.BLACK):
                push_text_message(user_id, 'Check!')
예제 #2
0
    def on_enter_botplaywhite(self, event):
        stamp = str(datetime.now().timestamp())
        room_id = event.source.room_id
        self.board.draw(room_id, stamp)
        r = int((len(self.history) + 1) / 2)
        board_info = 'Round ' + str(r) + ', white\'s turn.'
        push_text_message(room_id, board_info)
        push_image_message(room_id, domain + '/' + room_id + '/' + stamp)

        if self.board.is_win(pieces.Piece.BLACK):
            push_text_message(room_id, 'Black win!')
            self.board.remove(room_id)
            self.go_back(event)
            return
        if self.board.is_check(pieces.Piece.WHITE):
            push_text_message(room_id, 'Check!')
        self.advance(event)